我试图插入一些值到我的sqlite数据库。数据库已经在手机上的doc文件夹中。我不知道发生了什么问题。我设置跟踪执行,但数据库告诉我,它没有任何错误。有人能帮我吗?iOS:SQLite插入查询不起作用
if([[TRSharedLocalDatabase openDatabase] executeUpdateWithFormat:@"INSERT INTO event (title,date,address,latitude,longitude,location,facebookID,picPath,description) VALUES (%@,%@,%@,%@,%@,%@,%@,%@,%@)",event.title ,event.date, event.address, [NSNumber numberWithDouble:event.geoPoint.longitude], [NSNumber numberWithDouble:event.geoPoint.latitude], event.location.objectId, event.facebookID ,picPath ,event.description]) {
NSLog(@"Ok");
} else {
NSLog(@"Not Ok");
}
+(FMDatabase *)openDatabase {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"4PartyLocalSystem.sqlite"];
**FMDatabase *database = [FMDatabase databaseWithPath:writableDBPath];**
[database open];
[database setTraceExecution:YES];
return database;
}
2013年8月6日13:21:42.499 4Party [13018:907]的executeUpdate:INSERT INTO事件(标题,日期,地址,纬度,经度,位置,facebookID,picPath介绍)VALUES
拉斐尔,如果你提供的有关'TRSharedLocalDatabase'更多信息,这将是有益的。你可以分享“openDatabase”方法的代码吗?确切地说,如果不了解更多关于代码的功能,将很难帮助您。 – Aaron
openDatabase方法仅用于打开数据库。这里是:NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0]; NSString * writableDBPath = [documentsDirectory stringByAppendingPathComponent:@“4PartyLocalSystem.sqlite”]; FMDatabase * database = [FMDatabase databaseWithPath:writableDBPath]; [数据库打开]; [数据库setTraceExecution:YES]; 返回数据库; –
请通过编辑将问题添加到问题中,而不是将其添加到评论中。在评论 –