mysqltcl - Tcl Mysql Interface (Version 3.05)

XOTclIDE - new life for Tcl.
  • interactive
  • introspective
  • object oriented
  • syntax checking
  • version control
Mysqltcl is a simple API for Mysql-Database and Tcl scripting language.

New Version mysqltcl 3.052 (10.2012)
mysqltcl was described in March LinuxFocus online magazine

New in Version 3.052

New in Version 3.051

New in Version 3.05

New in Version 3.04

New in Version 3.03

New in Version 3.02

New in Version 3.01

Complete Change Log


Encoding differences between 2.14 and after 2.20

Internal using of Tcl C-Api functions. For more information read Tcl C-Api manual
version-encoding valuewrite dataread data
2.14option encoding not existsTcl_UtfToExternal [encoding system]Tcl_NewByteArrayObj
2.20encoding not setTcl_UtfToExternal [encoding system]Tcl_ExternalToUtf [encoding system]
-encoding binaryTcl_GetByteArrayFromObjTcl_NewByteArrayObj
-encoding iso8859-1Tcl_UtfToExternal iso8859-1Tcl_ExternalToUtf iso8859-1

Downloads:

Windows Binary Version of mysqltcl with zip packed mysqltcl.
Release 3.05 (compiles with mysql 3, 4 and 5)

Release 2.51 (with new command mysqlreceive) Old archival packages

Additional Software

Documentation

man2html
Authors:

Thanks to Jean-Luc Fontaine http://jfontain.free.fr for some patches.
Thanks to Alexander Schoepe for initial patch for -encoding option support.

Please conntact by bugs reports, installing problems or if you want to develop next version. Bugs Reports (mail@xdobry.de)


Installation (for version 2.15)

Use this option to install mysqltcl under FreeBSD 5.0, tcl 8.3 and mysql 3.23.54. Thanks to Diego Alberto Arias Prado
export CPP=/usr/bin/cpp
./configure --with-tcl=/usr/local/lib/tcl8.3 --with-tclinclude=/usr/local/include/tcl8.3 --with-mysql-include=/usr/local/include/mysql --with-mysql-lib=/usr/local/lib/mysql

make

make install
Installing under OpenBSD 3.1. Thanks to Fredrick Leitz.
LDFLAGS="-I/usr/local/lib/mysql -I/usr/local/lib/tcl8.3"
CPPFLAGS="-I/usr/local/include/mysql -I/usr/local/include/tcl8.3/generic"
export LDFLAGS  CPPFLAGS
./configure
make
make install

Mac OS X

with gcc
./configure CC=gcc --with-mysql-include=/Library/MySQL/include/mysql --with-mysql-lib=/Library/MySQL/lib/mysql/
thanks to Justin Dewind

with fink

./configure --with-mysql-include=/sw/include/mysql --with-mysql-lib=/sw/lib/mysql --with-tcl=/sw/lib --with-tclinclude=/sw/include
thanks to eric lebel

FAQ and Pitfalls

Commands out of sync; You can't run this command now

This error happens when you have used mysqlexec command with SQL select command, that normally should return result set. The next mysql command (mysqlsel mysqlexec mysqlmap) causes that error. You can use mysqlexec only for (INSER, DELETE and UPDATA Sql commands). For SELECT command you should use mysqlsel mysqlquerry mysqlmap mysqreceive.

Segmentation fault by connecting mysql with version earlier than 3.23.50

The earlier version of mysql have had bug in mysql_option function that was fixed in 3.23.50 see mysql changes log News 3.23.50. This can happens to Debian user of very old and "very stable" release. If you do not want to upgrade your system, please use mysqltcl 2.50 or later or comment out the line mysql_options(handle->connection,MYSQL_READ_DEFAULT_GROUP,groupname); from mysqltcl.c file. Then the .my.cnf file will be not recognized.

How mysqltcl handles UNI-coded (UTF8) strings till version 2.14?

All sql statments are converted to external representation by using Tcl_UtfToExternalDString function before sending to database. This function use character set specified by [encoding system] variable. All data read from database are treated as byte array. (By using function Tcl_NewByteArrayObj). If you want to convert this data to your representation use tcl function [encoding convertto ?encoding? string].
In Version 2.20 another way was chosen please read manual section mysqlconnect option -encoding.

The compilation and installation was OK but I got the message: "couldn't load file "libmysqltcl2.12.so": libmysqltcl2.12.so: cannot open shared object file: No such file or directory"

mysqltcl is dynamical linked with libmysqlclient. If the libmysqlclient library is not in the dynamical library path mysqltcl could not be loaded. Try "ldd libmysqltcl2.12.so" to see all dependences.

