【发布时间】:2011-11-25 17:49:25
【问题描述】:
我不知道我的程序有什么问题。在我的程序中运行此选择代码以从 SQlite 获取数据时,它第一次崩溃并显示以下错误消息:
杀死目标时杀死错误(无论如何都要杀死):
警告:函数“macosx_kill_inferior_safe”中“/SourceCache/gdb/gdb-1510/src/gdb/macosx/macosx-nat-inferior.c”的第 2179 行出错:(os/kern) 失败 (0x5x)
退出
这是我的插入代码:
-(id)init {
self = [super init];
sqlite3 *database;
NSMutableArray *locations;
NSString *result = nil;
NSString *dbPath = [self getWritableDBPath];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
NSString *sqlStr = [NSString stringWithFormat:@"select Longitude,Latitude from myLocation"];
const char *sqlStatement = [sqlStr UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
locations = [NSMutableArray array];
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
double longitude = sqlite3_column_double(compiledStatement, 0);
double latitude = sqlite3_column_double(compiledStatement, 1);
NSLog(@"%f , %f",longitude,latitude);
NSString *coords = [[[NSString alloc] initWithFormat:@"%f,%f\n",longitude,latitude] autorelease];
[locations addObject:coords];
NSLog(@"this location :-%@",locations);
//[coords release];
}
result = [locations componentsJoinedByString:@","]; // same as `fake_location`
NSLog(@"this for resulte data :- %@",result);
// Get file path here
NSError *error;
if ( [result writeToFile:dbPath atomically:YES encoding:NSUTF8StringEncoding error:&error] ) {
NSLog(@"%@", [error localizedDescription]);
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
pointsArray = [[result componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] retain];
pointsArrayIndex = 0;
oldLocationsIndex = 0;
[result release];
oldLocations = [[NSMutableArray alloc] init];
return self;
}
我第二次运行我的应用程序时,它会在控制台上显示:
保存错误:文件已加密或不是数据库
这些错误是什么意思,我该如何解决?
【问题讨论】:
-
你想在sqlite中触发插入查询吗??????
-
是的,我的朋友我需要 sqlite 插入语句
-
你试图用 NSData 覆盖整个数据库文件,你不能这样做,检查我下面的答案,你只需要触发插入查询...
-
@jignesh 实际上我正在尝试获取数据而不是插入数据。当我在编写选择代码后第一次运行时给我错误,当第二次运行时它给我保存错误:文件已加密或者不是数据库
-
你能调试一下 dbPath 它提供了什么吗??
标签: iphone objective-c sqlite