iphone开发中sqlite3常用操作
一使用原生库
1新建或插入
sqlite3 *db; if (sqlite3_open(@"xx.db", &db) != SQLITE_OK ) { return; } sqlite3_stmt *dbps; int dbrc; NSString *sql = @""; const char *sqlChar = [sql UTF8String]; dbrc = sqlite3_prepare_v2(db, sqlChar, -1, &dbps, NULL); dbrc = sqlite3_step(dbps); if(dbrc != SQLITE_DONE){ NSLog(@"exec sql error!,sql:%@,error code:%d.",sql,dbrc); } sqlite3_finalize(dbps); sqlite3_close(db);
2查询
sqlite3 *db; int dbrc; sqlite3_stmt *dbps; if (sqlite3_open(@"xx.db", &db) != SQLITE_OK ) { NSLog(@"couldnet't open db:"); return; } NSString *sql = @"select * from sqlite3_master "; const char *sqlChar = [sql UTF8String]; dbrc = sqlite3_prepare_v2 (db, sqlChar, -1, &dbps, NULL); while ((dbrc = sqlite3_step (dbps)) == SQLITE_ROW) { NSLog([[NSString alloc] initWithUTF8String:(char*) sqlite3_column_text(dbps, 0)]); } sqlite3_finalize(dbps); sqlite3_close(db);
二使用CSqliteDatabase
待续
相关推荐
liuxudong00 2020-11-19
章鱼之家 2020-10-29
leitingdulante 2020-10-21
xuegangic 2020-10-17
硬币0 2020-10-15
ZuoYanDeHuangHun 2020-09-18
chsoft 2020-09-17
MatrixHero 2020-08-20
XxZproject 2020-08-10
定格 2020-08-15
Mryiyi 2020-08-07
ydc0 2020-07-30
yechen00 2020-07-25
孝平 2020-07-18
ntfsformac 2020-06-23
好好学习天天 2020-06-12
Charliewolf 2020-06-05
MAC2007 2020-06-04
fanxiaoxuan 2020-06-03