GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-535c39c9fc
dbmi.h
Go to the documentation of this file.
1 /*!
2  \file include/dbmi.h
3 
4  \brief Main header of \ref dbmilib
5 
6  (C) 1999-2009, 2011 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10  */
11 
12 #ifndef GRASS_DBMI_H
13 #define GRASS_DBMI_H
14 
15 #include <stdio.h>
16 #include <grass/gis.h>
17 
18 #define DB_VERSION "0"
19 
20 #ifdef HAVE_SQLITE
21 #define DB_DEFAULT_DRIVER "sqlite"
22 #else
23 #define DB_DEFAULT_DRIVER "dbf"
24 #endif
25 
26 /* DB Prodedure Numbers */
27 #define DB_PROC_VERSION 999
28 
29 #define DB_PROC_CLOSE_DATABASE 101
30 #define DB_PROC_CREATE_DATABASE 102
31 #define DB_PROC_DELETE_DATABASE 103
32 #define DB_PROC_FIND_DATABASE 104
33 #define DB_PROC_LIST_DATABASES 105
34 #define DB_PROC_OPEN_DATABASE 106
35 #define DB_PROC_SHUTDOWN_DRIVER 107
36 
37 #define DB_PROC_CLOSE_CURSOR 201
38 #define DB_PROC_DELETE 202
39 #define DB_PROC_FETCH 203
40 #define DB_PROC_INSERT 204
41 #define DB_PROC_OPEN_INSERT_CURSOR 205
42 #define DB_PROC_OPEN_SELECT_CURSOR 206
43 #define DB_PROC_OPEN_UPDATE_CURSOR 207
44 #define DB_PROC_UPDATE 208
45 #define DB_PROC_ROWS 209
46 #define DB_PROC_BIND_UPDATE 220
47 #define DB_PROC_BIND_INSERT 221
48 
49 #define DB_PROC_EXECUTE_IMMEDIATE 301
50 #define DB_PROC_BEGIN_TRANSACTION 302
51 #define DB_PROC_COMMIT_TRANSACTION 303
52 
53 #define DB_PROC_CREATE_TABLE 401
54 #define DB_PROC_DESCRIBE_TABLE 402
55 #define DB_PROC_DROP_TABLE 403
56 #define DB_PROC_LIST_TABLES 404
57 #define DB_PROC_ADD_COLUMN 405
58 #define DB_PROC_DROP_COLUMN 406
59 #define DB_PROC_GRANT_ON_TABLE 407
60 
61 #define DB_PROC_CREATE_INDEX 701
62 #define DB_PROC_LIST_INDEXES 702
63 #define DB_PROC_DROP_INDEX 703
64 
65 /* Unix file permissions */
66 #define DB_PERM_R 01
67 #define DB_PERM_W 02
68 #define DB_PERM_X 04
69 
70 /* DB Error codes */
71 #define DB_OK 0
72 #define DB_FAILED 1
73 #define DB_NOPROC 2
74 #define DB_MEMORY_ERR -1
75 #define DB_PROTOCOL_ERR -2
76 #define DB_EOF -1
77 
78 /* dbColumn.sqlDataType */
79 #define DB_SQL_TYPE_UNKNOWN 0
80 
81 #define DB_SQL_TYPE_CHARACTER 1
82 #define DB_SQL_TYPE_SMALLINT 2
83 #define DB_SQL_TYPE_INTEGER 3
84 #define DB_SQL_TYPE_REAL 4
85 #define DB_SQL_TYPE_DOUBLE_PRECISION 6
86 #define DB_SQL_TYPE_DECIMAL 7
87 #define DB_SQL_TYPE_NUMERIC 8
88 #define DB_SQL_TYPE_DATE 9
89 #define DB_SQL_TYPE_TIME 10
90 #define DB_SQL_TYPE_TIMESTAMP 11
91 #define DB_SQL_TYPE_INTERVAL 12
92 #define DB_SQL_TYPE_TEXT 13 /* length not defined */
93 
94 #define DB_SQL_TYPE_SERIAL 21
95 
96 /* these are OR'ed (|) with the TIMESTAMP and INTERVAL type */
97 #define DB_YEAR 0x4000
98 #define DB_MONTH 0x2000
99 #define DB_DAY 0x1000
100 #define DB_HOUR 0x0800
101 #define DB_MINUTE 0x0400
102 #define DB_SECOND 0x0200
103 #define DB_FRACTION 0x0100
104 #define DB_DATETIME_MASK 0xFF00
105 
106 /* dbColumn.CDataType */
107 #define DB_C_TYPE_STRING 1
108 #define DB_C_TYPE_INT 2
109 #define DB_C_TYPE_DOUBLE 3
110 #define DB_C_TYPE_DATETIME 4
111 
112 /* fetch positions */
113 #define DB_CURRENT 1
114 #define DB_NEXT 2
115 #define DB_PREVIOUS 3
116 #define DB_FIRST 4
117 #define DB_LAST 5
118 
119 /* cursor modes/types */
120 #define DB_READONLY 1
121 #define DB_INSERT 2
122 #define DB_UPDATE 3
123 #define DB_SEQUENTIAL 0
124 #define DB_SCROLL 1
125 #define DB_INSENSITIVE 4
126 
127 /* privilege modes */
128 #define DB_GRANTED 1
129 #define DB_NOT_GRANTED -1
130 
131 /* Privileges */
132 #define DB_PRIV_SELECT 0x01
133 
134 #define DB_GROUP 0x01
135 #define DB_PUBLIC 0x02
136 
137 /* default value modes */
138 #define DB_DEFINED 1
139 #define DB_UNDEFINED 2
140 
141 /* static buffer for SQL statements */
142 #define DB_SQL_MAX 65536
143 
144 typedef void *dbAddress;
145 typedef int dbToken;
146 
147 typedef struct _db_string {
148  char *string;
149  int nalloc;
151 
152 typedef struct _dbmscap {
153  char driverName[256]; /* symbolic name for the dbms system */
154  char startup[256]; /* command to run the driver */
155  char comment[256]; /* comment field */
156  struct _dbmscap *next; /* linked list */
158 
159 typedef struct _db_dirent {
160  dbString name; /* file/dir name */
161  int isdir; /* bool: name is a directory */
162  int perm; /* permissions */
164 
165 typedef struct _db_driver {
166  dbDbmscap dbmscap; /* dbmscap entry for this driver */
167  FILE *send, *recv; /* i/o to-from driver */
168  int pid; /* process id of the driver */
170 
171 typedef struct _db_handle {
172  dbString dbName; /* database name */
173  /* dbString dbPath; */ /* directory containing dbName */
174  dbString dbSchema; /* database schema */
176 
177 typedef struct _db_date_time {
178  char current;
179  int year;
180  int month;
181  int day;
182  int hour;
183  int minute;
184  double seconds;
186 
187 typedef struct _db_value {
188  char isNull;
189  int i;
190  double d;
194 
195 typedef struct _db_column {
201  int dataLen;
203  int scale;
208  int select;
209  int update;
211 
212 typedef struct _db_table {
220 
221 typedef struct _db_cursor {
225  short *column_flags;
226  int type;
227  int mode;
229 
230 typedef struct _db_index {
235  char unique;
237 
238 typedef struct _db_driver_state {
239  char *dbname;
240  char *dbschema;
241  int open;
242  int ncursors;
245 
246 /* category value (integer) */
247 typedef struct {
248  int cat; /* category */
249  int val; /* value */
250 } dbCatValI;
251 
252 /* category value */
253 typedef struct {
254  int cat; /* category */
255  int isNull;
256  union {
257  int i;
258  double d;
259  /* s and t were added 22.8.2005, both are pointers,
260  * they so should not take more than 8 bytes.
261  * It would be better to add dbString, not pointer,
262  * But it could be > 8 bytes on some systems */
265  } val;
266 } dbCatVal;
267 
268 /* category value array */
269 typedef struct {
270  int n_values;
271  int alloc;
272  int ctype; /* C type of values stored in array DB_C_TYPE_* */
274 } dbCatValArray;
275 
276 /* parameters of connection */
277 typedef struct _db_connection {
278  char *driverName;
279  char *hostName;
281  char *schemaName;
282  char *port;
283  char *user;
284  char *password;
285  char *keycol; /* name of default key column */
286  char *group; /* default group to which select privilege is granted */
288 
289 /* reclass rule */
290 typedef struct {
291  int count; /* number of defined rules */
292  int alloc; /* size of allocated array */
293  char *table; /* table name */
294  char *key; /* key column name */
295  int *cat; /* array of new category numbers */
296  char **where; /* array of SQL WHERE conditions */
297  char **label; /* array of new category labels */
298 } dbRclsRule;
299 
300 #include <grass/defs/dbmi.h>
301 
302 #endif
struct _db_date_time dbDateTime
struct _db_index dbIndex
struct _db_cursor dbCursor
struct _db_column dbColumn
int dbToken
Definition: dbmi.h:145
struct _db_table dbTable
struct _db_driver dbDriver
struct _db_value dbValue
struct _db_connection dbConnection
struct _db_dirent dbDirent
struct _db_string dbString
struct _db_handle dbHandle
struct _db_driver_state dbDriverState
struct _dbmscap dbDbmscap
void * dbAddress
Definition: dbmi.h:144
char nullAllowed
Definition: dbmi.h:204
char hasDefaultValue
Definition: dbmi.h:205
int select
Definition: dbmi.h:208
int update
Definition: dbmi.h:209
dbValue defaultValue
Definition: dbmi.h:207
int precision
Definition: dbmi.h:202
dbValue value
Definition: dbmi.h:200
char useDefaultValue
Definition: dbmi.h:206
dbString columnName
Definition: dbmi.h:196
int hostDataType
Definition: dbmi.h:199
int dataLen
Definition: dbmi.h:201
int scale
Definition: dbmi.h:203
dbString description
Definition: dbmi.h:197
int sqlDataType
Definition: dbmi.h:198
char * password
Definition: dbmi.h:284
char * hostName
Definition: dbmi.h:279
char * schemaName
Definition: dbmi.h:281
char * port
Definition: dbmi.h:282
char * group
Definition: dbmi.h:286
char * user
Definition: dbmi.h:283
char * databaseName
Definition: dbmi.h:280
char * keycol
Definition: dbmi.h:285
char * driverName
Definition: dbmi.h:278
short * column_flags
Definition: dbmi.h:225
dbDriver * driver
Definition: dbmi.h:223
int mode
Definition: dbmi.h:227
dbTable * table
Definition: dbmi.h:224
int type
Definition: dbmi.h:226
dbToken token
Definition: dbmi.h:222
int day
Definition: dbmi.h:181
int year
Definition: dbmi.h:179
int minute
Definition: dbmi.h:183
int hour
Definition: dbmi.h:182
double seconds
Definition: dbmi.h:184
int month
Definition: dbmi.h:180
char current
Definition: dbmi.h:178
dbString name
Definition: dbmi.h:160
int perm
Definition: dbmi.h:162
int isdir
Definition: dbmi.h:161
dbCursor ** cursor_list
Definition: dbmi.h:243
char * dbname
Definition: dbmi.h:239
char * dbschema
Definition: dbmi.h:240
int ncursors
Definition: dbmi.h:242
int pid
Definition: dbmi.h:168
FILE * recv
Definition: dbmi.h:167
dbDbmscap dbmscap
Definition: dbmi.h:166
FILE * send
Definition: dbmi.h:167
dbString dbSchema
Definition: dbmi.h:174
dbString dbName
Definition: dbmi.h:172
dbString * columnNames
Definition: dbmi.h:234
int numColumns
Definition: dbmi.h:233
dbString indexName
Definition: dbmi.h:231
dbString tableName
Definition: dbmi.h:232
char unique
Definition: dbmi.h:235
int nalloc
Definition: dbmi.h:149
char * string
Definition: dbmi.h:148
dbString tableName
Definition: dbmi.h:213
int priv_insert
Definition: dbmi.h:217
int priv_delete
Definition: dbmi.h:218
int numColumns
Definition: dbmi.h:215
dbString description
Definition: dbmi.h:214
dbColumn * columns
Definition: dbmi.h:216
dbString s
Definition: dbmi.h:191
dbDateTime t
Definition: dbmi.h:192
char isNull
Definition: dbmi.h:188
double d
Definition: dbmi.h:190
int i
Definition: dbmi.h:189
Definition: dbmi.h:152
char comment[256]
Definition: dbmi.h:155
char startup[256]
Definition: dbmi.h:154
char driverName[256]
Definition: dbmi.h:153
struct _dbmscap * next
Definition: dbmi.h:156
int alloc
Definition: dbmi.h:271
int ctype
Definition: dbmi.h:272
int n_values
Definition: dbmi.h:270
dbCatVal * value
Definition: dbmi.h:273
int cat
Definition: dbmi.h:248
int val
Definition: dbmi.h:249
Definition: dbmi.h:253
dbDateTime * t
Definition: dbmi.h:264
int isNull
Definition: dbmi.h:255
int cat
Definition: dbmi.h:254
int i
Definition: dbmi.h:257
dbString * s
Definition: dbmi.h:263
double d
Definition: dbmi.h:258
int count
Definition: dbmi.h:291
char ** label
Definition: dbmi.h:297
char ** where
Definition: dbmi.h:296
int alloc
Definition: dbmi.h:292
char * table
Definition: dbmi.h:293
char * key
Definition: dbmi.h:294
int * cat
Definition: dbmi.h:295