SQLite Forum

Passing variable to SQLite3 fields
Login
> This does not work

It cannot possibly work: there's no way for that code to associate the contents of the string with specific variables.

Firstly, to bind values to a statement, you want the "bind" APIs:

<https://www.sqlite.org/c3ref/bind_blob.html>

Secondly, your code demonstrates a serious misuse of the API: you are opening the db on each call to your function and only closing it if the insert fails. That will end up producing a *major* memory leak. Opening it on each call is tremendously inefficient unless it's only called once during the life of the app. Each time a db is opened, it must eventually be closed, which is not happening in your code.