Advertisement
wkerswell

Sqlite get name.

Oct 18th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(NSMutableArray *)getCatNames{
  2.     //select sponser details
  3.  
  4.     //create sql string
  5.     NSString *sql = [NSString stringWithFormat:@"SELECT name FROM categories;"];
  6.    
  7.     //create sql statement
  8.     sqlite3_stmt *statment;
  9.    
  10.     //create array to sti0re all the entires in.
  11.     NSMutableArray *sponsors =[[NSMutableArray alloc]init ];
  12.    
  13.     //check to make sure statement runs ok
  14.     if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &statment, nil) == SQLITE_OK) {
  15.        
  16.         //foreach row
  17.         while (sqlite3_step(statment)==SQLITE_ROW) {
  18.            
  19.                 //get the column text
  20.                 char *field = (char *) sqlite3_column_text(statment, 0);
  21.                 //assign the text to a string
  22.                 NSString *strField = [[NSString alloc]initWithUTF8String:field];
  23.                 //add each field string to the array
  24.                 [sponsors addObject:strField];
  25.  
  26.             }
  27.            
  28.  
  29.     }
  30.     NSLog(@"sponsors array: %@",sponsors);
  31.     return sponsors;
  32.    
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement