grass-sqlite.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>GRASS-SQLite driver</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <link rel="stylesheet" href="grassdocs.css" type="text/css">
  7. </head>
  8. <body bgcolor="white">
  9. <img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
  10. <h1>SQLite driver in GRASS</h1>
  11. <H2>Creating a SQLite database</H2>
  12. GRASS is automatically creating the SQLite database if it is not yet
  13. existing when the first table is created in the SQLite database. It
  14. is sufficient to define the connection (see next step).
  15. <H2>Connecting GRASS to SQLite</H2>
  16. The database name 'sqlite.db' is at user's choice.
  17. Also the file storage location can be freely chosen. If the database
  18. does not exist, it will be automatically created when database content
  19. is created:
  20. <div class="code"><pre>
  21. # example for storing DB in mapset directory (keep single quotes):
  22. db.connect driver=sqlite database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db'
  23. db.connect -p
  24. </pre></div>
  25. <H2>Supported SQL commands</H2>
  26. All SQL commands supported by SQLite (for limitations, see
  27. SQLite help page:
  28. <a href="http://www.sqlite.org/lang.html">SQL As Understood By SQLite</a> and
  29. <a href="http://www.sqlite.org/omitted.html">Unsupported SQL</a>).
  30. <H2>Operators available in conditions</H2>
  31. All SQL operators supported by SQLite.
  32. <H2>Browsing table data in DB</H2>
  33. A convenient SQLite front-end is <a href="http://sqlitebrowser.sourceforge.net/">sqlitebrowser</a>.
  34. To open a DB file stored within the current mapset,
  35. the following way is suggested (corresponds to above database connection):
  36. <div class="code"><pre>
  37. eval `g.gisenv`
  38. # use double quotes:
  39. sqlitebrowser "$GISDBASE/$LOCATION_NAME/$MAPSET"/sqlite.db
  40. </pre></div>
  41. <!-- doesnt work yet, why?:
  42. ah, pending patch: http://www.sqlite.org/cvstrac/tktview?tn=1476
  43. <H2>Adding an unique ID column</H2>
  44. Import vector module require an unique ID column which can
  45. be generated as follows for a SQLite table:
  46. <div class="code"><pre>
  47. echo "
  48. ALTER TABLE mytable ADD ID integer;
  49. CREATE SEQUENCE mytable_seq;
  50. UPDATE mytabe SET ID = nextval('mytable_seq');
  51. DROP SEQUENCE mytable_seq;
  52. " | db.execute
  53. </pre></div>
  54. -->
  55. <H2>SEE ALSO</H2>
  56. <em><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="db.connect.html">db.connect</a>,
  59. <a HREF="db.execute.html">db.execute</a>,
  60. <a HREF="sql.html">SQL support in GRASS GIS</a>,
  61. <a HREF="http://www.sqlite.org/cvstrac/wiki?p=ManagementTools">sqlite - Management Tools</a>
  62. </em>
  63. <p><i>Last changed: $Date$</i>
  64. <HR>
  65. <BR><a href=index.html>Help Index</a>
  66. </body>
  67. </html>