SQLite 查询语句插入在 swift 中无法正常工作

问题描述

我正在调用一个插入查询语句,以便在 sqlite 文件的 tc_devices 中插入数据。但在 XCode 中,我在控制台中得到输出:无法插入行。

这里是 CreateTable 查询语句:-

"CREATE TABLE IF NOT EXISTS tc_devices (id INTEGER NOT NULL UNIQUE,name TEXT NOT NULL UNIQUE,uniqueid TEXT NOT NULL,lastupdate DATETIME DEFAULT NULL,positionid INTEGER DEFAULT NULL,groupid INTEGER DEFAULT NULL,attributes TEXT DEFAULT TEXT DEFAULT NULL,model TEXT DEFAULT NULL,contact TEXT DEFAULT NULL,category TEXT DEFAULT NULL,disabled BLOB DEFAULT '0');"

    let db = connectDatabase(fileName: "Contact.sqlite")
    let sqlITE_TRANSIENT = unsafeBitCast(-1,to: sqlite3_destructor_type.self)

    let insertStatementString = "INSERT INTO tc_devices (id,name,uniqueid,lastupdate,positionid,groupid,attributes,phone,model,contact,category,disabled) VALUES (?,?,?);"
    //        var insertStatementQuery: OpaquePointer?
    var insertStatementQuery: OpaquePointer? = nil
    
    let uniqueid = Utility.getUDID()
    let phoneno =  UserDefaults.standard.object(forKey: "UserMobileNo") as! String
    
    if(sqlite3_prepare_v2(db,insertStatementString,-1,&insertStatementQuery,nil)) == sqlITE_OK{
        
        sqlite3_bind_int(insertStatementQuery,1,Int32(devideId))
        sqlite3_bind_text(insertStatementQuery,2,(name as Nsstring).utf8String,sqlITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery,3,(uniqueid as Nsstring).utf8String,4,(currentTime as Nsstring).utf8String,sqlITE_TRANSIENT)
        sqlite3_bind_int(insertStatementQuery,5,Int32(0))
        sqlite3_bind_int(insertStatementQuery,6,Int32(0))
        sqlite3_bind_text(insertStatementQuery,7,nil,8,(phoneno as Nsstring).utf8String,9,10,11,12,"0",sqlITE_TRANSIENT)
        
        if sqlite3_step(insertStatementQuery) == sqlITE_DONE {
            print("Successfully inserted row.")
        } else {
            print("Could not insert row.")
        }
    } else {
        print("INSERT statement Could not be prepared.")
    }
    sqlite3_finalize(insertStatementQuery)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...