SQLite3 - 使用iOS 7不按顺序调用的库例程

时间:2013-11-26 11:38:47

标签: ios sqlite sequence

使用共享实例我有时会在执行期间崩溃。

崩溃可以复制,但绝不会以常规方式发生。使用iOS 7.0时出现的这种崩溃与以前的iOS版本一起正常运行。

欢迎提供帮助

2013-11-26 12:25:38.149 Publilex[1942:a0b] library routine called out of sequence
2013-11-26 12:25:38.229 Publilex[1942:a0b] Uncaught exception Failed to open database with message 'library routine called out of sequence'.

2013-11-26 12:25:38.261 Publilex[1942:a0b] Stack trace: (
    0   CoreFoundation                      0x01ef05e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01bc48b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01ef03bb +[NSException raise:format:] + 139
    3   Publilex                            0x00027097 -[DBAccess raiseSqliteException:] + 199
    4   Publilex                            0x00023c3d -[DBAccess open] + 173
    5   Publilex                            0x00023ae8 +[DBAccess shared] + 232
    6   Publilex                            0x00027e5e +[Word synIdForWord:] + 78
    7   Publilex                            0x0002812d +[Word synIdsFor:] + 429
    8   Publilex                            0x00037b8b -[Searcher nbArticlesFor:] + 187
    9   Publilex                            0x0002df2b -[SearchViewController updateSuggestionsFor:] + 731
    10  Publilex                            0x0002e5ef -[SearchViewController textField:shouldChangeCharactersInRange:replacementString:] + 783
    11  UIKit                               0x00e0fa56 -[UITextField keyboardInputShouldDelete:] + 252
    12  UIKit                               0x008ff0f7 -[UIKeyboardImpl callShouldDeleteWithWordCountForRapidDelete:characterCountForRapidDelete:] + 691
    13  UIKit                               0x00909ed5 -[UIKeyboardImpl deleteFromInputWithExecutionContext:] + 84
    14  UIKit                               0x00906965 -[UIKeyboardImpl handleDeleteAsRepeat:executionContext:] + 130
    15  UIKit                               0x0091516f -[UIKeyboardImpl handleKeyWithString:forKeyEvent:executionContext:] + 633
    16  UIKit                               0x00914cb6 -[UIKeyboardImpl handleKeyEvent:executionContext:] + 1808
    17  UIKit                               0x0091450f __33-[UIKeyboardImpl handleKeyEvent:]_block_invoke + 51
    18  UIKit                               0x00e371b8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
    19  UIKit                               0x00e3785f -[UIKeyboardTaskQueue addTask:] + 144
    20  UIKit                               0x009144d4 -[UIKeyboardImpl handleKeyEvent:] + 227
    21  UIKit                               0x0073dfbb -[UIApplication _handleKeyUIEvent:] + 330
    22  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    23  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    24  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    25  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    26  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    27  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    28  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    29  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    30  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    31  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    32  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    33  UIKit                               0x00884634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    34  UIKit                               0x0073de6a -[UIApplication handleKeyUIEvent:] + 84
    35  UIKit                               0x0073de0e -[UIApplication handleKeyHIDEvent:] + 458
    36  UIKit                               0x00725c8c _UIApplicationHandleEventQueue + 2954
    37  CoreFoundation                      0x01e798af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    38  CoreFoundation                      0x01e7923b __CFRunLoopDoSources0 + 235
    39  CoreFoundation                      0x01e9630e __CFRunLoopRun + 910
    40  CoreFoundation                      0x01e95b33 CFRunLoopRunSpecific + 467
    41  CoreFoundation                      0x01e9594b CFRunLoopRunInMode + 123
    42  GraphicsServices                    0x02ef49d7 GSEventRunModal + 192
    43  GraphicsServices                    0x02ef47fe GSEventRun + 104
    44  UIKit                               0x0072a94b UIApplicationMain + 1225
    45  Publilex                            0x00002893 main + 115
    46  libdyld.dylib                       0x0246e725 start + 0
)

+(DBAccess *)shared{
    @synchronized(self){
        if (sharedInstance == nil){
            sharedInstance = [[DBAccess alloc] initWithFileName:DATABASE_NAME];
            [sharedInstance createEditableCopyOfDatabaseIfNeeded];
        }
        [sharedInstance open];
    }
    return sharedInstance;
}

- (NSArray *) executeSQLNoCache:(NSString *)sql{

    NSLog(@"%@ - Execution No Cache", sql);

    char* errorMessage;

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSMutableDictionary *queryInfo = [[NSMutableDictionary alloc] initWithCapacity:1];
    [queryInfo setObject:sql forKey:@"sql"];

    NSMutableArray *rows = [[NSMutableArray alloc] init];

    sqlite3_stmt *statement = NULL;
    int returnCode = sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL);

    if (returnCode == SQLITE_OK) {

        BOOL needsToFetchColumnTypesAndNames = YES;
        NSArray *columnTypes = nil;
        NSArray *columnNames = nil;

        while (sqlite3_step(statement) == SQLITE_ROW) {
            if (needsToFetchColumnTypesAndNames) {
                columnTypes = [self columnTypesForStatement: statement];
                columnNames = [self columnNamesForStatement: statement];
                needsToFetchColumnTypesAndNames = NO;
            }

            NSMutableDictionary *row = [[NSMutableDictionary alloc] init];
            [self copyValuesFromStatement:statement
                                    toRow:row
                                queryInfo:queryInfo
                              columnTypes:columnTypes
                              columnNames:columnNames];

            [rows addObject:row];
            [row release];

        }

    } else {
        sqlite3_finalize(statement);

        [self raiseSqliteException:
         [[NSString stringWithFormat:@"Failed to execute statement : '%@' with message: ", sql] stringByAppendingString:@"%S"]];
    }

    [queryInfo release];
    sqlite3_exec(database, "COMMIT TRANSACTION", NULL, NULL, &errorMessage);
    sqlite3_finalize(statement);

    [pool release];
    return rows;
}

1 个答案:

答案 0 :(得分:0)

这里,代码运行没有SQL Cash的所有语句。并且引发的唯一错误是库耗尽序列:

- (NSArray *) executeSQLNoCache:(NSString *)sql{

    NSLog(@"%@ - Execution No Cache", sql);

    char* errorMessage;

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSMutableDictionary *queryInfo = [[NSMutableDictionary alloc] initWithCapacity:1];
    [queryInfo setObject:sql forKey:@"sql"];

    NSMutableArray *rows = [[NSMutableArray alloc] init];

    sqlite3_stmt *statement = NULL;
    int returnCode = sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL);

    if (returnCode == SQLITE_OK) {

        BOOL needsToFetchColumnTypesAndNames = YES;
        NSArray *columnTypes = nil;
        NSArray *columnNames = nil;

        while (sqlite3_step(statement) == SQLITE_ROW) {
            if (needsToFetchColumnTypesAndNames) {
                columnTypes = [self columnTypesForStatement: statement];
                columnNames = [self columnNamesForStatement: statement];
                needsToFetchColumnTypesAndNames = NO;
            }

            NSMutableDictionary *row = [[NSMutableDictionary alloc] init];
            [self copyValuesFromStatement:statement
                                    toRow:row
                                queryInfo:queryInfo
                              columnTypes:columnTypes
                              columnNames:columnNames];

            [rows addObject:row];
            [row release];

        }

        sqlite3_reset(statement);

    } else {
        sqlite3_finalize(statement);

        [self raiseSqliteException:
         [[NSString stringWithFormat:@"Failed to execute statement : '%@' with message: ", sql] stringByAppendingString:@"%S"]];
    }

    [queryInfo release];
    sqlite3_exec(database, "COMMIT TRANSACTION", NULL, NULL, &errorMessage);
    sqlite3_finalize(statement);
    sqlite3_close(database);

    [pool release];
    return rows;
}