From: Kevin K. <kk...@ny...> - 2009-02-10 15:40:45
|
Patrick Dunnigan wrote: > Hi, I have read tip 308 and various other web pages but can’t seem to > find any comprehensive documentation on the use of TDBC and the small > bits of example code that I have found seem to be conflicting. I can > help with the testing effort but need some information on how to use > TDBC in my scripts. Unfortunately, there isn't very much tutorial information out there. The manual pages *are* there, and if you install drivers (which you have to do to actually *use* tdbc) their manual pages will be there, too. 308 didn't change very much between TIP and implementation, but I agree that TIP prose isn't the easiest thing in the world to read. How far have you got? I don't think that an email thread is the best place to start developing a tutorial, but perhaps we can Wikify the missing knowledge and whack it into a decent form. That will be easiest to do starting from specific questions. In any case, if you haven't already, you need to: (a) Either have 8.6b1 (or later), or else have 8.5 plus the tcloo extension and the tdbc extension. (b) Have a SQL database that you can use. Windows users always have Jet (the engine underlying Microsoft Access) available, even if they haven't bought Access. SQLite runs everywhere. And TDBC has a MySQL driver. (c) Have the driver for the database. Windows users can get binaries for the drivers that are so far available (ODBC, MySQL and SQLite3) from http://preview.tinyurl.com/db2zw8 Unix users at this point still have to build from source. Source ZIPs are available from http://tdbc.tcl.tk/ (d) Once you have a driver built and operational, or if you get stuck, start asking questions! There isn't that much there, but I've probably neglected to document some key piece that's making you stumble. A summary example will give the basic idea: tdbc::sqlite3::connection create db /path/to/my/database.sql db allrows { CREATE TABLE people( name VARCHAR(40), phone VARCHAR(16) ) } set stmt [db prepare { INSERT INTO people(name, phone) VALUES(:name, :phone) }] foreach {name phone} { fred 555-1234 barney 555-1235 wilma 555-1234 betty 555-1235 } { $stmt allrows } $db foreach row {SELECT phone FROM people where NAME='fred'} { if {[dict exists $row phone]} { puts $phone } else { puts "fred has no phone" } } $db close |