1grass-odbc(1) Grass User's Manual grass-odbc(1)
2
3
4
5ODBC driver in GRASS Communication between GRASS and ODBC database for
6attribute management:
7| GRASS module | | ODBC Interface | | RDBMS
8| GRASS | DBMI driver | unixODBC | ODBC driver | PostgreSQL
9| Oracle
10| ...
11
13 All SQL commands supported by ODBC.
14
16 All SQL operators supported by ODBC.
17
19 In this example we copy the dbf file of a SHAPE map into ODBC, then
20 connect GRASS to the ODBC DBMS. Usually the table will be already
21 present in the DBMS.
22
23 Configure ODBC driver for selected database (manually or
24 with 'ODBCConfig'). ODBC drivers are defined in
25 /etc/odbcinst.ini. Here is example:
26 [PostgreSQL]
27 Description = ODBC for PostgreSQL
28 Driver = /usr/lib/libodbcpsql.so
29 Setup = /usr/lib/libodbcpsqlS.so
30 FileUsage = 1
31
32 Create DSN (data source name). The DSN is used as data‐
33 base name in db.* modules. Then DSN must be defined in
34 $HOME/.odbc.ini (for this user only) or in /etc/odbc.ini
35 for (for all users) [watch out for the database name
36 which appears twice and also for the PostgreSQL protocol
37 version]. Omit blanks at the beginning of lines:
38 [grass6test]
39 Description = PostgreSQL
40 Driver = PostgreSQL
41 Trace = No
42 TraceFile =
43 Database = grass6test
44 Servername = localhost
45 UserName = neteler
46 Password =
47 Port = 5432
48 Protocol = 8.0
49 ReadOnly = No
50 RowVersioning = No
51 ShowSystemTables = No
52 ShowOidColumn = No
53 FakeOidIndex = No
54 ConnSettings = Configuration of an DSN without
55 GUI is described on
56 http://www.unixodbc.org/odbcinst.html, but odbc.ini and
57 .odbc.ini may be created by the 'ODBCConfig' tool. You
58 can easily view your DSN structure by 'DataManager'. Con‐
59 figuration with GUI is described on
60 http://www.unixodbc.org/doc/UserManual/
61
62 To find out about your PostgreSQL protocol, run:
63
64 psql -V
65
66
67 Now create a new database if not yet existing:
68 db.createdb driver=odbc database=grass6test
69
70
71 Now store the table 'mytable.dbf' (here: in current
72 directory) into PostgreSQL through ODBC:
73 db.connect driver=odbc database=grass6test
74 db.copy from_driver=dbf from_database=./ from_ta‐
75 ble=mytable \
76 to_driver=odbc to_database=grass6test to_ta‐
77 ble=mytable
78
79
80 Next link map to attribute table (now the ODBC table is
81 used, not the dbf file):
82 v.db.connect map=mytable.shp table=mytable key=ID \
83 database=grass6test driver=odbc
84 v.db.connect -p
85
86
87 Finally a test: Here we should see the table columns (if
88 the ODBC connection works):
89 db.tables -p
90 db.columns table=mytable
91 Now the table name 'mytable' should appear.
92
93 Doesn't work? Check with 'isql ' if the ODBC-PostgreSQL connec‐
94 tion is really established.
95 Note that you can also connect mySQL, Oracle etc. through ODBC to
96 GRASS. You can also check the vector map itself concerning a current
97 link to a table:
98 v.db.connect -p mytable.shp
99 which should print the database connection through ODBC to the defined
100 RDBMS.
101
103 db.connect, v.db.connect, unixODBC web site, SQL support in GRASS GIS
104
105 Last changed: $Date: 2007-07-18 16:10:27 +0200 (Wed, 18 Jul 2007) $
106 Help Index
107
108
109
110GRASS 6.3.0 grass-odbc(1)