dbmilib.dox 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*! \page dbmilib GRASS DataBase Management Interface
  2. by GRASS Development Team
  3. http://grass.osgeo.org
  4. \section dbmiIntro Introduction
  5. The attribute management was completely changed in GRASS 6 to achieve
  6. multi-attribute capabilities managed within external databases. The
  7. former <tt>dig_cats/</tt> files (GRASS 5) are not used any more and
  8. all vector attributes are stored in external database. Connection with
  9. database is done through <b>DBMI library</b> (DataBase Management
  10. Interface) with its integrated drivers. At time of this writing
  11. following DBMI drivers for attribute storage are available:
  12. - DBF: xBase files (default)
  13. - ODBC: to interface from http://www.unixodbc.org
  14. - PostgreSQL driver (note that PostgreSQL can also be accessed through ODBC): http://www.postgresql.org
  15. - mySQL: http://mysql.com/
  16. - SQLite: http://www.sqlite.org
  17. These drivers are compiled depending on present DB related libraries
  18. and 'configure' settings. Only the DBF driver is always compiled. The
  19. default DBMI driver is defined in dbmi.h
  20. \code
  21. #define DB_DEFAULT_DRIVER "sqlite"
  22. \endcode
  23. In general records in table are linked to vector entities by field number
  24. and category number. The field number identifies a database table and the
  25. category number identifies the record record. I.e. for unique combination
  26. <tt>mapset + map + field + category</tt> exists one unique combination
  27. <tt>driver + database + table + row</tt>. Each element may have none, one or
  28. more categories (cats). More cats are distinguished by field number (field).
  29. The flexibility of this approach even supports the extreme case, that one
  30. vector entity may be linked to attributes in different tables in different
  31. databases connected by different drivers at the same time.
  32. The DBMI library contains drivers such as DBF, SQLite, ODBC, MySQL and
  33. PostgreSQL. The functionality of the database support varies with the
  34. capabilities of the underlying RDBMS. Main features are
  35. multi-attributes support for various data types, also multiple tables
  36. may optionally be linked to one or many vector entity/ies. SQL
  37. (Structured Query Language) is used for all drivers, but in a limited
  38. implementation.
  39. For DBMI architecture details please read Blazek et al. 2002 (see below).
  40. \section dbmiFunc DBMI library functions
  41. The <tt>db_*()</tt> functions are the programmer's API for GRASS DBMI
  42. programming. There are three groups:
  43. - <b>dbmi_base</b>: contains functions for modules, drivers (<tt>../../db/drivers/</tt>)
  44. - <b>dbmi_client</b>: contains functions for modules
  45. - <b>dbmi_driver</b>: contains functions for drivers (<tt>../../db/drivers/</tt>)
  46. \section dbmiBase DBMI BASE functions
  47. Allocation:
  48. - db_store()
  49. - db_malloc()
  50. - db_calloc()
  51. - db_realloc()
  52. - db_free()
  53. String manipulation:
  54. - db_char_to_lowercase()
  55. - db_char_to_uppercase()
  56. - db_Cstring_to_lowercase()
  57. - db_Cstring_to_uppercase()
  58. - db_nocase_compare()
  59. Column properties:
  60. - db_get_column_value()
  61. - db_get_column_default_value()
  62. - db_set_column_sqltype()
  63. - db_set_column_host_type()
  64. - db_get_column_scale()
  65. - db_set_column_scale()
  66. - db_get_column_precision()
  67. - db_set_column_precision()
  68. - db_get_column_sqltype()
  69. - db_get_column_host_type()
  70. - db_set_column_has_defined_default_value()
  71. - db_set_column_has_undefined_default_value()
  72. - db_unset_column_has_default_value()
  73. - db_test_column_has_default_value()
  74. - db_test_column_has_defined_default_value()
  75. - db_test_column_has_undefined_default_value()
  76. - db_set_column_use_default_value()
  77. - db_unset_column_use_default_value()
  78. - db_test_column_use_default_value()
  79. - db_set_column_null_allowed()
  80. - db_unset_column_null_allowed()
  81. - db_test_column_null_allowed()
  82. - db_get_column_length()
  83. - db_set_column_length()
  84. - db_set_column_select_priv_granted()
  85. - db_set_column_select_priv_not_granted()
  86. - db_get_column_select_priv()
  87. - db_set_column_update_priv_granted()
  88. - db_set_column_update_priv_not_granted()
  89. - db_get_column_update_priv()
  90. - db_init_column()
  91. - db_set_column_name()
  92. - db_get_column_name()
  93. - db_set_column_description()
  94. - db_get_column_description()
  95. - db_free_column()
  96. - db_copy_column()
  97. - db_convert_Cstring_to_column_value()
  98. - db_convert_Cstring_to_column_default_value()
  99. - db_convert_column_value_to_string()
  100. - db_convert_column_default_value_to_string()
  101. Connection settings:
  102. - db_set_connection()
  103. - db_get_connection()
  104. Cursor management:
  105. - db_init_cursor()
  106. - db_alloc_cursor_table()
  107. - db_free_cursor()
  108. - db_get_cursor_table()
  109. - db_set_cursor_table()
  110. - db_get_cursor_token()
  111. - db_set_cursor_token()
  112. - db_set_cursor_type_readonly()
  113. - db_set_cursor_type_update()
  114. - db_set_cursor_type_insert()
  115. - db_test_cursor_type_fetch()
  116. - db_test_cursor_type_update()
  117. - db_test_cursor_type_insert()
  118. - db_set_cursor_mode()
  119. - db_set_cursor_mode_scroll()
  120. - db_unset_cursor_mode_scroll()
  121. - db_unset_cursor_mode()
  122. - db_set_cursor_mode_insensitive()
  123. - db_unset_cursor_mode_insensitive()
  124. - db_test_cursor_mode_scroll()
  125. - db_test_cursor_mode_insensitive()
  126. - db_alloc_cursor_column_flags()
  127. - db_free_cursor_column_flags()
  128. - db_set_cursor_column_for_update()
  129. - db_unset_cursor_column_for_update()
  130. - db_test_cursor_column_for_update()
  131. - db_test_cursor_any_column_for_update()
  132. - db_set_cursor_column_flag()
  133. - db_unset_cursor_column_flag()
  134. - db_test_cursor_column_flag()
  135. - db_get_cursor_number_of_columns()
  136. - db_test_cursor_any_column_flag()
  137. DateTime conversion:
  138. - db_convert_value_datetime_into_string()
  139. - db_convert_Cstring_to_value_datetime()
  140. DBmscap management:
  141. - db_dbmscap_filename()
  142. - db_has_dbms()
  143. - db_copy_dbmscap_entry()
  144. - db_read_dbmscap()
  145. - db_free_dbmscap()
  146. Default settings:
  147. - db_get_default_driver_name()
  148. - db_get_default_database_name()
  149. - db_get_default_schema_name()
  150. - db_get_default_group_name()
  151. - db_set_default_connection()
  152. Dirent (directory entities) array:
  153. - db_dirent()
  154. - db_free_dirent_array()
  155. - db_alloc_dirent_array()
  156. Report errors:
  157. - db_on_error()
  158. - db_set_error_who()
  159. - db_get_error_who()
  160. - db_error()
  161. - db_protocol_error()
  162. - db_syserror()
  163. - db_get_error_code()
  164. - db_memory_error()
  165. - db_procedure_not_implemented()
  166. - db_noproc_error()
  167. - db_clear_error()
  168. - db_print_error()
  169. - db_debug_on()
  170. - db_debug_off()
  171. - db_debug()
  172. - db_get_error_msg()
  173. - db_auto_print_errors()
  174. - db_auto_print_protocol_errors()
  175. Handle management:
  176. - db_init_handle()
  177. - db_set_handle()
  178. - db_get_handle_dbname()
  179. - db_get_handle_dbschema()
  180. - db_free_handle()
  181. - db_free_handle_array()
  182. - db_alloc_handle_array()
  183. Index management:
  184. - db_init_index()
  185. - db_free_index()
  186. - db_alloc_index_columns()
  187. - db_alloc_index_array()
  188. - db_free_index_array()
  189. - db_set_index_name()
  190. - db_get_index_name()
  191. - db_set_index_table_name()
  192. - db_get_index_table_name()
  193. - db_get_index_number_of_columns()
  194. - db_set_index_column_name()
  195. - db_get_index_column_name()
  196. - db_set_index_type_unique()
  197. - db_set_index_type_non_unique()
  198. - db_test_index_type_unique()
  199. - db_print_index()
  200. Range functions:
  201. - db_interval_range()
  202. Login functions:
  203. - db_set_login()
  204. - db_get_login()
  205. Return codes (internal use only):
  206. - db__send_success()
  207. - db__send_failure()
  208. - db__recv_return_code()
  209. Data type conversion:
  210. - db_sqltype_to_Ctype()
  211. - db_sqltype_name()
  212. String manipulation:
  213. - db_init_string()
  214. - db_set_string()
  215. - db_set_string_no_copy()
  216. - db_sizeof_string()
  217. - db_zero_string()
  218. - db_enlarge_string()
  219. - db_get_string()
  220. - db_free_string()
  221. - db_free_string_array()
  222. - db_alloc_string_array()
  223. - db_append_string()
  224. - db_copy_string()
  225. - db_double_quote_string()
  226. Table/privileges management:
  227. - db_alloc_table()
  228. - db_init_table()
  229. - db_free_table()
  230. - db_set_table_name()
  231. - db_get_table_name()
  232. - db_set_table_description()
  233. - db_get_table_description()
  234. - db_get_table_number_of_columns()
  235. - db_set_table_select_priv_granted()
  236. - db_set_table_select_priv_not_granted()
  237. - db_get_table_select_priv()
  238. - db_set_table_update_priv_granted()
  239. - db_set_table_update_priv_not_granted()
  240. - db_get_table_update_priv()
  241. - db_set_table_insert_priv_granted()
  242. - db_set_table_insert_priv_not_granted()
  243. - db_get_table_insert_priv()
  244. - db_set_table_delete_priv_granted()
  245. - db_set_table_delete_priv_not_granted()
  246. - db_get_table_delete_priv()
  247. - db_get_table_column()
  248. - db_get_table_column_by_name()
  249. - db_set_table_column()
  250. - db_append_table_column()
  251. - db_clone_table()
  252. - db_table_to_sql()
  253. Token management:
  254. - db_find_token()
  255. - db_drop_token()
  256. - db_new_token()
  257. Value management:
  258. - db_test_value_isnull()
  259. - db_get_value_int()
  260. - db_get_value_double()
  261. - db_get_value_as_double()
  262. - db_get_value_string()
  263. - db_get_value_year()
  264. - db_get_value_month()
  265. - db_get_value_day()
  266. - db_get_value_hour()
  267. - db_get_value_minute()
  268. - db_get_value_seconds()
  269. - db_set_value_null()
  270. - db_set_value_not_null()
  271. - db_set_value_int()
  272. - db_set_value_double()
  273. - db_set_value_string()
  274. - db_set_value_year()
  275. - db_set_value_month()
  276. - db_set_value_day()
  277. - db_set_value_hour()
  278. - db_set_value_minute()
  279. - db_set_value_seconds()
  280. - db_test_value_datetime_current()
  281. - db_set_value_datetime_current()
  282. - db_set_value_datetime_not_current()
  283. - db_copy_value()
  284. - db_CatValArray_init()
  285. - db_CatValArray_free()
  286. - db_CatValArray_alloc()
  287. - db_CatValArray_realloc()
  288. - db_convert_Cstring_to_value()
  289. - db_convert_value_to_string()
  290. Misc:
  291. - db_isdir()
  292. - db_legal_tablename()
  293. - db_whoami
  294. \section dbmiClient DBMI CLIENT functions
  295. - db_add_column()
  296. - db_begin_transaction()
  297. - db_bind_update()
  298. - db_CatValArray_get_value()
  299. - db_CatValArray_get_value_double()
  300. - db_CatValArray_get_value_int()
  301. - db_CatValArray_sort()
  302. - db_CatValArray_sort_by_value()
  303. - db_close_cursor()
  304. - db_close_database()
  305. - db_close_database_shutdown_driver()
  306. - db_column_Ctype()
  307. - db_column_sqltype()
  308. - db_commit_transaction()
  309. - db_copy_table()
  310. - db_copy_table_where()
  311. - db_copy_table_select()
  312. - db_copy_table_by_ints()
  313. - db_create_database()
  314. - db_create_index()
  315. - db_create_table()
  316. - db_delete()
  317. - db_delete_database()
  318. - db_delete_table()
  319. - db_describe_table()
  320. - db_drop_column()
  321. - db_drop_index()
  322. - db_drop_table()
  323. - db_execute_immediate()
  324. - db_fetch()
  325. - db_find_database()
  326. - db_get_column()
  327. - db_get_num_rows()
  328. - db_get_table_number_of_rows()
  329. - db_grant_on_table()
  330. - db_gversion()
  331. - db_insert()
  332. - db_list_databases()
  333. - db_list_drivers()
  334. - db_list_indexes()
  335. - db_list_tables()
  336. - db_open_database()
  337. - db_open_insert_cursor()
  338. - db_open_select_cursor()
  339. - db_open_update_cursor()
  340. - db_print_column_definition()
  341. - db_print_table_definition()
  342. - db_start_driver_open_database()
  343. - db_select_CatValArray()
  344. - db_select_int()
  345. - db_select_value()
  346. - db_shutdown_driver()
  347. - db_start_driver()
  348. - db_table_exists()
  349. - db_update()
  350. \section dbmiDriver DBMI DRIVER functions
  351. - db_driver()
  352. - db_driver_mkdir()
  353. - db_d_add_column()
  354. - db_d_append_error()
  355. - db_d_begin_transaction()
  356. - db_d_bind_update()
  357. - db_d_close_cursor()
  358. - db_d_close_database()
  359. - db_d_commit_transaction()
  360. - db_d_create_database()
  361. - db_d_create_index()
  362. - db_d_create_table()
  363. - db_d_delete()
  364. - db_d_delete_database()
  365. - db_d_describe_table()
  366. - db_d_drop_column()
  367. - db_d_drop_index()
  368. - db_d_drop_table()
  369. - db_d_execute_immediate()
  370. - db_d_fetch()
  371. - db_d_find_database()
  372. - db_d_get_num_rows()
  373. - db_driver_mkdir()
  374. - db_d_grant_on_table()
  375. - db_d_init_error()
  376. - db_d_insert()
  377. - db_d_list_databases()
  378. - db_d_list_indexes()
  379. - db_d_list_tables()
  380. - db_d_open_database()
  381. - db_d_open_insert_cursor()
  382. - db_d_open_select_cursor()
  383. - db_d_open_update_cursor()
  384. - db_d_report_error()
  385. - db_d_update()
  386. \section dbmiReferences References
  387. Text based on: R. Blazek, M. Neteler, and R. Micarelli. The new GRASS 5.1
  388. vector architecture. In Open source GIS - GRASS users conference 2002,
  389. Trento, Italy, 11-13 September 2002. University of Trento, Italy, 2002.
  390. http://www.ing.unitn.it/~grass/proceedings/proceedings/pdfs/Blazek_Radim.pdf
  391. \section dbmiSeeAlso See Also
  392. GRASS Vector Architecture: \ref vectorlib
  393. \section dbmiAuthors Authors
  394. - Joel Jones (CERL/UIUC)
  395. - Radim Blazek
  396. */