objective c - sqlite3_exec == SQLITE_OK failure -
i'm new developing in objective c , struggling step if statement (sqlite3_exec==sqlite_ok). have been using tutorials , dont seem able find answer.
is able show me i'm going wrong?
-(ibaction)additembutton:(id)sender { char *error; if (sqlite3_open([dbpathstring utf8string], &itemdb) == sqlite_ok) { nsstring *insertstat = [nsstring stringwithformat:@"insert items(item) values ('%s')", [self.itemfield.text utf8string]]; const char *insert_stat = [insertstat utf8string]; if (sqlite3_exec(itemdb, insert_stat, null, null, &error)== sqlite_ok) { nslog(@"item added"); item *item = [[item alloc]init]; [item setitem:self.itemfield.text]; [arrayofitem addobject:item]; }else{ nslog(@"item not added"); } sqlite3_close(itemdb); } }
i have written simple sqlite helper performing general database tasks few lines of code fetching records db, inserting, updating , deleting records. source code can found here example
download , drag, drop zeesqlitehelper classes in project , set db name in zeesqlitehelper class.
getting records example:
[zeesqlitehelper initializesqlitedb]; nsstring *query = @"select * recipes"; nsmutablearray *results = [zeesqlitehelper readqueryfromdb:query]; [zeesqlitehelper closedatabase]; for insertion
[zeesqlitehelper initializesqlitedb]; nsstring *querystring = [nsstring stringwithformat:@"insert %@ (%@,%@) values ('%@','%@')",downloadstblname, tblattrfilename, tblattrfileurl, downloadinfo.filename, downloadinfo.fileurl]; [zeesqlitehelper executequery:querystring]; [zeesqlitehelper closedatabase]; for updation
[zeesqlitehelper initializesqlitedb]; nsstring *querystring = [nsstring stringwithformat:@"update %@ set %@='%@' %@='%@'",downloadstblname, tblattrfilename, newfilepath.lastpathcomponent, tblattrfilename,oldfilepath.lastpathcomponent]; [zeesqlitehelper executequery:querystring]; [zeesqlitehelper closedatabase]; for deletion
[zeesqlitehelper initializesqlitedb]; nsstring *querystring = [nsstring stringwithformat:@"delete %@ %@='%@'",downloadstblname, tblattrfilename,downloadedfileobj.videotitle]; [zeesqlitehelper executequery:querystring]; [zeesqlitehelper closedatabase]; appropriate message of success or failure logged on console.
Comments
Post a Comment