如何在Swift中使用SQLite中的一行填充字典?

时间:2019-06-01 05:21:12

标签: swift sqlite

{'col1':value1,'col2':value2,'col3':value3等}

在下面的代码中,如何存储整行值并将其存储在字典中?

    let queryStatementString = "SELECT * FROM TABLE WHERE val = ?;" 
    var queryStatement: OpaquePointer? = nil

    if sqlite3_prepare_v2(db, queryStatementString, -1, &queryStatement, nil) == SQLITE_OK {
        sqlite3_bind_text(queryStatement, 1, variable, -1, nil)

        while (sqlite3_step(queryStatement) == SQLITE_ROW) {
            let id = sqlite3_column_int(queryStatement, 0)
            let queryResultCol1 = sqlite3_column_text(queryStatement, 1)
            let queryResultCol2 = sqlite3_column_text(queryStatement, 0)

            let name = String(cString: queryResultCol1!            }
    }
    else {
        print("SELECT statement could not be prepared")
    }

    sqlite3_finalize(queryStatement)

0 个答案:

没有答案