@@ -17,7 +17,6 @@ static char sql_query_buffer[2000];
17// array used to store the string
17// array used to store the string
18//value obtain by get_val_text
18//value obtain by get_val_text
19unsigned char* array;
19unsigned char* array;
22 open an SQLite database file as
21 open an SQLite database file as
23 specified by the filename argument.
22 specified by the filename argument.
@@ -38,7 +37,6 @@ void* sqlite3_open_idr(const char *filename){
38 return dbi;
37 return dbi;
43 Frees the resource and returns 0 on success
41 Frees the resource and returns 0 on success
@@ -50,12 +48,10 @@ int sqlite3_close_idr(void* db){
50 free(dbi);
48 free(dbi);
55 return res;
52 return res;
60 SQLite wrapper around sqlite3_prepare_v2(),
56 SQLite wrapper around sqlite3_prepare_v2(),
61 sqlite3_step(), and sqlite3_finalize().
57 sqlite3_step(), and sqlite3_finalize().
@@ -64,11 +60,9 @@ int sqlite3_close_idr(void* db){
65int sqlite3_exec_idr(void* db, const char *sql)
61int sqlite3_exec_idr(void* db, const char *sql)
68 DBinfo* dbi =(DBinfo*) db;
63 DBinfo* dbi =(DBinfo*) db;
69 char* err;
64 char* err;
72 rc = sqlite3_exec(dbi->db_ptr,sql,NULL, NULL, &err);
66 rc = sqlite3_exec(dbi->db_ptr,sql,NULL, NULL, &err);
73 if (rc != SQLITE_OK && err != NULL) {
67 if (rc != SQLITE_OK && err != NULL) {
74 strncpy(dbi->buffer, err, sizeof(dbi->buffer));
68 strncpy(dbi->buffer, err, sizeof(dbi->buffer));
@@ -76,7 +70,6 @@ int sqlite3_exec_idr(void* db, const char *sql)
77 return rc;
71 return rc;
81 Gets the error store in the buffer
74 Gets the error store in the buffer
82 in the struct. Some certain functions
75 in the struct. Some certain functions
@@ -86,15 +79,12 @@ char* sqlite3_get_error(void* db) {
86 DBinfo* dbi =(DBinfo*) db;
79 DBinfo* dbi =(DBinfo*) db;
87 return dbi->buffer;
80 return dbi->buffer;
92 Compiles the query into a byte-code program
83 Compiles the query into a byte-code program
93 Returns a pointer to the sqlite3_stmt pointer
84 Returns a pointer to the sqlite3_stmt pointer
94 and stores it in the struct.
85 and stores it in the struct.
96void* sqlite3_prepare_idr(void *db,const char *zSql){
87void* sqlite3_prepare_idr(void *db,const char *zSql){
98 sqlite3_stmt* stmt;
88 sqlite3_stmt* stmt;
99 const char *tail;
89 const char *tail;
@@ -107,10 +97,8 @@ void* sqlite3_prepare_idr(void *db,const char *zSql){
107 if(rec != SQLITE_OK){
97 if(rec != SQLITE_OK){
108 return NULL;
98 return NULL;
111 return dbi;
100 return dbi;
115 Another wrapper interface that is preserved
103 Another wrapper interface that is preserved
116 for backwards compatibility.
104 for backwards compatibility.
@@ -118,7 +106,6 @@ void* sqlite3_prepare_idr(void *db,const char *zSql){
118 This was mainly used for testing within the
106 This was mainly used for testing within the
122void* sqlite3_get_table_idr(void* db,
109void* sqlite3_get_table_idr(void* db,
123 const char *sql){
110 const char *sql){
@@ -127,9 +114,7 @@ void* sqlite3_get_table_idr(void* db,
128 Table* tbl = malloc(sizeof(Table));
115 Table* tbl = malloc(sizeof(Table));
129 tbl->database = dbi;
116 tbl->database = dbi;
131 int res = sqlite3_get_table(dbi->db_ptr,sql,&tbl->table_data,&tbl->num_row,&tbl->num_col,&err);
117 int res = sqlite3_get_table(dbi->db_ptr,sql,&tbl->table_data,&tbl->num_row,&tbl->num_col,&err);
133 int array_size = sizeof(&tbl->table_data);
118 int array_size = sizeof(&tbl->table_data);
135 if( res != SQLITE_OK && err != NULL){
120 if( res != SQLITE_OK && err != NULL){
@@ -137,16 +122,11 @@ void* sqlite3_get_table_idr(void* db,
137 sqlite3_free(err);
122 sqlite3_free(err);
138 return NULL;
123 return NULL;
141 tbl -> data_size = array_size;
125 tbl -> data_size = array_size;
142− return tbl;
126+ return tbl;
150 This function executes queries.
130 This function executes queries.
151 This can be used after preparing a query
131 This can be used after preparing a query
152 In case of error or library misuse
132 In case of error or library misuse
@@ -171,7 +151,6 @@ int exec_db(void*p){
171 if(rc == SQLITE_ERROR && rc == SQLITE_MISUSE){
151 if(rc == SQLITE_ERROR && rc == SQLITE_MISUSE){
172 return 1;
152 return 1;
175 row_counter =0;
154 row_counter =0;
177 while (rc == SQLITE_ROW) {
156 while (rc == SQLITE_ROW) {
@@ -184,7 +163,6 @@ int exec_db(void*p){
184 dbi->row_count = row_counter;
163 dbi->row_count = row_counter;
185 dbi->col_count = col;
164 dbi->col_count = col;
186 return rc;
165 return rc;
190 Returns row number from DB Struct
168 Returns row number from DB Struct
@@ -195,12 +173,9 @@ int sqlite3_get_num_row_v2(void* p){
195 DBinfo* dbi =(DBinfo*) p;
173 DBinfo* dbi =(DBinfo*) p;
196 int row_number =dbi->row_count;
174 int row_number =dbi->row_count;
197 return row_number;
175 return row_number;
204 Returns column number from DB Struct
179 Returns column number from DB Struct
206int sqlite3_get_num_col_v2(void* p){
181int sqlite3_get_num_col_v2(void* p){
@@ -208,11 +183,9 @@ int sqlite3_get_num_col_v2(void* p){
208 DBinfo* dbi =(DBinfo*) p;
183 DBinfo* dbi =(DBinfo*) p;
209 int col_number =dbi-> col_count;
184 int col_number =dbi-> col_count;
210 return col_number;
185 return col_number;
216 Another way of obtaining row number
189 Another way of obtaining row number
217 Thought this function gets the value
190 Thought this function gets the value
218 from Table struct. The value is stored
191 from Table struct. The value is stored
@@ -225,12 +198,9 @@ int sqlite3_get_num_row(void* p){
225 Table* tbl =(Table*) p;
198 Table* tbl =(Table*) p;
226 int row_number =tbl->num_row;
199 int row_number =tbl->num_row;
227 return row_number;
200 return row_number;
234 Another way of obtaining column number
204 Another way of obtaining column number
235 Thought this function gets the value
205 Thought this function gets the value
236 from Table struct. The value is stored
206 from Table struct. The value is stored
@@ -238,13 +208,11 @@ int sqlite3_get_num_row(void* p){
238 Using this version is not recommended
208 Using this version is not recommended
239 unless used with get_table
209 unless used with get_table
242int sqlite3_get_num_col(void* p){
211int sqlite3_get_num_col(void* p){
244 Table* tbl =(Table*) p;
213 Table* tbl =(Table*) p;
245 int col_number =tbl-> num_col;
214 int col_number =tbl-> num_col;
246− return col_number;
215+ return col_number;
@@ -255,7 +223,6 @@ int sqlite3_get_num_col(void* p){
255 set the pointer to its initial state
223 set the pointer to its initial state
256 and then calls sqlite3_column_type
224 and then calls sqlite3_column_type
257 to get the type
225 to get the type
260int sqlite3_get_data_type(void* p, int nRow, int nCol){
227int sqlite3_get_data_type(void* p, int nRow, int nCol){
@@ -277,24 +244,18 @@ int sqlite3_get_data_type(void* p, int nRow, int nCol){
281 Obtains the integer value in a given column
247 Obtains the integer value in a given column
284int sqlite3_get_val_int(void* p, int nCol){
250int sqlite3_get_val_int(void* p, int nCol){
287 DBinfo* dbi =(DBinfo*) p;
252 DBinfo* dbi =(DBinfo*) p;
288 int val, col;
253 int val, col;
290 val =sqlite3_column_int(dbi->ppStmt, nCol);
254 val =sqlite3_column_int(dbi->ppStmt, nCol);
291 return val;
255 return val;
298 Obtains the text value
259 Obtains the text value
299 Need to allocate memory to store the string
260 Need to allocate memory to store the string
300 Use GC_malloc since Boehm garbage collector
261 Use GC_malloc since Boehm garbage collector
@@ -306,16 +267,12 @@ const unsigned char* sqlite3_get_val_text(void* p,int nCol){
306 DBinfo* dbi =(DBinfo*) p;
267 DBinfo* dbi =(DBinfo*) p;
307 int rc,i, val, counter;
268 int rc,i, val, counter;
308 const unsigned char* text_val;
269 const unsigned char* text_val;
310 array =(unsigned char *) GC_malloc(1000*sizeof(char));
270 array =(unsigned char *) GC_malloc(1000*sizeof(char));
312 text_val =sqlite3_column_text(dbi->ppStmt, nCol);
271 text_val =sqlite3_column_text(dbi->ppStmt, nCol);
313 memcpy(array, text_val, strlen(text_val));
272 memcpy(array, text_val, strlen(text_val));
315 return array;
273 return array;
319float sqlite3_get_float(void* p, int nCol){
276float sqlite3_get_float(void* p, int nCol){
321 DBinfo* dbi =(DBinfo*) p;
278 DBinfo* dbi =(DBinfo*) p;
@@ -326,7 +283,6 @@ float sqlite3_get_float(void* p, int nCol){
326 return float_val;
283 return float_val;
331 frees the pointer returned by get_table.
287 frees the pointer returned by get_table.
@@ -336,16 +292,12 @@ void sqlite3_free_table_idr(void* db){
336 sqlite3_free_table(tbl->table_data);
292 sqlite3_free_table(tbl->table_data);
337 free(tbl);
293 free(tbl);
341int sqlite3_step_idr(void* db){
295int sqlite3_step_idr(void* db){
343 DBinfo* dbi =(DBinfo*) db;
297 DBinfo* dbi =(DBinfo*) db;
344 int rc =sqlite3_step(dbi->ppStmt);
298 int rc =sqlite3_step(dbi->ppStmt);
345 return rc;
299 return rc;
350 Binds integer. This returns a pointer
302 Binds integer. This returns a pointer
351 because of the implementation of BindMulti
303 because of the implementation of BindMulti
@@ -375,7 +327,6 @@ void* sqlite3_bind_float_idr(void* p,int index, float val){
375 if(rc != SQLITE_OK){
327 if(rc != SQLITE_OK){
376 return NULL;
328 return NULL;
379 return dbi;
330 return dbi;
@@ -401,10 +352,7 @@ void* sqlite3_bind_text_idr(void* p,const char* text, int index,int length){
403 return dbi;
354 return dbi;
409 Used for testing column count function.
357 Used for testing column count function.
410 This function prepares query and by passing
358 This function prepares query and by passing
@@ -440,17 +388,13 @@ int sqlite3_column_count_idr(void* db, const char* tbl_name){
440 return rc;
388 return rc;
444int sqlite3_data_count_idr(void* db){
391int sqlite3_data_count_idr(void* db){
446 DBinfo* dbi =(DBinfo*) db;
393 DBinfo* dbi =(DBinfo*) db;
447 int rc = sqlite3_data_count(dbi->ppStmt);
394 int rc = sqlite3_data_count(dbi->ppStmt);
449 return rc;
396 return rc;
455 Must be called after prepare to clean up
399 Must be called after prepare to clean up
456 the resources.
400 the resources.
@@ -466,8 +410,6 @@ int sqlite3_complete_idr(const char *sql){
467 int rc = sqlite3_complete(sql);
411 int rc = sqlite3_complete(sql);
468 return rc;
412 return rc;
@@ -481,12 +423,10 @@ int sqlite3_reset_idr(void* db){
481 return rc;
423 return rc;
486 The following routines may be used to
427 The following routines may be used to
487 obtain column related information.
428 obtain column related information.
490const char *sqlite3_column_name_idr(void* db, int N){
430const char *sqlite3_column_name_idr(void* db, int N){
492 DBinfo* dbi=(DBinfo*) db;
432 DBinfo* dbi=(DBinfo*) db;
@@ -502,8 +442,6 @@ const char *sqlite3_column_decltype_idr(void* db,int n){
502 return dectype;
442 return dectype;
507int sqlite3_column_bytes_idr(void* db, int n){
445int sqlite3_column_bytes_idr(void* db, int n){
509 DBinfo* dbi=(DBinfo*) db;
447 DBinfo* dbi=(DBinfo*) db;
@@ -512,7 +450,6 @@ int sqlite3_column_bytes_idr(void* db, int n){
516const void *sqlite3_column_blob_idr(void* db, int iCol){
453const void *sqlite3_column_blob_idr(void* db, int iCol){
517 DBinfo* dbi=(DBinfo*) db;
454 DBinfo* dbi=(DBinfo*) db;
518 const void* data =sqlite3_column_blob(dbi-> ppStmt, iCol);
455 const void* data =sqlite3_column_blob(dbi-> ppStmt, iCol);
@@ -590,7 +527,6 @@ int sqlite3_backup_pagecount_idr(void *backup){
590 return res;
527 return res;
595 Get the length of string
531 Get the length of string
596 Need this in Idris since length will not
532 Need this in Idris since length will not