Reputation: 409
I'm trying to get the names of parameters but something is going wrong.
Code: (minimal code to re-produce the problem)
var db: OpaquePointer? = nil
var rc: Int32 = 0
rc = sqlite3_open("test.db", &self.db)
if rc != SQLITE_OK
{
print("cant open")
}
var statement: OpaquePointer? = nil
let sql = "insert into testtable values(?123);"
rc = sqlite3_prepare_v2(db, sql, -1, &statement, nil)
if rc != SQLITE_OK
{
print("cant prepare")
}
print(String(cString: sqlite3_bind_parameter_name(statement, 1))) // returns nil
sqlite3_finalize(statement)
sqlite3_close(db)
I get parameter names if I use @AAA
, :AAA
, $AAA
but I get nil
if I use ?123
( ?NNN
format). But according to website I should get ?123
as String
.
What am I doing wrong?
Thank you.
Upvotes: 0
Views: 469
Reputation: 318794
When you specify ?123
, the 123
is the index. So you need to pass 123
, not 1
, to the call to sqlite3_bind_parameter_name
.
You can see more in the documentation for the sqlite3_bind_xxx
functions.
Upvotes: 2