Я хочу вставить некоторые данные в менеджер sqlite.При вставке на экране консоли xcode появляется сообщение об ошибке.Но я не могу видеть данные в файле базы данных (mydataabase.sqlite) при его открытии.Как я могу решить это?
метод добавления в MyClass
- (void) addCoffee {
NSArray *pathsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *doumentDirectoryPath=[pathsArray objectAtIndex:0];
destinationPath=[doumentDirectoryPath stringByAppendingPathComponent:@"mydatabase.sqlite"];
NSLog(@"database path %@",destinationPath);
database=nil;
if (sqlite3_open([destinationPath UTF8String], &database)==SQLITE_OK)
{
NSLog(@"dataBaseOpen");
// leak happens here, do stuff then call sqlite3_close(database), or move it out of the if/else block.
if(addStmt == nil) {
const char *sql = "insert into records(Date, Latitude, Longitude) Values(?, ?, ?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) == SQLITE_OK){
sqlite3_bind_text(addStmt, 1, [Date UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(addStmt, 2, [Latitude doubleValue] );
sqlite3_bind_double(addStmt, 3, [Longitude doubleValue] );
}
else
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
recordID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}
else {
sqlite3_close(database);
NSLog(@"dataBaseNotOpen");
NSAssert1(0, @"Error while opening database '%s'", sqlite3_errmsg(database));
}
}
отправка данных:
iDailyAppDelegate *appDelegate = (iDailyAppDelegate *)[[UIApplication sharedApplication] delegate];
//Create a Coffee Object.
MyClass *coffeeObj = [[MyClass alloc] initWithPrimaryKey:0];
coffeeObj.Date = dateInString;
NSDecimalNumber *temp = [[NSDecimalNumber alloc] initWithString:first];
coffeeObj.Latitude = temp;
NSDecimalNumber *temp2 = [[NSDecimalNumber alloc] initWithString:second];
coffeeObj.Longitude = temp2;
[temp release];
coffeeObj.isDirty = NO;
coffeeObj.isDetailViewHydrated = YES;
//Add the object
[appDelegate addCoffee:coffeeObj];