ios - Error while calling sql statement -
i getting weirded error, have code data local db.
my query follows
select * survey_details feedback_status="yes"
when fire above query function gives proper output.but when pass no gives me error.
following function
-(nsmutablearray*)selectfromdbandaddtoarrayforfeedbackstatus:(nsstring *)feedbackstatus { nsmutablearray *tablearray = [[nsmutablearray alloc]init]; sqlite3_stmt *statement; const char *dbpath = [databasepath utf8string]; if (sqlite3_open(dbpath, &passiondb) == sqlite_ok) { nsstring *insertsql = [nsstring stringwithformat: @"select * survey_details feedback_status != \"%@\"",feedbackstatus]; nslog(@"insert stmnt %@", insertsql); const char *insert_stmt = [insertsql utf8string]; if(sqlite3_prepare_v2(passiondb, insert_stmt, -1, &statement, nil)== sqlite_ok) { nslog(@"sqlite_ok"); if (sqlite_row != sqlite3_step(passiondb)) { } else{ } while(sqlite3_step(statement) == sqlite_row) { nsmutablearray *edittablearray = [[nsmutablearray alloc]init]; nsstring *title = [nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 2)]; nsstring *name = [nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 3)]; nsstring *surname = [nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 4)]; nsstring *time = [nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 14)]; // nsstring *user_id = [nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 1)]; nsnumber *user_id = [nsnumber numberwithint:(int)sqlite3_column_int(statement, 1)]; [edittablearray addobject:title]; [edittablearray addobject:name]; [edittablearray addobject:surname]; [edittablearray addobject:time]; [edittablearray addobject:user_id]; nsstring *imagepath; if ([feedbackstatus isequaltostring:@"yes"]) { if(sqlite3_column_text(statement, 13) != nil) { imagepath = [nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 13)]; } else { imagepath = @"none"; } [edittablearray addobject:imagepath]; } [tablearray addobject:edittablearray]; edittablearray=nil; } nslog(@"tablearray1 %@",tablearray); } if (sqlite3_step(statement) == sqlite_done) { nslog(@"sqlite done"); nslog(@"error %s while sqlite3_step ", sqlite3_errmsg(passiondb)); } else { nslog(@"sqlite not done"); nslog(@"error %s while sqlite3_step ", sqlite3_errmsg(passiondb)); } sqlite3_finalize(statement); sqlite3_close(passiondb); } nslog(@"tablearray2 %@",tablearray); return tablearray; }
try using query:
nsstring *status= @"no"; nsstring *querysql = [nsstring stringwithformat:@"select * survey_details feedback_status ='%@'",status];
see if query works you.
Comments
Post a Comment