'''[http://www.xdobry.de/mysqltcl/%|%mysqltcl]''' is a simple interface to [MySQL] for [Tcl] ** Attributes ** current version: 3.052 release time: 2012-10 ** See Also ** [adb] ,by [Roalt Aalmoes]: a simple tcl database engine that uses mysqltcl underneath. ** Documentation ** [http://linuxfocus.org/English/March2004/article331.shtml%|%An introduction to the TclMySQL library] ,Diego Alberto Arias Prad ,2004-03: ** Description ** Tcl interface to [mysql] relational [database]. Supports Tcl 8 objects, unicode, nested queries, etc. Currently at version 3.05. ** Example ** [SS] 2005-02-12: I wrote this very short example of mysqltcl usage for a guy asking on the tclers chat about how to use it. I'll put it here to redirect to this page the next time people ask about it. This code connects to the mysql server at 'localhost', logs in with the username 'root', password 'foobar', selects the database 'mysql', and executes the query "SELECT HOST FROM USER". Every host returned is printed using [puts], and finally the mysql handle is closed. ====== package require mysqltcl set m [mysqlconnect -user root -db mysql -password foobar] mysqluse $m mysql foreach res [mysqlsel $m {select host from user} -flatlist] { puts $res } mysqlclose $m ====== [Artur Trzewik]: Some comments about example: `mysqluse $m mysql` is not needed in this case because the database is already specified as connection parameter. The fastest solution in mysqltcl for fetching data (bigger volumes) is '''mysqlmap'''. '''mysqlsel''' with '''-flatlist''' will build a Tcl-List with the whole result. For very big data-volumes the best choice is '''mysql::receive''', as that does not use client caching (on the level of mysqlclient C-library). Starting with version 3.00, you can also use namespace command names. ====== #using fetch mysql::sel $m {select host from user} while {[llength [set row [mysql::fetch $m]]]>0} { # row is always a list. using lindex avoids conversion list to string puts [lindex $row 0] } # the fastest way to operate data without building big internal Tcl lists. mysql::sel $m {select host from user} mysql::map $m host { puts $host } # for very big data volumes. No caching at all mysql::recieve $m {select host from user} host { puts $host } ====== [LV] 2007-09-10: So, is it really mysql::rec''ie''ve rather than mysql::rec''ei''ve ? ** Mysqltcl and [Starkit%|%Starkits] ** DrumBSD: I found this code on a mailing list which wraps mysqltcl for [Microsoft Windows] into a [starkit] or [starpack]. You have to modify pkg_Index.tcl like this: ====== proc loadmysqltcl { dir } { set oldcwd [pwd] cd $dir foreach file [glob *.dll] { file copy -force $file c:/winnt/temp } cd c:/winnt/temp load libmysqltcl[info sharedlibextension] cd $oldcwd } package ifneeded mysqltcl 3.01 [list loadmysqltcl $dir] ====== Anyway, there's a problem when "c:/winnt/temp" doesn't exists. So I tried to put a $tcl_platform(osVersion) into pkgIndex.tcl but it doesn't work. Maybe when it loads mysqltcl, the tcl_platform array doesn't exist. Any tips to solve this problem? [JH]: Did you make sure to declare tcl_platform global in the proc? [ramsan]: I think that all [Microsoft Windows] have defined the variable TEMP. So: ====== proc loadmysqltcl { dir } { set oldcwd [pwd] cd $dir foreach file [glob *.dll] { file copy -force $file $::env(TEMP) } cd $::env(TEMP) load libmysqltcl[info sharedlibextension] cd $oldcwd } package ifneeded mysqltcl 3.01 [list loadmysqltcl $dir] ====== ** Misc ** [crouzilles]: How do you use placeholders in mysqltcl? Can you do `{select * from mytable where name = ?}`? <> Package | Database | Library | SQL | MySQL