使用Sqlite3命令创建数据库及表过程,可以参见:http://www.cnblogs.com/frankliiu-java/archive/2010/05/18/1738144.html
sqlite3* db;
NSString *documentsPaths=[[NSBundle mainBundle]bundlePath];
NSLog(@"%@", documentsPaths);///Users/weizhiqiangzz/Library/Application Support/iPhone Simulator/6.0/Applications/D656D8E6-9F81-4D73-A33E-C641220EDF7B/SSShow.app
NSString *databaseFilePath=[documentsPaths stringByAppendingPathComponent:@"./Database/login.db"];
if (sqlite3_open([databaseFilePath UTF8String], &db)!=SQLITE_OK)
{
NSLog(@"打开数据库失败");
sqlite3_close(db);
return ;
}
const char *selectSql="select userName, password from user";
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(db, selectSql, -1, &statement, nil) == SQLITE_OK)
{
NSLog(@"select ok");
while(sqlite3_step(statement) == SQLITE_ROW)
{
NSString *name = [[NSString alloc]initWithCString:(char*)sqlite3_column_text(statement, 0) encoding:NSUTF8StringEncoding];
NSLog(@"row name %@", name);
}
}
else
{
NSLog(@"fail to execute [sqlite3_prepare_v2]");
}
sqlite3_finalize(statement);