Guest User

Untitled

a guest
May 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. -(UIImage *) getPointImage:(NSString *)pointName
  2. {
  3. UIImage *retImg;
  4. const char *sql = "SELECT image from Image where name=?";
  5.  
  6. sqlite3_stmt *statement;
  7. // Preparing a statement compiles the SQL query into a byte-code program in the SQLite library.
  8. // The third parameter is either the length of the SQL string or -1 to read up to the first null terminator.
  9. int result = sqlite3_prepare(imgDatabase, sql, -1, &statement, NULL);
  10.  
  11. if (result == SQLITE_OK)
  12. {
  13. //fill in the name of the point we are looking for
  14. sqlite3_bind_text(statement, 1, [pointName UTF8String], -1, SQLITE_TRANSIENT);
  15. // We "step" through the results - once for each row.
  16. while (sqlite3_step(statement) == SQLITE_ROW)
  17. {
  18.  
  19. int dataSize = sqlite3_column_bytes(statement, 0);
  20. NSMutableData *data = [NSMutableData dataWithLength:dataSize];
  21. memcpy([data mutableBytes], sqlite3_column_blob(statement, 0), dataSize);
  22. retImg = [[UIImage alloc] initWithData:data];
  23. }
  24. }
  25. // "Finalize" the statement - releases the resources associated with
  26. //the statement.
  27. sqlite3_finalize(statement);
  28. return retImg;
  29.  
  30. }
Add Comment
Please, Sign In to add comment