Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite3 (iOs) query not executing
    primarykey
    data
    text
    <p>I'm fairly new to iPhone dev.</p> <p>Im having some trouble getting this to work.</p> <p>This is the code i want to execute:</p> <pre><code>[self openDB]; sqlite3_stmt *statement; NSString *sql2 = [NSString stringWithFormat:@"INSERT INTO CheckList (CLName, DateAdd, Active, Costum, Percentage, UserId) VALUES ('ola232332332324', '2012-02-03', 1, 1, NULL, 1)"]; if(sqlite3_prepare_v2(db, [sql2 UTF8String], -1, &amp;statement, NULL) == SQLITE_OK) { alert1 = [[UIAlertView alloc] initWithTitle:@"Grats" message:@"The query was executed!" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles: nil]; [alert1 show]; [alert1 release]; } else { NSAssert(0, @"Failed to execute"); } sqlite3_finalize(statement); </code></pre> <p>And this is the code i use to call the db:</p> <pre><code>-(NSString *) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; return [documentsDir stringByAppendingPathComponent:@"prosegur.sqlite"]; } -(void) openDB { sqlite3_open([[self filePath] UTF8String], &amp;db); if (sqlite3_open([[self filePath] UTF8String], &amp;db) != SQLITE_OK){ NSAssert(0, @"Failed to open db"); } } </code></pre> <p>Thanks in advance,</p> <p>Rodolfo Matos</p> <p><strong>Edit:</strong> Trying to use the FMDB, here's the code:</p> <pre><code>FMDatabase *database = [FMDatabase databaseWithPath:@"prosegur.sqlite"]; if([database open]){ NSLog(@"yes"); [database executeUpdate:@"INSERT INTO CheckList (CLName, DateAdd, Active, Costum, UserId) VALUES ('cenas', '2012-02-0', 1, 1, 1)"];} else { NSLog(@"not"); } </code></pre> <p>Passes by the [database open] verification, but it doesn't execute the query. Any suggestion? Thanks!</p> <p><strong>EDIT 2:</strong> Already did what it was suggested, i'm starting to think that it creates a database and executes the query inside of it, but since it doesn't exist any table, it ignores that fact. </p> <p>Here's the updated code: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsPath = [[paths objectAtIndex:0] retain]; NSString *path = [[docsPath stringByAppendingPathComponent:@"prosegur.sqlite"] retain];</p> <pre><code>FMDatabase *database = [FMDatabase databaseWithPath:path]; [database open]; if([database open]) { NSLog(@"yes"); [database executeUpdate:@"INSERT INTO CheckList (CLName) VALUES (?)", @"cenas"]; } else { NSLog(@"no"); } [database close]; </code></pre> <p>Thanks again! :)</p>
    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.
 

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