on master help sign in
printing data, doesnt quite work on idris
6349317melissam
contribs/lib/SQLite3/sqlite3.idr+6−7
@@ -249,12 +249,12 @@ bind_null (MkStmtPtr pointer) indexval =do
249
249
250instance Show DBVal where
250instance Show DBVal where
251 show (DBInt i) = "Int val: " ++ show i
251 show (DBInt i) = "Int val: " ++ show i
252− show (DBText i) = "Text val: " ++ i
252+ show (DBText i) = "Text val: " ++ show i
253 show (DBFloat i) = "Float val: " ++ show i
253 show (DBFloat i) = "Float val: " ++ show i
254 show (DBNull ) = "NULL"
254 show (DBNull ) = "NULL"
255
255
256print_data_v2 : DBVal -> String
256print_data_v2 : DBVal -> String
257−print_data_v2 val = (show val)
257+print_data_v2 = show
258
258
259test : DB()
259test : DB()
260test = do db <- liftIO (open_db "somedb.db")
260test = do db <- liftIO (open_db "somedb.db")
@@ -268,12 +268,11 @@ test = do db <- liftIO (open_db "somedb.db")
268 return ()
268 return ()
269
269
270test2 : DB ()
270test2 : DB ()
271−test2 = do db <- liftIO (open_db "somedb.db")
271+test2 = do db <- liftIO (open_db "students.db")
272−
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")
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")
274 --res <- (toList "Student" "select *from Student;" db)
273 --res <- (toList "Student" "select *from Student;" db)
275− -- mydata <- liftIO ( get_data db "Student" 1 1)
274+ mydata <- liftIO ( get_data db "Student" 1 1)
276−
275+ liftIO(print mydata)
277 c <- liftIO (close_db db)
276 c <- liftIO (close_db db)
278 return ()
277 return ()
279
278
contribs/lib/SQLite3/sqlite3api.c+6−6
@@ -21,8 +21,8 @@ void* sqlite3_open_idr(const char *filename){
21 int res =sqlite3_open(filename,&db);
21 int res =sqlite3_open(filename,&db);
22
22
23 if(res != SQLITE_OK){
23 if(res != SQLITE_OK){
24−
25 printf("Error occured while opening the databse.");
24 printf("Error occured while opening the databse.");
25+ return NULL;
26 }
26 }
27 DBinfo *dbi = malloc(sizeof(DBinfo));
27 DBinfo *dbi = malloc(sizeof(DBinfo));
28 dbi->db_ptr = db;
28 dbi->db_ptr = db;
@@ -209,8 +209,8 @@ int sqlite3_get_val_int(void* p,const char* tbl_name, int nRow, int nCol){
209
209
210 }
210 }
211
211
212− rc =sqlite3_column_int(stmt, nCol);
212+ val =sqlite3_column_int(stmt, nCol);
213− printf("int_val : %d\n", rc );
213+ printf("int_val : %d\n", val );
214 rc =sqlite3_finalize(stmt);
214 rc =sqlite3_finalize(stmt);
215 if( rc != SQLITE_OK){
215 if( rc != SQLITE_OK){
216 printf("Couldnt finalize:\n");
216 printf("Couldnt finalize:\n");
@@ -236,8 +236,8 @@ const unsigned char* sqlite3_get_val_text(void* p,const char* tbl_name,int nRow,
236
236
237 rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
237 rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
238 if(rc != SQLITE_OK){
238 if(rc != SQLITE_OK){
239− fprintf(stderr, "SQL Prepare error");
239+ fprintf(stderr, "SQL Prepare error\n");
240−
240+ return NULL;
241 }
241 }
242 rc = sqlite3_step(stmt);
242 rc = sqlite3_step(stmt);
243
243
@@ -273,7 +273,7 @@ float sqlite3_get_float(void* p,const char* tbl_name, int nRow, int nCol){
273
273
274 rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
274 rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
275 if(rc != SQLITE_OK){
275 if(rc != SQLITE_OK){
276− fprintf(stderr, "SQL Prepare error");
276+ fprintf(stderr, "SQL Prepare error\n");
277
277
278 }
278 }
279 rc = sqlite3_step(stmt);
279 rc = sqlite3_step(stmt);