on master help sign in
using gc.h
7708af2melissam
contribs/lib/SQLite3/sqlite3.idr+8−7
@@ -211,6 +211,7 @@ toList name stmt x = do
211 res <- forM [0..(nbR-1)] (\ i =>
211 res <- forM [0..(nbR-1)] (\ i =>
212 forM [0..(nmC-1)] (\ j =>
212 forM [0..(nmC-1)] (\ j =>
213 liftIO(get_data x name i j)
213 liftIO(get_data x name i j)
214+
214 )
215 )
215 )
216 )
216 liftIO (free_table ptr)
217 liftIO (free_table ptr)
@@ -248,9 +249,9 @@ bind_null (MkStmtPtr pointer) indexval =do
248
249
249
250
250instance Show DBVal where
251instance Show DBVal where
251− show (DBInt i) = "Int val: " ++ show i
252+ show (DBInt i) = "Int val: " ++ show i ++ "\n"
252− show (DBText i) = "Text val: " ++ show i
253+ show (DBText i) = "Text val: " ++ show i ++ "\n"
253− show (DBFloat i) = "Float val: " ++ show i
254+ show (DBFloat i) = "Float val: " ++ show i ++ "\n"
254 show (DBNull ) = "NULL"
255 show (DBNull ) = "NULL"
255
256
256print_data_v2 : DBVal -> String
257print_data_v2 : DBVal -> String
@@ -269,10 +270,10 @@ test = do db <- liftIO (open_db "somedb.db")
269
270
270test2 : DB ()
271test2 : DB ()
271test2 = do db <- liftIO (open_db "students.db")
272test2 = do db <- liftIO (open_db "students.db")
272− -- tbl <- (get_table db "SELECT Student.Name FROM Student, Module, Enrollment WHERE Module.Credits = 30 AND Student.School_student = Enrollment.School_Student AND Student.School = Enrollment.School AND Enrollment.Code = Module.Code")
273+ tbl <- (get_table db "SELECT Student.Name FROM Student, Module, Enrollment WHERE Module.Credits = 30 AND Student.School_student = Enrollment.School_Student AND Student.School = Enrollment.School AND Enrollment.Code = Module.Code")
273− --res <- (toList "Student" "select *from Student;" db)
274+ res <- (toList "Student" "select *from Student;" db)
274− mydata <- liftIO ( get_data db "Student" 1 1)
275+ --mydata <- liftIO ( get_data db "Student" 1 1)
275− liftIO(print mydata)
276+ liftIO(print res)
276 c <- liftIO (close_db db)
277 c <- liftIO (close_db db)
277 return ()
278 return ()
278
279
contribs/lib/SQLite3/sqlite3api.c+13−12
@@ -116,13 +116,13 @@ void* sqlite3_get_table_idr(void* db,
116 row = tbl->num_row;
116 row = tbl->num_row;
117 col = tbl->num_col;
117 col = tbl->num_col;
118
118
119− for( i=0; i< row; i++){
119+// for( i=0; i< row; i++){
120− for(j=0;j<col; j++){
120+// for(j=0;j<col; j++){
121− printf("%s\n", tbl->table_data[(i+1)*col +j]);
121+// printf("%s\n", tbl->table_data[(i+1)*col +j]);
122−
122+//
123− }
123+// }
124−
124+//
125− }
125+// }
126 return tbl;
126 return tbl;
127
127
128}
128}
@@ -171,7 +171,7 @@ int sqlite3_get_data_type(void* p,const char* tbl_name, int nRow, int nCol){
171 }
171 }
172
172
173 val =sqlite3_column_type(stmt, nCol);
173 val =sqlite3_column_type(stmt, nCol);
174− printf("Type : %d\n", val );
174+ //printf("Type : %d\n", val );
175
175
176 rc =sqlite3_finalize(stmt);
176 rc =sqlite3_finalize(stmt);
177 if( rc != SQLITE_OK){
177 if( rc != SQLITE_OK){
@@ -210,7 +210,6 @@ int sqlite3_get_val_int(void* p,const char* tbl_name, int nRow, int nCol){
210 }
210 }
211
211
212 val =sqlite3_column_int(stmt, nCol);
212 val =sqlite3_column_int(stmt, nCol);
213− printf("int_val : %d\n", val );
214 rc =sqlite3_finalize(stmt);
213 rc =sqlite3_finalize(stmt);
215 if( rc != SQLITE_OK){
214 if( rc != SQLITE_OK){
216 printf("Couldnt finalize:\n");
215 printf("Couldnt finalize:\n");
@@ -248,10 +247,11 @@ const unsigned char* sqlite3_get_val_text(void* p,const char* tbl_name,int nRow,
248
247
249 }
248 }
250
249
250+ for ( i=0; i< 100000000; i++){
251− array =(unsigned char *) malloc(1000*sizeof(char));
251+ array =(unsigned char *) GC_malloc(1000*sizeof(char));
252+ }
252 text_val =sqlite3_column_text(stmt, nCol);
253 text_val =sqlite3_column_text(stmt, nCol);
253 memcpy(array, text_val, sizeof(text_val));
254 memcpy(array, text_val, sizeof(text_val));
254− printf("text_val : %s\n", text_val );
255 rc =sqlite3_finalize(stmt);
255 rc =sqlite3_finalize(stmt);
256 if( rc != SQLITE_OK){
256 if( rc != SQLITE_OK){
257 printf("Couldn't finalize.\n");
257 printf("Couldn't finalize.\n");
@@ -261,6 +261,7 @@ const unsigned char* sqlite3_get_val_text(void* p,const char* tbl_name,int nRow,
261
261
262}
262}
263
263
264+
264float sqlite3_get_float(void* p,const char* tbl_name, int nRow, int nCol){
265float sqlite3_get_float(void* p,const char* tbl_name, int nRow, int nCol){
265
266
266 DBinfo* dbi =(DBinfo*) p;
267 DBinfo* dbi =(DBinfo*) p;
@@ -290,7 +291,7 @@ float sqlite3_get_float(void* p,const char* tbl_name, int nRow, int nCol){
290 }
291 }
291 double_val =sqlite3_column_double(stmt, nCol);
292 double_val =sqlite3_column_double(stmt, nCol);
292 float float_val =(float)double_val;
293 float float_val =(float)double_val;
293− printf("float_val %f\n", float_val);
294+ //printf("float_val %f\n", float_val);
294 rc =sqlite3_finalize(stmt);
295 rc =sqlite3_finalize(stmt);
295 if( rc != SQLITE_OK){
296 if( rc != SQLITE_OK){
296 printf("Couldn't finalize.\n");
297 printf("Couldn't finalize.\n");