iOS Sqlite3

      * 数据库操作要添加  libsqlite3.dylib  静态库
      * 包含头文件: import "sqlite3.h"
sqlite的方法
      * 1、sqlite3        *db,数据库句柄,跟文件句柄FILE很类似
      * 2、sqlite3_stmt   *stmt,这个相当于ODBC的Command对象,用于保存编译好的SQL语句
      * 3、sqlite3_open() 打开数据库,没有数据库时创建
      * 4、sqlite3_exec() 执行非查询的sql语句
      * 5、Sqlite3_step() 在调用sqlite3_prepare后,使用这个函数在记录集中移动
      * 6、sqlite3_close()关闭数据库
      *
      * 还有一系列用于从记录集字段中获取数据,e.g
      * 1、sqlite3_column_text()  取text类型的数据
      * 2、sqlite3_column_blob()  取blob类型数据

      * 3、sqlite3_column_int()   取int类型数据

// 邦定第一个int参数
sqlite3_bind_int(stmt, 1, 1);
// 邦定第二个字符串参数
sqlite3_bind_text(stmt, 2, [title UTF8String], -1, SQLITE_TRANSIENT);


完整的流程代码

NSString *sql = [NSString stringWithFormat:@"select NAME from education where ID = %d", index];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(dictDatabase, [sql UTF8String], -1, &statement, nil) != SQLITE_OK) {
sqlite3_close(dictDatabase);
} else {
if (sqlite3_step(statement) == SQLITE_ROW) {
char *cResult = (char *)sqlite3_column_text(statement, 0);
if (cResult) {
result = [NSString stringWithUTF8String:cResult];
}
}
}

    sqlite3_finalize(statement);

相关查询语句

NSString *sql = [NSString stringWithFormat:@"select NAME from education where ID = %d", index];
    NSString *sql = [NSString stringWithFormat:@"select BIG_ID from vocation where id = %d",index] ;
   NSString *sql = @"select DISTINCT BIG_NAME ,BIG_ID from vocation ORDER BY BIG_ID";
        sql = [NSString stringWithFormat:@"select BIG_NAME from vocation where BIG_ID = %d", index];
        sql = [NSString stringWithFormat:@"select ICONURL from vocation where ID = %d",index];
NSString *sql = @"select count(ID) from education";
NSString *sql = @"select count(DISTINCT BIG_ID) from vocation";
NSString *sql = @"select NAME from province order by ID asc";
NSString *sql = [NSString stringWithFormat:@"select ID from city where NAME like '%@\%%' and PRO_ID = %d", cityName, provinceId];
    NSString *sqlStr = @"select icon, name from emotions where type = ? order by icon asc;";



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值