GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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 8192
143 
144 typedef void *dbAddress;
145 typedef int dbToken;
146 
147 typedef struct _db_string
148 {
149  char *string;
150  int nalloc;
151 } dbString;
152 
153 typedef struct _dbmscap
154 {
155  char driverName[256]; /* symbolic name for the dbms system */
156  char startup[256]; /* command to run the driver */
157  char comment[256]; /* comment field */
158  struct _dbmscap *next; /* linked list */
159 } dbDbmscap;
160 
161 typedef struct _db_dirent
162 {
163  dbString name; /* file/dir name */
164  int isdir; /* bool: name is a directory */
165  int perm; /* permissions */
166 } dbDirent;
167 
168 typedef struct _db_driver
169 {
170  dbDbmscap dbmscap; /* dbmscap entry for this driver */
171  FILE *send, *recv; /* i/o to-from driver */
172  int pid; /* process id of the driver */
173 } dbDriver;
174 
175 typedef struct _db_handle
176 {
177  dbString dbName; /* database name */
178  /* dbString dbPath; *//* directory containing dbName */
179  dbString dbSchema; /* database schema */
180 } dbHandle;
181 
182 typedef struct _db_date_time
183 {
184  char current;
185  int year;
186  int month;
187  int day;
188  int hour;
189  int minute;
190  double seconds;
191 } dbDateTime;
192 
193 typedef struct _db_value
194 {
195  char isNull;
196  int i;
197  double d;
200 } dbValue;
201 
202 typedef struct _db_column
203 {
209  int dataLen;
211  int scale;
216  int select;
217  int update;
218 } dbColumn;
219 
220 typedef struct _db_table
221 {
228 } dbTable;
229 
230 typedef struct _db_cursor
231 {
235  short *column_flags;
236  int type;
237  int mode;
238 } dbCursor;
239 
240 typedef struct _db_index
241 {
246  char unique;
247 } dbIndex;
248 
249 typedef struct _db_driver_state
250 {
251  char *dbname;
252  char *dbschema;
253  int open;
254  int ncursors;
256 } dbDriverState;
257 
258 /* category value (integer) */
259 typedef struct
260 {
261  int cat; /* category */
262  int val; /* value */
263 } dbCatValI;
264 
265 /* category value */
266 typedef struct
267 {
268  int cat; /* category */
269  int isNull;
270  union
271  {
272  int i;
273  double d;
274  /* s and t were added 22.8.2005, both are pointers,
275  * they so should not take more than 8 bytes.
276  * It would be better to add dbString, not pointer,
277  * But it could be > 8 bytes on some systems */
280  } val;
281 } dbCatVal;
282 
283 /* category value array */
284 typedef struct
285 {
286  int n_values;
287  int alloc;
288  int ctype; /* C type of values stored in array DB_C_TYPE_* */
290 } dbCatValArray;
291 
292 /* parameters of connection */
293 typedef struct _db_connection
294 {
295  char *driverName;
296  char *hostName;
298  char *schemaName;
299  char *port;
300  char *user;
301  char *password;
302  char *keycol; /* name of default key column */
303  char *group; /* default group to which select privilege is granted */
304 } dbConnection;
305 
306 /* reclass rule */
307 typedef struct
308 {
309  int count; /* number of defined rules */
310  int alloc; /* size of allocated array */
311  char *table; /* table name */
312  char *key; /* key column name */
313  int *cat; /* array of new category numbers */
314  char **where; /* array of SQL WHERE conditions */
315  char **label; /* array of new category labels */
316 } dbRclsRule;
317 
318 #include <grass/defs/dbmi.h>
319 
320 #endif
int hostDataType
Definition: dbmi.h:207
double d
Definition: dbmi.h:197
int isNull
Definition: dbmi.h:269
int minute
Definition: dbmi.h:189
struct _dbmscap * next
Definition: dbmi.h:158
Definition: dbmi.h:153
struct _db_date_time dbDateTime
dbString dbName
Definition: dbmi.h:177
dbString name
Definition: dbmi.h:163
char * key
Definition: dbmi.h:312
int n_values
Definition: dbmi.h:286
dbValue value
Definition: dbmi.h:208
dbString s
Definition: dbmi.h:198
struct _db_string dbString
dbString columnName
Definition: dbmi.h:204
int ctype
Definition: dbmi.h:288
dbColumn * columns
Definition: dbmi.h:225
struct _db_cursor dbCursor
struct _db_value dbValue
int hour
Definition: dbmi.h:188
dbDbmscap dbmscap
Definition: dbmi.h:170
int alloc
Definition: dbmi.h:310
int priv_delete
Definition: dbmi.h:227
struct _db_handle dbHandle
int dbToken
Definition: dbmi.h:145
int numColumns
Definition: dbmi.h:244
dbString description
Definition: dbmi.h:223
char hasDefaultValue
Definition: dbmi.h:213
dbString indexName
Definition: dbmi.h:242
dbString tableName
Definition: dbmi.h:222
int scale
Definition: dbmi.h:211
char * keycol
Definition: dbmi.h:302
dbCatVal * value
Definition: dbmi.h:289
dbDateTime * t
Definition: dbmi.h:279
int alloc
Definition: dbmi.h:287
int numColumns
Definition: dbmi.h:224
int perm
Definition: dbmi.h:165
int ncursors
Definition: dbmi.h:254
char * schemaName
Definition: dbmi.h:298
dbDriver * driver
Definition: dbmi.h:233
char ** where
Definition: dbmi.h:314
struct _db_table dbTable
struct _db_dirent dbDirent
int select
Definition: dbmi.h:216
struct _db_connection dbConnection
int type
Definition: dbmi.h:236
void * dbAddress
Definition: dbmi.h:144
char * databaseName
Definition: dbmi.h:297
int cat
Definition: dbmi.h:268
Definition: dbmi.h:266
struct _db_driver dbDriver
char unique
Definition: dbmi.h:246
struct _dbmscap dbDbmscap
char * dbschema
Definition: dbmi.h:252
char * string
Definition: dbmi.h:149
int i
Definition: dbmi.h:272
int * cat
Definition: dbmi.h:313
int val
Definition: dbmi.h:262
double seconds
Definition: dbmi.h:190
dbToken token
Definition: dbmi.h:232
dbCursor ** cursor_list
Definition: dbmi.h:255
char * driverName
Definition: dbmi.h:295
dbDateTime t
Definition: dbmi.h:199
dbString description
Definition: dbmi.h:205
char * table
Definition: dbmi.h:311
dbString * s
Definition: dbmi.h:278
dbString tableName
Definition: dbmi.h:243
int pid
Definition: dbmi.h:172
short * column_flags
Definition: dbmi.h:235
char * port
Definition: dbmi.h:299
char * password
Definition: dbmi.h:301
int cat
Definition: dbmi.h:261
int dataLen
Definition: dbmi.h:209
char * hostName
Definition: dbmi.h:296
char * dbname
Definition: dbmi.h:251
int i
Definition: dbmi.h:196
struct _db_index dbIndex
dbValue defaultValue
Definition: dbmi.h:215
char current
Definition: dbmi.h:184
char isNull
Definition: dbmi.h:195
int isdir
Definition: dbmi.h:164
int nalloc
Definition: dbmi.h:150
char useDefaultValue
Definition: dbmi.h:214
int precision
Definition: dbmi.h:210
int count
Definition: dbmi.h:309
int month
Definition: dbmi.h:186
int priv_insert
Definition: dbmi.h:226
dbString dbSchema
Definition: dbmi.h:179
struct _db_column dbColumn
int year
Definition: dbmi.h:185
int mode
Definition: dbmi.h:237
int update
Definition: dbmi.h:217
FILE * send
Definition: dbmi.h:171
dbTable * table
Definition: dbmi.h:234
int day
Definition: dbmi.h:187
double d
Definition: dbmi.h:273
struct _db_driver_state dbDriverState
char * group
Definition: dbmi.h:303
char * user
Definition: dbmi.h:300
int sqlDataType
Definition: dbmi.h:206
char nullAllowed
Definition: dbmi.h:212
dbString * columnNames
Definition: dbmi.h:245
char ** label
Definition: dbmi.h:315