I have an app that has been doing a SQLite3 select statement perfectly before I upgraded to Xcode 4. I have not changed anything.
Somehow it now says that my SQLite3 database is no longer a database (returns error 26), yet I am able to open and edit it in Base 2.1 (895).
Does anyone know please if anything in Xcode 4 was deprecated, which would cause this to happen?
Here is my select method:
Code:
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
//*Get key
NSMutableDictionary *newbusinessData = [NewBusiness getData];//Call my Singleton
int AgeNBKey = [[newbusinessData objectForKey:@"AgeNB"] integerValue];
NSLog(@"AgeNBKey: %i:",AgeNBKey);
NSString *s = [NSString stringWithFormat:@"SELECT Rate from PremiumRates WHERE AgeNB = %i", AgeNBKey];
NSLog(@"s: %@",s);
const char *sql = [s cStringUsingEncoding:NSASCIIStringEncoding];
sqlite3_stmt *selectstmt;
int num = sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL);
if(num == SQLITE_OK) {
NSLog( @"Error LOG: %s", sqlite3_errmsg(database) );
}else{
NSLog(@"num:%d", num);//if 26 then File opened that is not a database file
}
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger queryKey = sqlite3_column_int(selectstmt, 0);
PremiumRates *manObj = [[PremiumRates alloc] initWithPrimaryKey:queryKey];
manObj.Rate = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(selectstmt, 0)];
manObj.isDirty = NO;
[newbusinessData setValue: manObj.Rate forKey:@"PremiumRate"];
//Write to Plist
NSString *plistPath = [NewBusiness getPath];//Call my Singleton
[newbusinessData writeToFile:plistPath atomically:YES];
[manObj release];
}
}
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}