Guest User

Untitled

a guest
Jan 14th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. -(void) readtheDB {
  2. // Open the database.
  3. if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
  4. NSString *updateQuery = [[NSString alloc] initWithFormat:@"SELECT * FROM people"];
  5. const char *query = [updateQuery UTF8String];
  6. [updateQuery release];
  7.  
  8. sqlite3_stmt *statement;
  9. int res = (sqlite3_prepare_v2( database, query, -1, &statement, NULL));
  10.  
  11. if(res == SQLITE_OK) {
  12. while(sqlite3_step(statement) == SQLITE_ROW) {
  13. // Read the data from the result row
  14. NSString *aUser = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
  15. NSString *aPass = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
  16. NSString *url = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
  17.  
  18. NSLog(aUser);
  19. NSLog(aPass);
  20. }
  21. sqlite3_finalize(statement);
  22. }else {
  23. NSLog(@"Failed to prepare read query with error code: %d", res);
  24. }
  25. }else {
  26. NSLog(@"Failed to open the database");
  27. }
  28.  
  29. sqlite3_close(database);
  30. }
Add Comment
Please, Sign In to add comment