【问题标题】:Sqlite database file is getting encrypted or is not a databaseSqlite 数据库文件正在加密或不是数据库
【发布时间】:2011-11-25 17:49:25
【问题描述】:

我不知道我的程序有什么问题。在我的程序中运行此选择代码以从 SQlite 获取数据时,它第一次崩溃并显示以下错误消息:

杀死目标时杀死错误(无论如何都要杀死):
警告:函数“macosx_kill_inferior_safe”中“/SourceCache/gdb/gdb-1510/src/gdb/macosx/macosx-nat-i​​nferior.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


【解决方案1】:

您需要使用以下方法触发插入查询:

-(void)insertLocation:(double)latitude withLongitude:(double)longitude
{
sqlite3_stmt *insertStatement = nil;
const char *sql = "insert into UserJourneyLocation(Latitude, Longitude) Values(?,?)";
int returnValue = sqlite3_prepare_v2(database, sql, -1, &insertStatement, NULL);
if(returnValue == SQLITE_OK)
{
    sqlite3_bind_double(insertStatement,1,latitude);
            sqlite3_bind_double(insertStatement,2,longitude);
    if(sqlite3_step(insertStatement)==SQLITE_DONE)
    {
        //Data;
    }
}
sqlite3_finalize(insertStatement);
}

【讨论】:

  • 对不起我的朋友,我在做选择语句而不是插入语句对不起请检查更新数据问题
  • 但是你不能使用[result writeToFile:dbPath atomically:YES encoding:NSUTF8StringEncoding error:&error]将数据写入数据库,你能说说为什么使用这条线吗??
  • 我评论那行它可以工作,但现在显示下一个类似的错误 -[CFString release]: message sent to deallocated instance 0xe2db5f0.
  • 谢谢它的工作,但我应该什么时候写[结果 writeToFile:dbPath atomically:YES encoding:NSUTF8StringEncoding error:&error] 有什么用。什么时候使用它
【解决方案2】:

是的,我有。

进入iphone应用程序文件夹

/users/(yourname)/library/application support/iphone 模拟器/user/application

并删除所有目标。然后重新启动您的应用程序。

【讨论】:

  • 没有我的朋友,它会告诉我保存错误:文件已加密或不是数据库
猜你喜欢
  • 2014-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多