Created
September 18, 2011 02:30
-
-
Save igaiga/1224631 to your computer and use it in GitHub Desktop.
iOS sqlite select statement sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#import <sqlite3.h> | |
sqlite3* d = nil; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *path = [documentsDirectory stringByAppendingPathComponent: @"testdb.db"]; | |
if (sqlite3_open([path UTF8String], &d) != SQLITE_OK) { | |
// Even though the open failed, call close to properly clean up resources. | |
sqlite3_close(d); | |
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(d)); | |
// Additional error handling, as appropriate... | |
} | |
sqlite3_stmt *sqlstmt; | |
char *sql = "select * from CartaReadingSystemMaster;"; | |
int ret; | |
ret = sqlite3_prepare_v2(d, sql, -1, &sqlstmt, NULL); | |
if (ret == SQLITE_OK) { | |
NSLog(@"*** SQLITE_OK"); | |
if(SQLITE_ROW == sqlite3_step(sqlstmt)){ | |
NSLog(@"%s",sqlite3_column_text(sqlstmt,0)); | |
NSLog(@"%s",sqlite3_column_text(sqlstmt,1)); | |
NSLog(@"%s",sqlite3_column_text(sqlstmt,2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment