0

I've a SQLite db on this position

/Users/software/Library/Application Support/iPhone Simulator/5.0/Applications/723EEE91-CB9D-4A27-8492-D61E127E72B7/myAPP.app/localDB.sqlite

No problems on write, delete or read data. For example if I write on DB and close application, I find data in my DB, but if I restart the app my DB will clear. Can someone tell me why?

This is an example of a DB instance

SQLiteUtilities *db = [[SQLiteUtilities alloc]init:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"localDB.sqlite"]];

[db loadValuesFromQuery:@"SELECT * FROM categories;"];
for (int i = 0; i < [db getSize]; i++) {
    NSLog(@"-- %@", [db objectAtIndex:i]);
}
[db release];

-(void)loadValuesFromQuery:(NSString *)query {

GenericRecord *record = [[[GenericRecord alloc]init] autorelease];

if (sqlite3_open([pathDB UTF8String], &database) == SQLITE_OK) {
    // query che ricava i valori
    const char *sql = (const char *) [query UTF8String];
    sqlite3_stmt *selectstmt;

    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

        while(sqlite3_step(selectstmt) == SQLITE_ROW) {
            // ricaviamo i valori letti dalla query
            record.uniqueID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
            record.superID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
            record.subSuperID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
            record.title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];
            record.description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];
            record.price = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)];
            record.note = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 7)];
            record.pictureURL = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 8)];
            record.catName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 9)];
            record.subCatName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 10)];

            NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selectstmt, 11) length:sqlite3_column_bytes(selectstmt, 11)];
            if(data) record.imageBig = [UIImage imageWithData:data];

            [self.list addObject:record];

        }
    }
}
sqlite3_close(database);

}

  • Try [this][1] [1]: http://stackoverflow.com/questions/9887785/sqlite-database-load-fails-issue-with-sqlite-prepare-statement-iphone-xcod/9888240#9888240 – WaaleedKhan Mar 30 '12 at 12:55
  • app fail here, on nsassert if(success) { NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"localDB.sqlite"]; success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error]; if (!success) NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]); } – user1303255 Mar 30 '12 at 13:19
  • dude ur application is not getting the DB from the finder.... check out my answer in the above link and try the steps, hopefully it will work – WaaleedKhan Mar 30 '12 at 13:22

1 Answers1

0

Also curious why I'm seeing so much raw sqlite3 work these days - any reason you're not using Core Data? Just a suggestion - it may not fit your needs (i.e., schema already exists and you're downloading it directly, etc).

Scott Corscadden
  • 2,831
  • 1
  • 25
  • 43