on master help sign in
printing data, doesnt quite work on idris
commit63493170ff89fc78a388995c476dee15c62d0f65 authormelissam <mfm6@st-andrews.ac.uk> dateTue 17 Jul 2012, 15:44 (14 years ago) parent083440b
2 files changed+12−13
contribs/lib/SQLite3/sqlite3.idr+6−7 contribs/lib/SQLite3/sqlite3api.c+6−6
contribs/lib/SQLite3/sqlite3.idr+6−7
@@ -249,12 +249,12 @@ bind_null (MkStmtPtr pointer) indexval =do
249249
250250instance Show DBVal where
251251 show (DBInt i) = "Int val: " ++ show i
252− show (DBText i) = "Text val: " ++ i
252+ show (DBText i) = "Text val: " ++ show i
253253 show (DBFloat i) = "Float val: " ++ show i
254254 show (DBNull ) = "NULL"
255255
256256print_data_v2 : DBVal -> String
257−print_data_v2 val = (show val)
257+print_data_v2 = show
258258
259259test : DB()
260260test = do db <- liftIO (open_db "somedb.db")
@@ -268,12 +268,11 @@ test = do db <- liftIO (open_db "somedb.db")
268268 return ()
269269
270270test2 : DB ()
271−test2 = do db <- liftIO (open_db "somedb.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")
271+test2 = 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")
274273 --res <- (toList "Student" "select *from Student;" db)
275− -- mydata <- liftIO ( get_data db "Student" 1 1)
276−
274+ mydata <- liftIO ( get_data db "Student" 1 1)
275+ liftIO(print mydata)
277276 c <- liftIO (close_db db)
278277 return ()
279278
contribs/lib/SQLite3/sqlite3api.c+6−6
@@ -21,8 +21,8 @@ void* sqlite3_open_idr(const char *filename){
2121 int res =sqlite3_open(filename,&db);
2222
2323 if(res != SQLITE_OK){
24−
2524 printf("Error occured while opening the databse.");
25+ return NULL;
2626 }
2727 DBinfo *dbi = malloc(sizeof(DBinfo));
2828 dbi->db_ptr = db;
@@ -209,8 +209,8 @@ int sqlite3_get_val_int(void* p,const char* tbl_name, int nRow, int nCol){
209209
210210 }
211211
212− rc =sqlite3_column_int(stmt, nCol);
213− printf("int_val : %d\n", rc );
212+ val =sqlite3_column_int(stmt, nCol);
213+ printf("int_val : %d\n", val );
214214 rc =sqlite3_finalize(stmt);
215215 if( rc != SQLITE_OK){
216216 printf("Couldnt finalize:\n");
@@ -236,8 +236,8 @@ const unsigned char* sqlite3_get_val_text(void* p,const char* tbl_name,int nRow,
236236
237237 rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
238238 if(rc != SQLITE_OK){
239− fprintf(stderr, "SQL Prepare error");
240−
239+ fprintf(stderr, "SQL Prepare error\n");
240+ return NULL;
241241 }
242242 rc = sqlite3_step(stmt);
243243
@@ -273,7 +273,7 @@ float sqlite3_get_float(void* p,const char* tbl_name, int nRow, int nCol){
273273
274274 rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
275275 if(rc != SQLITE_OK){
276− fprintf(stderr, "SQL Prepare error");
276+ fprintf(stderr, "SQL Prepare error\n");
277277
278278 }
279279 rc = sqlite3_step(stmt);