zoukankan      html  css  js  c++  java
  • 数据类型的处理(提取自FMDB)

    if ((!obj) || ((NSNull *)obj == [NSNull null])) {

            sqlite3_bind_null(pStmt, idx);

        }

        

        // FIXME - someday check the return codes on these binds.

        else if ([obj isKindOfClass:[NSData class]]) {

            const void *bytes = [obj bytes];

            if (!bytes) {

                // it's an empty NSData object, aka [NSData data].

                // Don't pass a NULL pointer, or sqlite will bind a SQL null instead of a blob.

                bytes = "";

            }

            sqlite3_bind_blob(pStmt, idx, bytes, (int)[obj length], SQLITE_STATIC);

        }

        else if ([obj isKindOfClass:[NSDate class]]) {

            if (self.hasDateFormatter)

                sqlite3_bind_text(pStmt, idx, [[self stringFromDate:obj] UTF8String], -1, SQLITE_STATIC);

            else

                sqlite3_bind_double(pStmt, idx, [obj timeIntervalSince1970]);

        }

        else if ([obj isKindOfClass:[NSNumber class]]) {

            

            if (strcmp([obj objCType], @encode(BOOL)) == 0) {

                sqlite3_bind_int(pStmt, idx, ([obj boolValue] ? 1 : 0));

            }

            else if (strcmp([obj objCType], @encode(int)) == 0) {

                sqlite3_bind_int64(pStmt, idx, [obj longValue]);

            }

            else if (strcmp([obj objCType], @encode(long)) == 0) {

                sqlite3_bind_int64(pStmt, idx, [obj longValue]);

            }

            else if (strcmp([obj objCType], @encode(long long)) == 0) {

                sqlite3_bind_int64(pStmt, idx, [obj longLongValue]);

            }

            else if (strcmp([obj objCType], @encode(unsigned long long)) == 0) {

                sqlite3_bind_int64(pStmt, idx, (longlong)[obj unsignedLongLongValue]);

            }

            else if (strcmp([obj objCType], @encode(float)) == 0) {

                sqlite3_bind_double(pStmt, idx, [obj floatValue]);

            }

            else if (strcmp([obj objCType], @encode(double)) == 0) {

                sqlite3_bind_double(pStmt, idx, [obj doubleValue]);

            }

            else {

                sqlite3_bind_text(pStmt, idx, [[obj description] UTF8String], -1, SQLITE_STATIC);

            }

        }

        else {

            sqlite3_bind_text(pStmt, idx, [[obj description] UTF8String], -1, SQLITE_STATIC);

        }

  • 相关阅读:
    微信小程序 组件事件传递
    vue 项目引入字体报错
    vue 单文件 样式写了scoped 不能覆盖框架原有样式的解决办法
    react 动态获取数据
    百度地图marker点击任意一个当前的变化,其余的marker不变
    对象字面量中可以使用中括号作为属性,表示属性也能是一个变量
    二维数组转化为一维数组 contact 与apply 的结合
    一个对象如何复制给另一个对象,互不影响
    在-for 循环里面如何利用ref 操作dom
    mac 进程管理
  • 原文地址:https://www.cnblogs.com/liyufeng2013/p/3421618.html
Copyright © 2011-2022 走看看