Файл базы данных Sqlite становится зашифрованным или не является базой данных - PullRequest
0 голосов
/ 30 июня 2011

Понятия не имею, в чем проблема в моей программе. При запуске этого кода выбора для извлечения данных из SQlite в моей программе, в первый раз он падает с этим сообщением об ошибке:

ошибка уничтожения при убийстве цели (в любом случае):
предупреждение: ошибка в строке 2179 "/SourceCache/gdb/gdb-1510/src/gdb/macosx/macosx-nat-inferior.c" в функции "macosx_kill_inferior_safe": (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;
}

Во второй раз, когда я запускаю свое приложение, оно показывает мне это на консоли:

Ошибка сохранения: файл зашифрован или не является базой данных

Что означают эти ошибки, и как мне их решить?

Ответы [ 2 ]

1 голос
/ 30 июня 2011

Вам нужно запустить запрос вставки, используя следующее:

-(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);
}
0 голосов
/ 30 июня 2011

Да, у меня есть.

Перейдите в папку документов приложения iphone

/ users / (ваше имя) / библиотека / поддержка приложений / iphone simulator / user / application

И удалите все цели. После этого перезапустите приложение.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...