Primary Author: KBK[Add a pointer to a list of existing drivers, as well as drivers in the process of being developed]LV Note that I notice that the digital signature listed at the web site says that it expired in Oct. Also, will the various TDBC drivers currently available soon be added to ActiveState's teapot repository? I don't see anything with the letters 'tdbc in it when I run teacup list. Or is it invisible because under Tcl 8.6 it comes as part of the package?See also :
Details at: http://tip.tcl.tk/308.html TCT Status: TIP status is now Final for Tcl 8.6 and code appears in the Tcl 8.6 cvs head. Primary site: http://tdbc.tcl.tk/
Examples
Opening a connection to a database
If you have installed the ODBC driver:package require tdbc::odbc
set connStr "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};"
append connStr DBQ= [file native [file normalize mydatabse.mdb]]
tdbc::odbc::connection create db $connStrOr:package require Tk
tdbc::odbc::connection create db {} -parent .
# prompt the user with the system dialogsAfter installing the SQLite3 driver (and sqlite software?):package require tdbc::sqlite3 tdbc::sqlite3::connection create db "/path/to/mydatabase.sqlite3"If you have a MySQL database, the driver (and perhaps the mysql software?) installed:
package require tdbc::mysql
tdbc::mysql::connection create db -user joe -passwd sesame \
-host 127.0.0.1 -database customersSimple Querying
set name "O'Hara"
db foreach {
SELECT firstname FROM customers WHERE surname = :name
} results {
puts "Found \"[dict get $results firstname]\" in the customers table"
}Discussion
LV 2008 Dec 02 So, what is the connection between TDBC and TclDBI? Was TclDBI an influencing design? Or is TclDBI just another example of an abstraction layer? Just curious about the motivation behind the reference.Also, where on the WWW is the work and discussion regarding TDBC occurring?NEM I don't know if TclDBI was an influence. Perhaps KBK could comment. Discussion of the TIP occurred on Tcl-Core and on a TDBC mailing list [1]. There is a site at http://tdbc.tcl.tk/ too. The TIP status is Accepted, but not yet Final, so is just waiting for integration into the Tcl code base, which I guess will happen some time before 8.6b1. The design looks very good to me, but I haven't been successful in building it as an extension. I don't know if anyone else has practical experience with it yet?KBK TclDBI, nstcl and tclodbc were all influences on the design. It also was compared with jdbc, Perl's DBI, odbc, and several native Tcl interfaces to specific databases (e.g., pgtcl, oratcl, mysqltcl, sqlite). Code was not borrowed directly from any of these, but ideas were lifted liberally.It's a design goal that it should be possible to write a driver in either C or Tcl.SRIV I'm partway done making a client/server tdbc interface. Im testing with Sqlite on the server side, accessing it through the tdbcsqlite3 package that KBK wrote. On the client, its a going to be a tdbc compliant package to interact with the server. So far its working very well.DKF: It might or might not be part of 8.6b1 (that's very soon). IIRC, it was heavily influenced by lots of things that have been done in tcl-and-databases world; KBK's used a great many of them so he knows which parts of those previous attempts sucked and which parts were necessary for production use.(Indeed, it did make 8.6b1. But you need an external driver; it was only core support modules that were in 8.6b1 itself.)KBK Drivers are available by downloading the latest tdbc.zip from http://tdbc.tcl.tk . There are also binaries for the Windows versions of the drivers in SourceForge's file release system at https://sourceforge.net/project/showfiles.php?group_id=10894&package_id=305160RS wonders on 2009-01-12 whether it might make sense to provide a pure-Tcl driver as last fallback solution as well, in the absence of all supported databases. This implementation could implement tables just as lists of lists in memory, and do commit/rollback by just writing/reading them to/from a plaintext file. Most work would probably have to go into an SQL parser there, of course...DKF: If someone supplies an implementation "driver", sure...JMN: I'm using the precompiled windows tdbc1.0b9 and tdbcodbc1.0b9 - and I'm getting a strange error with some MS Access MEMO fields. A nul character (\0) is appearing at exactly character position 255 within a field value in a '$resultset foreach row ..' loop. (resultset returned from a query ie: [db prepare "select * from $queryname"] execute] )I tried producing a simplified version of my program in order to submit a bug report - but couldn't reproduce it in the simple program :( It's got me beat as to where this nul is coming from.Just flagging it here for now in case someone has some debugging ideas etc..KBK Please log bugs at http://tdbc.tcl.tk/ . Go to Login in the heading bar, and log in as anonymous. Then go to Tickets in the heading bar and select New Ticket. The Detailed Description panel uses HTML markup; please mark up code samples like
<verbatim> # your code goes here </verbatim>and use the Preview button. (But don't worry too much if you don't get it quite right, we can go to the database and retrieve your unformatted text.I've taken the liberty of logging the bug referenced above but haven't had a chance to investigate it yet. It's most likely an off-by-one error when extending the buffer for returned strings. I'll have a look.
HaO - 2009-07-03 03:32:52I am interesting using TDBC on tcl 8.5. I have read about an "backport" somewhere. So I took the source distribution and compiled with MS-VC6:
- Generic package compiles out of the box with the makefile in win and TCLDIR macro set. sub library must be installed manually.
- For the odbc driver, there is no win makefile (of course mingw is present). I used a version from TDBC with the following modifications:
- Precompiler: -D inline=_inline -D USE_TCLOO_STUBS -D USE_TDBC_STUBS -D USE_TK_STUBS
- Additional include folders: tdbc\generic TclOO0.6\generic
- Additional libraries: odbc32.lib odbccp32.lib user32.lib "$(TCLDIR)\lib\tkstub85.lib" tdbcstub10.lib tclOOstub06.lib
