Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks mmcomb, Thanks Mat. From both your advices i have solved the problem completely.</p> <ul> <li><p><strong>Firstly</strong> I wasn't checking the DB path and then opening the connection.</p></li> <li><p><strong>Secondly</strong> after having prepared the statement and bounding the appropriate variables i had to call <code>sqlite3_step</code> before calling <code>sqlite3_last_insert_rowid</code>.</p></li> <li><p><strong>Thirdly</strong> i needed to call <code>sqlite3_finalize</code> to free the resources.</p></li> <li><p><strong>Fourthly</strong> i needed to <code>sqlite3_close</code> the connection.</p></li> </ul> <p>'library routine called out of sequence' error was due to not opening and closing the connection properly. </p> <p>This is the right code:</p> <pre><code>NSInteger keyID; // in .h class NSMutableArray *user;// in .h class -(void) writeintoUserDatabase:(NSString*)value1:(NSString*)value2:(NSString*)value3 { sqlite3* database; databaseName = @"UserData";// create a db with this name and keep it in app resources folder NSString *pathToDatabase; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; pathToDatabase = [documentsDir stringByAppendingPathComponent:databaseName]; int databaseReturnCode = sqlite3_open([pathToDatabase UTF8String], &amp;database); NSLog(@"databaseReturnCode %d",databaseReturnCode); if(databaseReturnCode == SQLITE_OK) { const char *sql = "insert into UserData(firstName,lastName,userName) Values(?, ?, ?)"; sqlite3_stmt *insert_statement; sqlite3_prepare_v2(database, sql, -1, &amp;insert_statement, NULL); sqlite3_bind_text(insert_statement, 1, [value0 UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(insert_statement, 2, [value1 UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(insert_statement, 3, [value2 UTF8String], -1, SQLITE_TRANSIENT); printf( "is there an error?: %s\n", sqlite3_errmsg(database) ); while(sqlite3_step(insert_statement) == SQLITE_ROW) { NSString *aFirstName = [NSString stringWithUTF8String: (char*)sqlite3_column_text(insert_statement, 1)]; NSString *aLastName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(insert_statement, 2)]; NSString *aUserName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(insert_statement, 3)]; users = [[NSMutableArray alloc]initWithObjects:aFirstName,aLastName,aUserName,nil]; } keyID = sqlite3_last_insert_rowid(database); sqlite3_reset(insert_statement); sqlite3_finalize(insert_statement); } sqlite3_close(database); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload