sqlite error :/* SQL error or missing database */
- by user262325
Hello everyone
I have a project in which I stored sqlite database file "data.sqlite3" to
'Group'&files'-'resource'
Below are my viewcontroller source codes
//-myviewcontroller.h
#import "sqlite3.h"
#define kFilename @"data.sqlite3"
//myviewcontroller.m
-(NSString *)dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:kFilename];
}
-(void)f
{
if (sqlite3_open([[self dataFilePath] UTF8String],&database)!=SQLITE_OK)
//dataFilePath returns
///Users/interdev/Library/Application Support/iPhone Simulator/User/Applications/095C6E05-4EAE-4817-883E-A72E39D439E0/Documents/data.sqlite3
{
sqlite3_close(database);
NSAssert(0,@"Failed to open database");//no problem
}
NSString *query = @"SELECT * FROM table1 ORDER BY ROW";//table1 is table name
sqlite3_stmt *statement;
NSInteger v=sqlite3_prepare_v2( database, [query UTF8String],
-1, &statement, nil);
NSString *zs= [NSString stringWithFormat:@"%d",v];
NSLog(@" The buttontitile is %@ ",zs);
if ( v == SQLITE_OK) { // ...
}
I checked value of v in log, it always is 1
#define SQLITE_ERROR 1 /* SQL error or missing database */
I do not know why this happened.