dbmi.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 "dbf"
  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. char *string;
  107. int nalloc;
  108. } dbString;
  109. typedef struct _dbmscap {
  110. char driverName[256]; /* symbolic name for the dbms system */
  111. char startup[256]; /* command to run the driver */
  112. char comment[256]; /* comment field */
  113. struct _dbmscap *next; /* linked list */
  114. } dbDbmscap;
  115. typedef struct _db_dirent {
  116. dbString name; /* file/dir name */
  117. int isdir; /* bool: name is a directory */
  118. int perm; /* permissions */
  119. } dbDirent;
  120. typedef struct _db_driver {
  121. dbDbmscap dbmscap; /* dbmscap entry for this driver */
  122. FILE *send, *recv; /* i/o to-from driver */
  123. int pid; /* process id of the driver */
  124. } dbDriver;
  125. typedef struct _db_handle {
  126. dbString dbName; /* database name */
  127. /* dbString dbPath; */ /* directory containing dbName */
  128. dbString dbSchema; /* database schema */
  129. } dbHandle;
  130. typedef struct _db_date_time {
  131. char current;
  132. int year;
  133. int month;
  134. int day;
  135. int hour;
  136. int minute;
  137. double seconds;
  138. } dbDateTime;
  139. typedef struct _db_value {
  140. char isNull;
  141. int i;
  142. double d;
  143. dbString s;
  144. dbDateTime t;
  145. } dbValue;
  146. typedef struct _db_column {
  147. dbString columnName;
  148. dbString description;
  149. int sqlDataType;
  150. int hostDataType;
  151. dbValue value;
  152. int dataLen;
  153. int precision;
  154. int scale;
  155. char nullAllowed;
  156. char hasDefaultValue;
  157. char useDefaultValue;
  158. dbValue defaultValue;
  159. int select;
  160. int update;
  161. } dbColumn;
  162. typedef struct _db_table {
  163. dbString tableName;
  164. dbString description;
  165. int numColumns;
  166. dbColumn * columns;
  167. int priv_insert;
  168. int priv_delete;
  169. } dbTable;
  170. typedef struct _db_cursor {
  171. dbToken token;
  172. dbDriver *driver;
  173. dbTable *table;
  174. short *column_flags;
  175. int type;
  176. int mode;
  177. } dbCursor;
  178. typedef struct _db_index {
  179. dbString indexName;
  180. dbString tableName;
  181. int numColumns;
  182. dbString * columnNames;
  183. char unique;
  184. } dbIndex;
  185. typedef struct _db_driver_state
  186. {
  187. char *dbname;
  188. char *dbschema;
  189. int open;
  190. int ncursors;
  191. dbCursor **cursor_list;
  192. }dbDriverState;
  193. /* category value (integer) */
  194. typedef struct
  195. {
  196. int cat; /* category */
  197. int val; /* value */
  198. }dbCatValI;
  199. /* category value */
  200. typedef struct
  201. {
  202. int cat; /* category */
  203. int isNull;
  204. union {
  205. int i;
  206. double d;
  207. /* s and t were added 22.8.2005, both are pointers,
  208. * they so should not take more than 8 bytes.
  209. * It would be better to add dbString, not pointer,
  210. * But it could be > 8 bytes on some systems */
  211. dbString *s;
  212. dbDateTime *t;
  213. } val;
  214. }dbCatVal;
  215. /* category value array */
  216. typedef struct
  217. {
  218. int n_values;
  219. int alloc;
  220. int ctype; /* C type of values stored in array DB_C_TYPE_* */
  221. dbCatVal *value;
  222. }dbCatValArray;
  223. /* parameters of connection */
  224. typedef struct _db_connection
  225. {
  226. char *driverName;
  227. /* char *hostName; */
  228. char *databaseName;
  229. char *schemaName;
  230. char *location;
  231. char *user;
  232. char *password;
  233. char *keycol; /* name of default key column */
  234. char *group; /* deafault group to which select privilege is granted */
  235. }dbConnection;
  236. /* reclass rule */
  237. typedef struct
  238. {
  239. int count; /* number of defined rules */
  240. int alloc; /* size of allocated array */
  241. char *table; /* table name */
  242. char *key; /* key column name */
  243. int *cat; /* array of new category numbers */
  244. char **where; /* array of SQL WHERE conditions */
  245. char **label; /* array of new category labels */
  246. }dbRclsRule;
  247. #include <grass/proto_dbmi.h>
  248. #endif