xcode - SQLite Query statement - Objective C -
my problem cant values select query executes 101 error.
i think problem has quotes in select statement
sqlite3 * database ;
nsstring * path = [[[ nsbundle mainbundle ]resourcepath ] stringbyappendingpathcomponent : @"cars.sqlite"]; int returncode = sqlite3_open ([ path cstringusingencoding : nsutf8stringencoding], &database) ; sqlite3_stmt * statement ; char * st ; nsstring *querysql = [nsstring stringwithformat: @"select brand,model cars brand=%@;", tmpbrand]; const char *query_stmt = [querysql utf8string]; st = sqlite3_mprintf (query_stmt); if(sqlite3_prepare_v2 ( database , query_stmt , -1 ,& statement ,null )==sqlite_ok){ returncode = sqlite3_step ( statement ) ; // statement returns record while ( returncode == sqlite_row ) // while there rows { models*tmp=[[models alloc]init]; char* n=(char*)sqlite3_column_text(statement,0); tmp=[nsstring stringwithcstring:n encoding:nsutf8stringencoding]; char* model=(char*)sqlite3_column_text(statement, 1); tmp.model=[nsstring stringwithcstring:model encoding:nsutf8stringencoding]; [data addobject:tmp]; returncode = sqlite3_step ( statement ) ; // statement returns record } sqlite3_finalize(statement); }
}
a quick @ the documentation shows error 101 means "done".
the sqlite_done result code indicates operation has completed.
if you're not getting rows expect, you're right, it's query. make work need put single quotes around '%@'
.
however, not right way of doing it. should using prepared statements. is, query looks select brand,model cars brand=?
, fill in values using bind function.
Comments
Post a Comment