Simon Slavin wrote: 

> How do you pass the handle from your C code to your Tcl code ?  

I don't.  I pass it from Tcl to C.  

The handle in Tcl is a command name registered with the interpreter.  
SQLite attaches a structure to the registration that contains the 
underlying handle as used by the C API.  

I'm writing a Tcl extension in C and I don't want to touch a bunch of 
Tcl code.  The Tcl caller gives me its command-name handle to the DB.  
I ask the Tcl core for the registration data for that command name, and 
use it to get the underlying SQLite handle for my C calls.  

(Checking whether I've got a real Tcl db handle is not 100% fool proof, 
but takes care of basic caller stupidity and is good enough for my 
app.)  

With error checks removed:

    Tcl_CmdInfo cmdInfo;
    const char* zDbHandle = Tcl_GetStringFromObj(objv[2], 0);
    Tcl_GetCommandInfo(pInterp, zDbHandle, &cmdInfo);
    sqlite3 *pDb = *((sqlite3**)cmdInfo.objClientData);
    /* Carry on, using pDb in C API calls.
    */

I was considering asking about this a while ago on this group, but opted 
not to for fear of being publicly flogged by drh. :)

Actually, I was hoping the SQLite devs would promise not to change the
way they do Tcl command registration in future releases, so this kind 
of thing will continue to work.

> You are sharing the same connection to the database between the two 
> languages, right ?  

Yep.  

> You're not doing your INSERTs from one connection and your COMMITs from 
> another ?  

Right, the one connection is shared.  

Eric 

-- 
Eric A. Smith

Substitute "damn" every time you're inclined to write "very"; your
editor will delete it and the writing will be just as it should be.
    -- Mark Twain
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to