Random sqlite file encrypted or not database

I have an application that often accesses sqlite database. It works great most of the time, but sometimes in one of my database functions it fails and returns:

file is encrypted or not a database

I do not have encryption, but I can’t determine exactly how this happens. It is not always reproducible from accident logs, it happens on the main thread.

Thanks in advance.

@synchronized(self) {
    sqlite3 *database = mydb;
    int result = 0;

    static sqlite3_stmt *stmt = nil;
    if (stmt == nil) {
        const char *sql = "select sum(not isAvailable) from table1 e inner join table2 f on e.key=f.pk where f.pk=? AND e.isDeleting=0;";
        if (sqlite3_prepare_v2(database, sql, -1, &stmt, NULL) != SQLITE_OK) {
            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
        }
    }

    sqlite3_bind_int(stmt, 1, obj.primaryKey);

    if (sqlite3_step(stmt) == SQLITE_ROW) {
        int val = sqlite3_column_int(stmt, 0);
        result = val;
    } else {
        [NSException raise:@"SQL Fail" format:@"SQL Failed: %s", sqlite3_errmsg(database)];
    }
    // Reset the statement for future reuse.
    sqlite3_reset(stmt);

    return result;
}
+5
source share
4 answers

SQLite SQLite, sqlite3_key "pragma key =" . , , SQLite, , . , . SQLite, sqlite3_rekey "pragma rekey =". SQLite, , sqlite3_key ( " =" ), sqlite3_rekey ( "pragma rekey =" ).

+1

, DB - . , .

, , DB. DB "" , ( , SQLite , ). (: - " "?)

0

, " ", , 2 3. , , .

, SQLite SQLite Administrator 0.8.3.2 " " SQLite3, , -, 2, a. s3db. " " " SQLite3" , , . .

| SQLite Administrator , . SQL , Database | New.

0

.

, "" . TimeStamp, . , - , sql ( ), "", , , .

0

All Articles