ios - Cant use Fast enumeration to fill sqlite table -


i have messages object called mastermessages. looks this:

self.messages = ( "<lean: 0x7fcf98665140, objectid: vgle1uj5ki, localid: (null)> {\n    messagebody = jj;\n    recipientid = xvvxetqjph;\n    senderid = xvvxetqjph;\n    timestamp = \"1424991590106.210938\";\n}", "<lean: 0x7fcf98667940, objectid: rgbfybmklu, localid: (null)> {\n    messagebody = \"test 3 ian\";\n    recipientid = xvvxetqjph;\n    senderid = hoy7ujlzoh;\n    timestamp = \"1424631667110.638184\";\n}", "<lean: 0x7fcf98667f30, objectid: hb5uhwsysu, localid: (null)> {\n    messagebody = \"test 2 user1\";\n    recipientid = xvvxetqjph;\n    senderid = vqzxwbdnal;\n    timestamp = \"1424630904935.162109\";\n}", "<lean: 0x7fcf986685b0, objectid: doe2b9oq5b, localid: (null)> {\n    messagebody = \"test 1\";\n    recipientid = xvvxetqjph;\n    senderid = xvvxetqjph;\n    timestamp = \"1424630808309.478027\";\n}" ) 

i create sqlite database calling method in viewdidload , saying sqlite3_errmsg variable being used incorrectly (it used char):

-(void)createdatabase{  nsstring *docsdir; nsarray *dirpaths;  // documents directory dirpaths = nssearchpathfordirectoriesindomains(                                                nsdocumentdirectory, nsuserdomainmask, yes);  docsdir = dirpaths[0];  // build path database file _databasepath = [[nsstring alloc]                  initwithstring: [docsdir stringbyappendingpathcomponent:                                   @"messages.db"]];  nsfilemanager *filemgr = [nsfilemanager defaultmanager];  if ([filemgr fileexistsatpath: _databasepath ] == no) {     const char *dbpath = [_databasepath utf8string];      if (sqlite3_open(dbpath, &_messagesdb) == sqlite_ok)     {         sqlite3_errmsg *errmsg;         const char *sql_stmt =         "create table if not exists messages (id integer primary key autoincrement, objectid text, messagebody text, recipientid text, senderid text, create_time text)";          if (sqlite3_exec(_messagesdb, sql_stmt, null, null, &errmsg) != sqlite_ok)         {             nslog(@"failed create table");          }         sqlite3_close(_messagesdb);     } else {         nslog(@"failed open/create database");     } }  } 

i'm trying save mastermessages sqlite 'messages' table using fast enumeration , sqlite3_bind_xxx rmaddy suggested believe invoking incorrectly because keep getting error of expected identifier.

-(void)savequery{ sqlite3_stmt    *statement; const char *dbpath = [_databasepath utf8string];  if (sqlite3_open(dbpath, &_messagesdb) == sqlite_ok) {     (id lean in mastermessages) {         int *insertsql = [int sqlite3_bind("insert messages (objectid, messagebody, recipientid, senderid, create_time) values (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\")",                            [lean valueforkeypath:@"objectid"],                            [lean valueforkeypath:@"messagebody"],                            [lean valueforkeypath:@"recipientid"],                            [lean valueforkeypath:@"senderid"],                            [lean valueforkeypath:@"timestamp"])];          nslog(@"insertsql = %@", insertsql);          const char *insert_stmt = [insertsql utf8string];         sqlite3_prepare_v2(_messagesdb, insert_stmt,                         -1, &statement, null);         if (sqlite3_step(statement) == sqlite_done)         {             nslog(@"message added");         } else {             nslog(@"failed add message");         }     }     sqlite3_finalize(statement);     sqlite3_close(_messagesdb); } } 

how fix this?

thank you.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -