lundi 4 mai 2015

Truncate Table in objective c

I want to delete all table data. But my method is not work.

+(void)truncate
{     
 sqlite3_stmt *deleteComment = nil;
 if (deleteComment == nil) {
    const char *sql;
    sql = "TRUNCATE TABLE ReponseTable";

    if (sqlite3_prepare_v2(database,sql, -1, &deleteComment, NULL) != SQLITE_OK) {
        NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
    }


    if (SQLITE_DONE != sqlite3_step(deleteComment)) {
        NSAssert1(0, @"Error while deleting data. '%s'", sqlite3_errmsg(database));
    }
    sqlite3_reset(deleteComment);
 }        
}

I am getting exception

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error while creating add statement. 'out of memory''

*** First throw call stack:
(
    0   CoreFoundation                      0x00000001049a73f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000104640bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001049a725a +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x000000010425e28f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
    4   BoomAGift                           0x00000001024fd3c4 +[Database truncate] + 276
    5   BoomAGift                           0x00000001024f8325 -[AppDelegate application:didFinishLaunchingWithOptions:] + 405
    6   UIKit                               0x0000000102ade5a5 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 234
    7   UIKit                               0x0000000102adf0ec -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2463
    8   UIKit                               0x0000000102ae1e5c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
    9   UIKit                               0x0000000102ae0d22 -[UIApplication workspaceDidEndTransaction:] + 179
    10  FrontBoardServices                  0x0000000107b202a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    11  CoreFoundation                      0x00000001048dcabc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    12  CoreFoundation                      0x00000001048d2805 __CFRunLoopDoBlocks + 341
    13  CoreFoundation                      0x00000001048d25c5 __CFRunLoopRun + 2389
    14  CoreFoundation                      0x00000001048d1a06 CFRunLoopRunSpecific + 470
    15  UIKit                               0x0000000102ae0799 -[UIApplication _run] + 413
    16  UIKit                               0x0000000102ae3550 UIApplicationMain + 1282
    17  BoomAGift                           0x0000000102537dd3 main + 115
    18  libdyld.dylib                       0x0000000106007145 start + 1
    19  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Aucun commentaire:

Enregistrer un commentaire