0

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

这里 CreateTable 查询语句:-

“创建表如果不存在 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 NULL,phone TEXT DEFAULT NULL,型号 TEXT DEFAULT NULL,联系 TEXT DEFAULT NULL,类别 TEXT DEFAULT NULL,禁用 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, -1, SQLITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery, 3, (uniqueid as NSString).utf8String, -1, SQLITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery, 4, (currentTime as NSString).utf8String, -1, SQLITE_TRANSIENT)
        sqlite3_bind_int(insertStatementQuery, 5, Int32(0))
        sqlite3_bind_int(insertStatementQuery, 6, Int32(0))
        sqlite3_bind_text(insertStatementQuery, 7, nil, -1, SQLITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery, 8, (phoneno as NSString).utf8String, -1, SQLITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery, 9, nil, -1, SQLITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery, 10, nil, -1, SQLITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery, 11, nil, -1, SQLITE_TRANSIENT)
        sqlite3_bind_text(insertStatementQuery, 12, "0", -1, 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)
4

0 回答 0