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