1/*! \page dbmilib GRASS DataBase Management Interface
2
3by GRASS Development Team
4
5https://grass.osgeo.org
6
7\section dbmiIntro Introduction
8
9The attribute management was completely changed in GRASS 6 to achieve
10multi-attribute capabilities managed within external databases. The
11former <tt>dig_cats/</tt> files (GRASS 5) are not used any more and
12all vector attributes are stored in external database. Connection with
13database is done through <b>DBMI library</b> (DataBase Management
14Interface) with its integrated drivers. At time of this writing
15following DBMI drivers for attribute storage are available:
16
17 - DBF: xBase files (default)
18 - ODBC: to interface from http://www.unixodbc.org
19 - PostgreSQL driver (note that PostgreSQL can also be accessed through ODBC): http://www.postgresql.org
20 - mySQL: http://mysql.com/
21 - SQLite: http://www.sqlite.org
22
23These drivers are compiled depending on present DB related libraries
24and 'configure' settings. Only the DBF driver is always compiled. The
25default DBMI driver is defined in dbmi.h
26
27\code
28#define DB_DEFAULT_DRIVER "sqlite"
29\endcode
30
31In general records in table are linked to vector entities by field number
32and category number.  The field number identifies a database table and the
33category number identifies the record record. I.e. for unique combination
34<tt>mapset + map + field + category</tt> exists one unique combination
35<tt>driver + database + table + row</tt>. Each element may have none, one or
36more categories (cats). More cats are distinguished by field number (field).
37The flexibility of this approach even supports the extreme case, that one
38vector entity may be linked to attributes in different tables in different
39databases connected by different drivers at the same time.
40
41The DBMI library contains drivers such as DBF, SQLite, ODBC, MySQL and
42PostgreSQL.  The functionality of the database support varies with the
43capabilities of the underlying RDBMS. Main features are
44multi-attributes support for various data types, also multiple tables
45may optionally be linked to one or many vector entity/ies. SQL
46(Structured Query Language) is used for all drivers, but in a limited
47implementation.
48
49For DBMI architecture details please read Blazek et al. 2002 (see below).
50
51\section dbmiFunc DBMI library functions
52
53The <tt>db_*()</tt> functions are the programmer's API for GRASS DBMI
54programming. There are three groups:
55
56 - <b>dbmi_base</b>:   contains functions for modules, drivers (<tt>../../db/drivers/</tt>)
57 - <b>dbmi_client</b>: contains functions for modules
58 - <b>dbmi_driver</b>: contains functions for drivers (<tt>../../db/drivers/</tt>)
59
60\section dbmiBase DBMI BASE functions
61
62Allocation:
63
64 - db_store()
65
66 - db_malloc()
67
68 - db_calloc()
69
70 - db_realloc()
71
72 - db_free()
73
74String manipulation:
75
76 - db_char_to_lowercase()
77
78 - db_char_to_uppercase()
79
80 - db_Cstring_to_lowercase()
81
82 - db_Cstring_to_uppercase()
83
84 - db_nocase_compare()
85
86Column properties:
87
88 - db_get_column_value()
89
90 - db_get_column_default_value()
91
92 - db_set_column_sqltype()
93
94 - db_set_column_host_type()
95
96 - db_get_column_scale()
97
98 - db_set_column_scale()
99
100 - db_get_column_precision()
101
102 - db_set_column_precision()
103
104 - db_get_column_sqltype()
105
106 - db_get_column_host_type()
107
108 - db_set_column_has_defined_default_value()
109
110 - db_set_column_has_undefined_default_value()
111
112 - db_unset_column_has_default_value()
113
114 - db_test_column_has_default_value()
115
116 - db_test_column_has_defined_default_value()
117
118 - db_test_column_has_undefined_default_value()
119
120 - db_set_column_use_default_value()
121
122 - db_unset_column_use_default_value()
123
124 - db_test_column_use_default_value()
125
126 - db_set_column_null_allowed()
127
128 - db_unset_column_null_allowed()
129
130 - db_test_column_null_allowed()
131
132 - db_get_column_length()
133
134 - db_set_column_length()
135
136 - db_set_column_select_priv_granted()
137
138 - db_set_column_select_priv_not_granted()
139
140 - db_get_column_select_priv()
141
142 - db_set_column_update_priv_granted()
143
144 - db_set_column_update_priv_not_granted()
145
146 - db_get_column_update_priv()
147
148 - db_init_column()
149
150 - db_set_column_name()
151
152 - db_get_column_name()
153
154 - db_set_column_description()
155
156 - db_get_column_description()
157
158 - db_free_column()
159
160 - db_copy_column()
161
162 - db_convert_Cstring_to_column_value()
163
164 - db_convert_Cstring_to_column_default_value()
165
166 - db_convert_column_value_to_string()
167
168 - db_convert_column_default_value_to_string()
169
170Connection settings:
171
172 - db_set_connection()
173
174 - db_get_connection()
175
176Cursor management:
177
178 - db_init_cursor()
179
180 - db_alloc_cursor_table()
181
182 - db_free_cursor()
183
184 - db_get_cursor_table()
185
186 - db_set_cursor_table()
187
188 - db_get_cursor_token()
189
190 - db_set_cursor_token()
191
192 - db_set_cursor_type_readonly()
193
194 - db_set_cursor_type_update()
195
196 - db_set_cursor_type_insert()
197
198 - db_test_cursor_type_fetch()
199
200 - db_test_cursor_type_update()
201
202 - db_test_cursor_type_insert()
203
204 - db_set_cursor_mode()
205
206 - db_set_cursor_mode_scroll()
207
208 - db_unset_cursor_mode_scroll()
209
210 - db_unset_cursor_mode()
211
212 - db_set_cursor_mode_insensitive()
213
214 - db_unset_cursor_mode_insensitive()
215
216 - db_test_cursor_mode_scroll()
217
218 - db_test_cursor_mode_insensitive()
219
220 - db_alloc_cursor_column_flags()
221
222 - db_free_cursor_column_flags()
223
224 - db_set_cursor_column_for_update()
225
226 - db_unset_cursor_column_for_update()
227
228 - db_test_cursor_column_for_update()
229
230 - db_test_cursor_any_column_for_update()
231
232 - db_set_cursor_column_flag()
233
234 - db_unset_cursor_column_flag()
235
236 - db_test_cursor_column_flag()
237
238 - db_get_cursor_number_of_columns()
239
240 - db_test_cursor_any_column_flag()
241
242DateTime conversion:
243
244 - db_convert_value_datetime_into_string()
245
246 - db_convert_Cstring_to_value_datetime()
247
248DBmscap management:
249
250 - db_dbmscap_filename()
251
252 - db_has_dbms()
253
254 - db_copy_dbmscap_entry()
255
256 - db_read_dbmscap()
257
258 - db_free_dbmscap()
259
260Default settings:
261
262 - db_get_default_driver_name()
263
264 - db_get_default_database_name()
265
266 - db_get_default_schema_name()
267
268 - db_get_default_group_name()
269
270 - db_set_default_connection()
271
272Dirent (directory entities) array:
273
274 - db_dirent()
275
276 - db_free_dirent_array()
277
278 - db_alloc_dirent_array()
279
280Report errors:
281
282 - db_on_error()
283
284 - db_set_error_who()
285
286 - db_get_error_who()
287
288 - db_error()
289
290 - db_protocol_error()
291
292 - db_syserror()
293
294 - db_get_error_code()
295
296 - db_memory_error()
297
298 - db_procedure_not_implemented()
299
300 - db_noproc_error()
301
302 - db_clear_error()
303
304 - db_print_error()
305
306 - db_debug_on()
307
308 - db_debug_off()
309
310 - db_debug()
311
312 - db_get_error_msg()
313
314 - db_auto_print_errors()
315
316 - db_auto_print_protocol_errors()
317
318Handle management:
319
320 - db_init_handle()
321
322 - db_set_handle()
323
324 - db_get_handle_dbname()
325
326 - db_get_handle_dbschema()
327
328 - db_free_handle()
329
330 - db_free_handle_array()
331
332 - db_alloc_handle_array()
333
334Index management:
335
336 - db_init_index()
337
338 - db_free_index()
339
340 - db_alloc_index_columns()
341
342 - db_alloc_index_array()
343
344 - db_free_index_array()
345
346 - db_set_index_name()
347
348 - db_get_index_name()
349
350 - db_set_index_table_name()
351
352 - db_get_index_table_name()
353
354 - db_get_index_number_of_columns()
355
356 - db_set_index_column_name()
357
358 - db_get_index_column_name()
359
360 - db_set_index_type_unique()
361
362 - db_set_index_type_non_unique()
363
364 - db_test_index_type_unique()
365
366 - db_print_index()
367
368Range functions:
369
370 - db_interval_range()
371
372Login functions:
373
374 - db_set_login()
375
376 - db_get_login()
377
378Return codes (internal use only):
379
380 - db__send_success()
381
382 - db__send_failure()
383
384 - db__recv_return_code()
385
386Data type conversion:
387
388 - db_sqltype_to_Ctype()
389
390 - db_sqltype_name()
391
392String manipulation:
393
394 - db_init_string()
395
396 - db_set_string()
397
398 - db_set_string_no_copy()
399
400 - db_sizeof_string()
401
402 - db_zero_string()
403
404 - db_enlarge_string()
405
406 - db_get_string()
407
408 - db_free_string()
409
410 - db_free_string_array()
411
412 - db_alloc_string_array()
413
414 - db_append_string()
415
416 - db_copy_string()
417
418 - db_double_quote_string()
419
420Table/privileges management:
421
422 - db_alloc_table()
423
424 - db_init_table()
425
426 - db_free_table()
427
428 - db_set_table_name()
429
430 - db_get_table_name()
431
432 - db_set_table_description()
433
434 - db_get_table_description()
435
436 - db_get_table_number_of_columns()
437
438 - db_set_table_select_priv_granted()
439
440 - db_set_table_select_priv_not_granted()
441
442 - db_get_table_select_priv()
443
444 - db_set_table_update_priv_granted()
445
446 - db_set_table_update_priv_not_granted()
447
448 - db_get_table_update_priv()
449
450 - db_set_table_insert_priv_granted()
451
452 - db_set_table_insert_priv_not_granted()
453
454 - db_get_table_insert_priv()
455
456 - db_set_table_delete_priv_granted()
457
458 - db_set_table_delete_priv_not_granted()
459
460 - db_get_table_delete_priv()
461
462 - db_get_table_column()
463
464 - db_get_table_column_by_name()
465
466 - db_set_table_column()
467
468 - db_append_table_column()
469
470 - db_clone_table()
471
472 - db_table_to_sql()
473
474Token management:
475
476 - db_find_token()
477
478 - db_drop_token()
479
480 - db_new_token()
481
482Value management:
483
484 - db_test_value_isnull()
485
486 - db_get_value_int()
487
488 - db_get_value_double()
489
490 - db_get_value_as_double()
491
492 - db_get_value_string()
493
494 - db_get_value_year()
495
496 - db_get_value_month()
497
498 - db_get_value_day()
499
500 - db_get_value_hour()
501
502 - db_get_value_minute()
503
504 - db_get_value_seconds()
505
506 - db_set_value_null()
507
508 - db_set_value_not_null()
509
510 - db_set_value_int()
511
512 - db_set_value_double()
513
514 - db_set_value_string()
515
516 - db_set_value_year()
517
518 - db_set_value_month()
519
520 - db_set_value_day()
521
522 - db_set_value_hour()
523
524 - db_set_value_minute()
525
526 - db_set_value_seconds()
527
528 - db_test_value_datetime_current()
529
530 - db_set_value_datetime_current()
531
532 - db_set_value_datetime_not_current()
533
534 - db_copy_value()
535
536 - db_CatValArray_init()
537
538 - db_CatValArray_free()
539
540 - db_CatValArray_alloc()
541
542 - db_CatValArray_realloc()
543
544 - db_convert_Cstring_to_value()
545
546 - db_convert_value_to_string()
547
548Misc:
549
550 - db_isdir()
551
552 - db_legal_tablename()
553
554 - db_whoami
555
556\section dbmiClient DBMI CLIENT functions
557
558 - db_add_column()
559
560 - db_begin_transaction()
561
562 - db_bind_update()
563
564 - db_CatValArray_get_value()
565
566 - db_CatValArray_get_value_double()
567
568 - db_CatValArray_get_value_int()
569
570 - db_CatValArray_sort()
571
572 - db_CatValArray_sort_by_value()
573
574 - db_close_cursor()
575
576 - db_close_database()
577
578 - db_close_database_shutdown_driver()
579
580 - db_column_Ctype()
581
582 - db_column_sqltype()
583
584 - db_commit_transaction()
585
586 - db_copy_table()
587
588 - db_copy_table_where()
589
590 - db_copy_table_select()
591
592 - db_copy_table_by_ints()
593
594 - db_create_database()
595
596 - db_create_index()
597
598 - db_create_table()
599
600 - db_delete()
601
602 - db_delete_database()
603
604 - db_delete_table()
605
606 - db_describe_table()
607
608 - db_drop_column()
609
610 - db_drop_index()
611
612 - db_drop_table()
613
614 - db_execute_immediate()
615
616 - db_fetch()
617
618 - db_find_database()
619
620 - db_get_column()
621
622 - db_get_num_rows()
623
624 - db_get_table_number_of_rows()
625
626 - db_grant_on_table()
627
628 - db_gversion()
629
630 - db_insert()
631
632 - db_list_databases()
633
634 - db_list_drivers()
635
636 - db_list_indexes()
637
638 - db_list_tables()
639
640 - db_open_database()
641
642 - db_open_insert_cursor()
643
644 - db_open_select_cursor()
645
646 - db_open_update_cursor()
647
648 - db_print_column_definition()
649
650 - db_print_table_definition()
651
652 - db_start_driver_open_database()
653
654 - db_select_CatValArray()
655
656 - db_select_int()
657
658 - db_select_value()
659
660 - db_shutdown_driver()
661
662 - db_start_driver()
663
664 - db_table_exists()
665
666 - db_update()
667
668
669\section dbmiDriver DBMI DRIVER functions
670
671 - db_driver()
672
673 - db_driver_mkdir()
674
675 - db_d_add_column()
676
677 - db_d_append_error()
678
679 - db_d_begin_transaction()
680
681 - db_d_bind_update()
682
683 - db_d_close_cursor()
684
685 - db_d_close_database()
686
687 - db_d_commit_transaction()
688
689 - db_d_create_database()
690
691 - db_d_create_index()
692
693 - db_d_create_table()
694
695 - db_d_delete()
696
697 - db_d_delete_database()
698
699 - db_d_describe_table()
700
701 - db_d_drop_column()
702
703 - db_d_drop_index()
704
705 - db_d_drop_table()
706
707 - db_d_execute_immediate()
708
709 - db_d_fetch()
710
711 - db_d_find_database()
712
713 - db_d_get_num_rows()
714
715 - db_driver_mkdir()
716
717 - db_d_grant_on_table()
718
719 - db_d_init_error()
720
721 - db_d_insert()
722
723 - db_d_list_databases()
724
725 - db_d_list_indexes()
726
727 - db_d_list_tables()
728
729 - db_d_open_database()
730
731 - db_d_open_insert_cursor()
732
733 - db_d_open_select_cursor()
734
735 - db_d_open_update_cursor()
736
737 - db_d_report_error()
738
739 - db_d_update()
740
741\section dbmiReferences References
742
743Text based on: R. Blazek, M. Neteler, and R. Micarelli. The new GRASS 5.1
744 vector architecture. In Open source GIS - GRASS users conference 2002,
745 Trento, Italy, 11-13 September 2002. University of Trento, Italy, 2002.
746 http://www.ing.unitn.it/~grass/proceedings/proceedings/pdfs/Blazek_Radim.pdf
747
748\section dbmiSeeAlso See Also
749
750GRASS Vector Architecture: \ref vectorlib
751
752\section dbmiAuthors Authors
753
754 - Joel Jones (CERL/UIUC)
755 - Radim Blazek
756*/
757