1grass-odbc(1) Grass User's Manual grass-odbc(1)
2
3
4
6 Communication between GRASS and ODBC database for attribute management:
7
8 GRASS module <-> <--> ODBC Interface <--> RDBMS
9
10 GRASS DBMI driver unixODBC ODBC driver PostgreSQL
11
12 Oracle
13
14 ...
15
16
18 All SQL commands supported by ODBC.
19
21 All SQL operators supported by ODBC.
22
24 In this example we copy the dbf file of a SHAPE map into ODBC, then
25 connect GRASS to the ODBC DBMS. Usually the table will be already
26 present in the DBMS.
27
28 Defining the ODBC connection
29 MS-Windows
30 On MS-Windows, in order to be able to connect, the ODBC connection
31 needs to be configured using dedicated tools (tool called "ODBC Data
32 Source Administrator") and give a name to that connection. This name is
33 then used as database name when accessing from a client via ODBC.
34
35 Linux
36 Configure ODBC driver for selected database (manually or with ’ODBC‐
37 Config’). ODBC drivers are defined in /etc/odbcinst.ini. Here an exam‐
38 ple:
39
40 [PostgreSQL]
41 Description = ODBC for PostgreSQL
42 Driver = /usr/lib/libodbcpsql.so
43 Setup = /usr/lib/libodbcpsqlS.so
44 FileUsage = 1
45
46 Create DSN (data source name). The DSN is used as database name in db.*
47 modules. Then DSN must be defined in $HOME/.odbc.ini (for this user
48 only) or in /etc/odbc.ini for (for all users) [watch out for the data‐
49 base name which appears twice and also for the PostgreSQL protocol ver‐
50 sion]. Omit blanks at the beginning of lines:
51
52 [grass6test]
53 Description = PostgreSQL
54 Driver = PostgreSQL
55 Trace = No
56 TraceFile =
57 Database = grass6test
58 Servername = localhost
59 UserName = neteler
60 Password =
61 Port = 5432
62 Protocol = 8.0
63 ReadOnly = No
64 RowVersioning = No
65 ShowSystemTables = No
66 ShowOidColumn = No
67 FakeOidIndex = No
68 ConnSettings =
69 Configuration of an DSN without GUI is described on
70 http://www.unixodbc.org/odbcinst.html, but odbc.ini and .odbc.ini may
71 be created by the ’ODBCConfig’ tool. You can easily view your DSN
72 structure by ’DataManager’. Configuration with GUI is described on
73 http://www.unixodbc.org/doc/UserManual/
74
75 To find out about your PostgreSQL protocol, run:
76 psql -V
77
78 Using the ODBC driver
79 Now create a new database if not yet existing:
80
81 db.createdb driver=odbc database=grass6test
82
83 To store a table ’mytable.dbf’ (here: in current directory) into Post‐
84 greSQL through ODBC, run:
85
86 db.connect driver=odbc database=grass6test
87 db.copy from_driver=dbf from_database=./ from_table=mytable \
88 to_driver=odbc to_database=grass6test to_table=mytable
89
90 Next link the map to the attribute table (now the ODBC table is used,
91 not the dbf file):
92
93 v.db.connect map=mytable.shp table=mytable key=ID \
94 database=grass6test driver=odbc
95 v.db.connect -p
96
97 Finally a test: Here we should see the table columns (if the ODBC con‐
98 nection works):
99 db.tables -p
100 db.columns table=mytable
101
102 Now the table name ’mytable’ should appear.
103 Doesn’t work? Check with ’isql <databasename>’ if the ODBC-PostgreSQL
104 connection is really established.
105
106 Note that you can also connect mySQL, Oracle etc. through ODBC to
107 GRASS.
108
109 You can also check the vector map itself concerning a current link to a
110 table:
111
112 v.db.connect -p mytable.shp
113
114 which should print the database connection through ODBC to the defined
115 RDBMS.
116
118 db.connect, v.db.connect, unixODBC web site, SQL support in GRASS GIS
119
120 Last changed: $Date: 2014-04-20 12:28:15 +0200 (Sun, 20 Apr 2014) $
121
122 Main index | Topics index | Keywords index | Graphical index | Full
123 index
124
125 © 2003-2019 GRASS Development Team, GRASS GIS 7.4.4 Reference Manual
126
127
128
129GRASS 7.4.4 grass-odbc(1)