dbmi.h 7.1 KB

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