dbmi.h 7.1 KB

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