dbmi.h 6.7 KB

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