1

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:

  1. Write TCL scripts for the embedded SQLite from the embedded TCL interpeter.
  2. Pass an SQLite connection from the embedded TCL interpreter to C++ and use it in C++ for db operations, as well as the other way around.

I would appreciate suggestions.

3
  • Do people still use TCL? Also, the question is way to broad. It's effectively your wish list only. Commented Oct 10, 2017 at 8:51
  • 1
    SQLite's own test suite is partly written in Tcl. See wiki.tcl.tk/2633 for some info on Tcl/SQLite integration. Commented Oct 10, 2017 at 9:01
  • Thanks @Colin, but I couldn't find any info on the page that could help me. Commented Oct 10, 2017 at 17:35

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

1 Comment

many thanks for your answer. Since I want to embed TCL, my intent is to include only the TCL core code and SQLite code in my project and build then into one exec file. This way I can use SQLite in my C++ code as well as in TCL. Is this achievable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.