Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Sqlite3_column_text()

if sqlite3_prepare_v2(db, "select a from aaa", -1, &q,nil) == SQLITE_OK {
    while sqlite3_step(q) == SQLITE_ROW {
        let res = sqlite3_column_text(q, 1)
        print(res)
    }
} else {
    print("NOT WORKING")
    NSLog("%s", sqlite3_errmsg(db))
}

In my table aaa I have a field named 'a' and values 1,2,3 as shown here :

enter image description here

I'm trying to put the values in an array or just print them, but when I print (print(res)), the values are just "nil".

How can I get the real values?

EDIT: the values (1,2,3) are strings and not intagers, that why i chose sqlite3_column_text() and not sqlite3_column_int()

like image 203
Help Pleasee Avatar asked Oct 17 '25 15:10

Help Pleasee


1 Answers

SOLVED:

the problem was to convert the function sqlite3_column_text() to string and the solution in swift3 is:

let string = String(cString: sqlite3_column_text(statement, 0))
like image 198
Help Pleasee Avatar answered Oct 20 '25 07:10

Help Pleasee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!