Guest User

try-catch-finally (sqlite3)

a guest
Apr 28th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sqlite3_stmt *statement = nil;
  2.  
  3. @try {
  4.     sqlite3_open([databasePath UTF8String], &database);
  5.    
  6.     @try {
  7.         NSString *queryStatement = @"INSERT INTO People (ID_Organization, Name, EMail) VALUES (?, ?, ?);";
  8.        
  9.         sqlite3_prepare_v2(database, [queryStatement UTF8String], -1, &statement, NULL);
  10.        
  11.         @try {
  12.             sqlite3_bind_int(statement, aPerson.organizationID, 1);
  13.             sqlite3_bind_text(statement, 2, [aPerson.name UTF8String], -1, NULL);
  14.             sqlite3_bind_text(statement, 3, [aPerson.eMail UTF8String], -1, NULL);
  15.            
  16.             sqlite3_step(statement);
  17.            
  18.             NSLog(@"Person inserted.");
  19.             aPerson.ID = sqlite3_last_insert_rowid(database);
  20.             return TRUE;
  21.         }
  22.         @catch (NSException *exception) {
  23.             NSLog(@"%s", sqlite3_errmsg(database));
  24.             return FALSE;
  25.         }
  26.     }
  27.     @catch (NSException *exception) {
  28.         NSLog(@"%s", sqlite3_errmsg(database));
  29.         return FALSE;
  30.     }
  31.     @finally {
  32.         sqlite3_reset(statement);
  33.     }
  34. }
  35. @catch (NSException *exception) {
  36.     NSLog(@"%s", sqlite3_errmsg(database));
  37.     return FALSE;
  38. }
  39. @finally {
  40.     sqlite3_close(database);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment