SQLite Forum

string concatenation issue in prepared statement
Login
For anyone stumbling upon this thread. It seems that the bug came from using buffer.count which in swift returns the total number of bytes (including the \\0 character)

whereas by reading the doc, it seems that sqlite3_bind_text expects the number of bytes of the "value" (so, i assume, excluding the \0 character in the end).

It probably lead to having the null termination included in the resulting sql expression, and thus terminating the final string before its real end.

In the end, code that works is 

```swift
"B".utf8CString.withUnsafeBufferPointer { (buffer) -> Int32 in
            return sqlite3_bind_text(
                statement,
                1,
                buffer.baseAddress,
                Int32(buffer.count - 1),
                unsafeBitCast(-1, to: sqlite3_destructor_type.self)
            )
        }
```