GRASS Programmer's Manual 6.4.1(2011)
|
00001 00015 #include <stdlib.h> 00016 #include <grass/dbmi.h> 00017 #include "dbstubs.h" 00018 00019 00020 static dbDriverState state; 00021 00025 void db__init_driver_state(void) 00026 { 00027 db_zero((void *)&state, sizeof(state)); 00028 } 00029 00035 dbDriverState *db__get_driver_state(void) 00036 { 00037 return &state; 00038 } 00039 00046 int db__test_database_open(void) 00047 { 00048 return state.open ? 1 : 0; 00049 } 00050 00057 void db__mark_database_open(const char *dbname, const char *dbschema) 00058 { 00059 state.dbname = db_store(dbname); 00060 state.dbschema = db_store(dbschema); 00061 state.open = 1; 00062 } 00063 00067 void db__mark_database_closed(void) 00068 { 00069 db_free(state.dbname); 00070 db_free(state.dbschema); 00071 state.open = 0; 00072 } 00073 00079 void db__add_cursor_to_driver_state(dbCursor * cursor) 00080 { 00081 dbCursor **list; 00082 int i; 00083 00084 /* find an empty slot in the cursor list */ 00085 list = state.cursor_list; 00086 for (i = 0; i < state.ncursors; i++) 00087 if (list[i] == NULL) 00088 break; 00089 00090 /* if not found, extend list */ 00091 if (i >= state.ncursors) { 00092 list = 00093 (dbCursor **) db_realloc((void *)list, 00094 (i + 1) * sizeof(dbCursor *)); 00095 if (list == NULL) 00096 return; 00097 state.cursor_list = list; 00098 state.ncursors = i + 1; 00099 } 00100 00101 /* add it in */ 00102 list[i] = cursor; 00103 } 00104 00110 void db__drop_cursor_from_driver_state(dbCursor * cursor) 00111 { 00112 int i; 00113 00114 for (i = 0; i < state.ncursors; i++) 00115 if (state.cursor_list[i] == cursor) 00116 state.cursor_list[i] = NULL; 00117 } 00118 00122 void db__close_all_cursors(void) 00123 { 00124 int i; 00125 00126 for (i = 0; i < state.ncursors; i++) 00127 if (state.cursor_list[i]) 00128 db_driver_close_cursor(state.cursor_list[i]); 00129 00130 if (state.cursor_list) 00131 db_free(state.cursor_list); 00132 00133 state.ncursors = 0; 00134 state.cursor_list = NULL; 00135 }