Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is how I've inserted data into sqlite in iOS 5 and it is working fine. </p> <pre><code>-(void) checkAndCreateDatabase{ BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; success = [fileManager fileExistsAtPath:databasePath]; if(success) return; NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; } -(void) openDatabase { NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDir = [documentsPaths objectAtIndex:0]; databasePath = [documentDir stringByAppendingPathComponent:YOUR_DATABASE_NAME]; [self checkAndCreateDatabase]; if(sqlite3_open([databasePath UTF8String],&amp;database) == SQLITE_OK) NSLog(@"Database opened."); } -(BOOL)insertDataWithUsername:(NSString*)name withPassword:(NSString*)password withAge:(int)age { [self openDatabase]; NSString *query = nil; query = [NSString stringWithFormat:@"INSERT INTO your_table(name, password, age) Values('%@','%@', %d)", name, password, age]; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, [query UTF8String], -1, &amp;compiledStatement, NULL) == SQLITE_OK) { if(SQLITE_DONE != sqlite3_step(compiledStatement)) NSLog( @"Error while inserting data: '%s'", sqlite3_errmsg(database)); else NSLog(@"New data inserted"); sqlite3_reset(compiledStatement); }else { NSLog( @"Error while inserting '%s'", sqlite3_errmsg(database)); } sqlite3_finalize(compiledStatement); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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.
 

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