grass-sqlite.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!-- meta page description: SQLite DATABASE DRIVER -->
  2. The SQLite driver is the default DBMI backend.
  3. <h2>Creating a SQLite database</h2>
  4. GRASS is automatically creating the SQLite database if it is not yet
  5. existing when the first table is created in the SQLite database. It
  6. is sufficient to define the connection (see next step).
  7. <h2>Connecting GRASS to SQLite</h2>
  8. The database name 'sqlite.db' is at user's choice.
  9. Also the file storage location can be freely chosen. If the database
  10. does not exist, it will be automatically created when database content
  11. is created:
  12. <div class="code"><pre>
  13. # example for storing DB in mapset directory (keep single quotes):
  14. db.connect driver=sqlite database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
  15. db.connect -p
  16. </pre></div>
  17. <h2>Supported SQL commands</h2>
  18. All SQL commands supported by SQLite (for limitations, see
  19. SQLite help page:
  20. <a href="http://www.sqlite.org/lang.html">SQL As Understood By SQLite</a> and
  21. <a href="http://www.sqlite.org/omitted.html">Unsupported SQL</a>).
  22. <h2>Operators available in conditions</h2>
  23. All SQL operators supported by SQLite.
  24. <h2>Browsing table data in DB</h2>
  25. A convenient SQLite front-end is <a href="http://sqlitebrowser.sourceforge.net/">sqlitebrowser</a>.
  26. To open a DB file stored within the current mapset,
  27. the following way is suggested (corresponds to above database connection):
  28. <div class="code"><pre>
  29. # fetch GRASS variables as shell environment variables:
  30. eval `g.gisenv`
  31. # use double quotes:
  32. sqlitebrowser "$GISDBASE/$LOCATION_NAME/$MAPSET"/sqlite/sqlite.db
  33. </pre></div>
  34. <!-- doesn't work yet, why?:
  35. ah, pending patch: http://www.sqlite.org/cvstrac/tktview?tn=1476
  36. <h2>Adding an unique ID column</h2>
  37. Import vector module require an unique ID column which can
  38. be generated as follows for a SQLite table:
  39. <div class="code"><pre>
  40. echo "
  41. ALTER TABLE mytable ADD ID integer;
  42. CREATE SEQUENCE mytable_seq;
  43. UPDATE mytabe SET ID = nextval('mytable_seq');
  44. DROP SEQUENCE mytable_seq;
  45. " | db.execute
  46. </pre></div>
  47. -->
  48. <h2>SEE ALSO</h2>
  49. <em>
  50. <a href="db.connect.html">db.connect</a>,
  51. <a href="db.execute.html">db.execute</a>,
  52. <a href="db.select.html">db.select</a>
  53. <br><br>
  54. <a href="sql.html">SQL support in GRASS GIS</a>
  55. <br><br>
  56. <a href="http://www.sqlite.org">SQLite web site</a>,
  57. <a href="http://www.sqlite.org/quickstart.html">SQLite manual</a>,
  58. <a href="http://www.sqlite.org/cvstrac/wiki?p=ManagementTools">sqlite - Management Tools</a>
  59. </em>
  60. <!--
  61. <p>
  62. <i>Last changed: $Date$</i>
  63. -->