ldd libmysqltcl2.12.so
   libmysqlclient.so.10 => /usr/local/mysql/lib/mysql/libmysqlclient.so.10 (0x40007000)
   libc.so.6 => /lib/libc.so.6 (0x40030000)
   libz.so.1 => /lib/libz.so.1 (0x40143000)
   libcrypt.so.1 => /lib/libcrypt.so.1 (0x40152000)
   libnsl.so.1 => /lib/libnsl.so.1 (0x40180000)
   libm.so.6 => /lib/libm.so.6 (0x40196000)
   /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
You can adapt LD_LIBRARY_PATH environment variable to the libmysqlclient library. You can also try to link libmysqlclient statical. You must adapt Makefile for it.
You can use option --enable-mysqlstatic in configure script for build mysql static linked with mysqlclient library.

I got also following message from sun user:
However, the correct fix is NOT to adjust LD_LIBRARY_PATH; see LDPATH for details of why that is a bad solution. Rather, one needs to adjust the configure options to embed the path to the required library in the referring library. On Solaris 11, I use this configuration line:

./configure LIBS=-R/opt/mysql/mysql/lib --with-mysql-include=/opt/mysql/mysql/include --with-mysql-lib=/opt/mysql/mysql/lib --enable-shared
--with-tcl=/opt/ActiveTcl-8.5/lib --with-tclinclude=/opt/ActiveTcl-8.5/include
and the LIBS setting does the right thing in that regard. Something similar is the right way to handle this problem under Linux, as well.

I get the message: "sh: syntax error at line 1: `;' unexpected" by make install

This problem was reported by Sun and Compaq Tru64 machines. It seems the shell on this machines have another syntax then linux shell. I have seen in news groups that problem also by another linux projects. To solve the problem you should set some magic environment variable to change compatibility behaviour of your shell. If someone has near information please mail me it. There are 2 important files that you can also copy manual.

/usr/lib/mysqltcl-2.11/libmysqltcl2.11.so
/usr/lib/mysqltcl-2.11/pkgIndex.tcl

I can not find tclmysqlsh (Tcl with mysqltcl shell) provided in earlier versions

You should use package mechanisms. It is more portable and the right way in Tcl.

package require mysqltcl 

I become some differences in encoding by receiving results from (mysqlsel $sql -list, mysqlsel $sql -flatlist, mysqlnext)

mysql $sql -list returns list of list. mysql $sql -flatlist returns a list. mysqlnext returns a list. Even if you retrieve one row and one column you becomes list structures. If you handle such results as string when tcl must convert the list to string. It is better to use lindex command to access directly the list elements (even then there are only one element) to avoid internal types converting. (Such converting can also change the encoding of the string elements)

set result [lindex [lindex [mysqlsel $handle "select blob from pictures where id=2" -list] 0] 0]
set result [lindex [mysqlsel $handle "select blob from pictures where id=2" -flatlist] 0]
mysqlsel $handle "select blob from pictures where id=2" 
set result [lindex [mysqlnext $handle] 0]
There are some problems by retrieving binary data from mysql by some installations.

By problems you should use.

mysqlconnect -encoding binary
Up from version 2.20 mysql use symetric read and write. That means you do not need to uses enocding converting. But consider if you write binary data to mysql they are converted to system encoding that means you write binary and they can be in mysql as utf-8. See exmaple in tests/binarytest.tcl.
In version to 2.14 you can use to get binary data read from database.
encoding convertfrom [encoding system] $sql_read_data
Problems by build static linked mysqltcl on Solaris; with option --enable-mysqlstatic

The configuration script with this option work good only for Linux. I have not found any way to make it machine independent.

Jean-Luc have reporterted an alternative manually way to static compile mysqltcl on Solaris 5.9

$ ld -G -o libmysqltcl2.40.so mysqltcl.o  /usr/local/mysql/lib/libmysqlclient.a -lz -lcrypt -lnsl -lm -L/home/mysql/tcltk/lib -ltclstub8.4 -lc -lsocket -ldl

Projects that use mysqltcl

If you use mysqltcl internal in your project and you do not fear to angry your business partner (this big software partner!) by talking about it, please report it me. I want to publish some users stories one this site. It will help another users to assess the stability and usability of mysqltcl and also Tcl and MYSQL. The interesting things were performance, development costs, comparitions to another systems. What is the mysqltcl using for in real life? (50-100 downloads a week) It will also help to improve future versions.

Another Tcl mysql Interfaces:


WEB-Master Artur Trzewik
Last modified: Tue Dec 28 14:29:30 CET 2004