On Mar 28, 2008, at 4:35 PM, Noah Hart wrote:
> A general question for the TCL experts....
>
> There is no problem, I'm just trying to understand how TCL works.
>
> In tester.tcl,v 1.79, at line 60, there is the following section:
>
> # Create a test database
> #
> catch {db close}
> file delete -force test.db
> file delete -force test.db-journal
> sqlite3 db ./test.db
> set ::DB [sqlite3_connection_pointer db]
>
> My question is: Why is the last line not "set ::DB db"
>
> What does sqlite3_connection_pointer do?
> Since this is not a tcl verb, or defined by sqlite3, where does this
> get
> defined?
>
There are countless new TCL verbs implemented in C code and found
in SQLite source files whose names begin with "test". The
sqlite3_connection_pointer verb is but one of many.
(BTW, in TCL lingo, one would normally call this a "command" not a
"verb". But if you are more comfortable with "verb", that terminology
works for me too.)
The sqlite3_connection_pointer verb is an anachronism. The various
new TCL verbs that interface to SQLite (example: sqlite3_prepare,
sqlite3_steo, etc.) often require a database connection as a parameter.
Originally, the implementations of these commands required that the
parameter be the hexadecimal representation of the actually sqlite3*
pointer. But when you use the "sqlite3" command to open a database
connection, you get back a TCL object, not a pointer. The
sqlite3_connection_pointer verb would translate the TCL database
object into the appropriate pointer.
The statement:
set ::DB [sqlite3_connection_pointer db]
translates the TCL database object "db" into a hexadecimal pointer
value and stores that value in the global variable "DB". Subsequent
commands in the same script would then use the value as "$::DB".
This is all an anachronism because at this point, most of the other
TCL commands have been upgraded and can accept the TCL database
object directly. So instead of saying:
sqlite3_prepare $::DB ...
we can now say:
sqlite3_prepare db ...
which is much more convenient. However, the test scripts have been
generated incrementally over the past 8 years and most of them have not
been upgraded to take advantage of the new syntax. So there are still
many calls to [sqlite3_connection_pointer] and uses of $::DB even though
they are not needed.
D. Richard Hipp
[EMAIL PROTECTED]
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users