Spatialite Gui Notes
Spatialite Gui Notes
Spatialite Gui Notes
You've just launched spatialite-gui; so you are now facing a window like this one … as you can
easily understand, currently there is no database connected.
We obviously have now to establish a connection to some database, but before beginning any actual
work, let us examine the two buttons evidenced at the tool-bar rightmost side.
Default output charset:
spatialite-gui automatically detects the locale charset setting currently in use on your PC; but may
well be you wish to use a different one, or you prefer choosing the output charset to be used each
time one is needed. This small pane enables you to manage this aspect as you need.
On-line help:
You can easily check the SQL syntax expected by SQLite and SpatiaLite using this help pane.
Establishing a connection to some database:
SQLite adopts a peculiar architecture: a whole database is contained in an ordinary file. So you can
choose one of the following actions:
• connect to an already existing database-file
• create a new (initially empty) database-file
NOTE: the latest spatialite-gui version automatically initializes any newly created database.
Consequently now there is no need to manually execute the init_spatialite.sql script, because this
task has already been performed during database creation.
As you can notice, the geometry_columns and spatial_ref_sys tables are already defined and
populated as appropriate immediately after database creation.
And SQLite supports as well the capability to store databases directly in memory, with no need to
use any file-system file. So the complete range of actions you can perform in order to establish a
database connection is as follows:
• connecting to an already existing database-file
• creating a new (initially empty) database-file
• loading an already existing database-file as an in-memory-database
• creating a new (initially empty) in-memory-database
This practically means that very easily you can get supersonic performances using in-memory-
databases, but this may be a risky operation because:
• if some trouble arises (power failure, system crash …) any update you have performed on
the database will be irreparably lost.
• if the memory space required to store the database is too big, you can then get the paradox
effect to slow down your system in a severe way.
Perform a VACUUM:
This one is a maintenance operation. The complete database will undergone a full rebuild, and any
unused space will be actually freed:
• VACUUMing an huge database may require a long time
• a properly VACUUMed database surely performs better
It's your choice why and when VACUUMize your databases; anyway performing a VACUUM is
absolutely suggested as a good practice every time you've performed an huge number of INSERTs
and/or DELETEs.
Supposing you have opted to connect some in-memory-database [the unconventional way], you are
now enabled to perform the following actions:
Exactly the same as above. But this time your database was using a volatile storage media, so any
data is now irremediably lost.
This one may be a good new is you where performing some stupid test, but may be a real
catastrophe if you where performing any serious work.
Perform a VACUUM:
Exactly the same as above, but this time anything runs faster.
Please, carefully consider that VACUUMing an in-memory-database more or less requires twice
the memory amount currently required.
spatialite-gui supports an even smarter feature, i.e. the one of AutoSaving the in-memory-database
to a corresponding database-file from time to time, on a regular and periodic base:
• an external database-file path is required
◦ if the in-memory-database was loaded from a database-file, then the original database-
file will be periodically overwritten.
◦ if the in-memory-database was created from scratch, in order to actually start the
AutoSave feature you are required to perform a manual Save a first time; then the same
path will be periodically overwritten.
• you can select the time interval, choosing the one most well suited to your needs.
• The AutoSave feature is smart enough to skip unneeded exports [i.e. when the in-memory-
database has no pending changes to be saved]
• To prevent any obnoxious consequence deriving from system crashes, power failures and so
on, the following security schema is implemented by AutoSave:
◦ the already existing database-file is renamed as database-file.bak
◦ then a new copy of database-file is generated by export.
◦ and finally database-file.bak is deleted
◦ so, if something goes the wrong way, database-file.bak still contains a (may be
obsolete) valid copy of your database.
All right, now you know all we need to know about database connections.
It's time to start using spatialite-gui for some useful task.