1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <stdlib.h>
#include "dbmi.h"
#include "dbstubs.h"
static dbDriverState state;
void
db__init_driver_state()
{
db_zero((void *)&state, sizeof(state));
}
dbDriverState *
db__get_driver_state()
{
return &state;
}
db__test_database_open ()
{
return state.open ? 1 : 0 ;
}
void
db__mark_database_open (dbname, dbschema)
char *dbname;
char *dbschema;
{
state.dbname = dbname;
state.dbschema = dbschema;
state.open = 1;
}
void
db__mark_database_closed ()
{
free(state.dbname);
free(state.dbschema);
state.open = 0;
}
void
db__add_cursor_to_driver_state(cursor)
dbCursor *cursor;
{
dbCursor **list;
int i;
/* find an empty slot in the cursor list */
list = state.cursor_list;
for (i = 0; i < state.ncursors; i++)
if (list[i] == NULL)
break;
/* if not found, extend list */
if (i >= state.ncursors)
{
list = (dbCursor **) db_realloc ((void *)list, (i+1) * sizeof(dbCursor *));
if (list == NULL)
return;
state.cursor_list = list;
state.ncursors = i+1;
}
/* add it in */
list[i] = cursor;
}
void
db__drop_cursor_from_driver_state(cursor)
dbCursor *cursor;
{
int i;
for (i = 0; i < state.ncursors; i++)
if (state.cursor_list[i] == cursor)
state.cursor_list[i] = NULL;
}
void
db__close_all_cursors()
{
int i;
for (i = 0; i < state.ncursors; i++)
if (state.cursor_list[i])
db_driver_close_cursor (state.cursor_list[i]);
if (state.cursor_list)
free (state.cursor_list);
state.ncursors = 0;
state.cursor_list = NULL;
}
|