Reputation: 33
I am writing a C++ application that embeds TCL and for its database operations I am also embedding SQLite in it. I would like to be able to do the following:
I would appreciate suggestions.
Upvotes: 1
Views: 272
Reputation: 137567
Tcl 8.6 should ship with a build of the SQLite interface, the sqlite3
package. However, there's no (official) way to share a database connection from the package with your C++ code; there's simply no API in the package that you can call from C++ to get the connection. The official workaround is to create another connection from your C++ code and that shouldn't be too onerous unless you're doing weird mixing of things between queries in the two language bindings, a very much not normal use case.
You can hack it by using Tcl_GetCommandInfo()
to retrieve, among other things, the Tcl database handle command's ClientData
field. That can then be cast to a pointer to a structure whose first field is a sqlite3*
handle, much as you'd obtain with sqlite3_open()
. Which is messy and fragile. Also, you'd still need to respect the usual rules, such as needing to keep to a single thread. This really isn't what I'd recommend!
Upvotes: 1