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