如何使用ios的sqlitemanager建立数据库
1个回答
展开全部
步骤是:
先加入sqlite开发库libsqlite3.dylib,
新建或打开数据库,
创建数据表,
插入数据,
查询数据并打印
NSString *sqlQuery = @"SELECT * FROM PERSONINFO";
sqlite3_stmt * statement;
if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
char *name = (char*)sqlite3_column_text(statement, 1);
NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
int age = sqlite3_column_int(statement, 2);
char *address = (char*)sqlite3_column_text(statement, 3);
NSString *nsAddressStr = [[NSString alloc]initWithUTF8String:address];
NSLog(@"name:%@ age:%d address:%@",nsNameStr,age, nsAddressStr);
}
}
sqlite3_close(db);
先加入sqlite开发库libsqlite3.dylib,
新建或打开数据库,
创建数据表,
插入数据,
查询数据并打印
NSString *sqlQuery = @"SELECT * FROM PERSONINFO";
sqlite3_stmt * statement;
if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
char *name = (char*)sqlite3_column_text(statement, 1);
NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
int age = sqlite3_column_int(statement, 2);
char *address = (char*)sqlite3_column_text(statement, 3);
NSString *nsAddressStr = [[NSString alloc]initWithUTF8String:address];
NSLog(@"name:%@ age:%d address:%@",nsNameStr,age, nsAddressStr);
}
}
sqlite3_close(db);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询