October 5, 2007

A simple MySQL client in Tcl/Tk using mysqltcl

Yesterday, Ron Cripe emailed me asking if I knew of any simple examples of how to use Tcl/Tk with MySQL. I knew about mysqltcl and pointed him in that direction, but he said he needed an actual example on how to use it.

I've done a lot of Tcl programming but have mostly avoided doing GUI's with Tk, so I figured this might be a good opportunity to do some learning, myself. I quickly wrote a simple application that connects to a MySQL database, then lets you execute queries against it and displays the results. You can download it here:

It's named .txt to make it easier to download--just rename it to only .tcl (removing the .txt) once you've saved it.

When you start the app, it presents you with a simple login dialog:

mysqltcl-client login dialog

Enter your username and password, change the host, port and database values if necessary, and press Enter or click the Connect button. If all goes well, the login dialog will go away and the query window will appear:

mysqltcl-client query dialog

This is an example of what the query dialog looks like after executing a SHOW TABLES query. Very simple, not terribly exciting, but what do you want for a 5KB, 181-line Tcl script?

If you have Tcl, Tk and mysqltcl installed, go ahead and grab a copy of this script and check it out. If you have questions about the code, just ask: I'll try my best to answer them.

Tags: , , , ,

Posted by dossy at 12:19 AM | 529 | Link | Comments (3) | Trackbacks (0) | Bloglines | Feedster | Technorati | BlogPulse
Frederick's of Hollywood, Inc.


Comments
1
Gravatar Icon

Hi Dossy,

I feel so lucky to found this website..It sound interesting to me since I am also work on tcl and mysql (mysqtcl) and looking for this quite very long time. I have some problem with mysqltcl that I hope you can answer.

OK..let me explain, I want to access the mysql database from tcl code, so I have installed mysql5.0.4 and mysqltcl3.0.2 and I already have tcl8.3.2 installed with the linux package (i am using debian). My mysql and tcl is working fine. The problem now is I can't connect both of them using mysqltcl..I am using command "mysql::connect" but it returned "bash:command not found"..the installation was succesfull, but I dont have any idea why this happened. Actually I am totally new in mysqltcl, I just follow the command from the manual. So I want to ask you if u have any idea on how to connect them using mysqltcl..

Thanks in advance for you time and help!!

Posted by: newbie36 on October 26, 2007 at 06:47 AM | Permalink
2
Gravatar Icon

newbie36: Are you executing your Tcl script correctly? If you're getting a "bash: command not found" error, it doesn't sound like it. It sounds like you're trying to execute Tcl code from your shell prompt, not as a Tcl script.

I'll need more specific details (i.e., see exactly what you're doing) to really give you any help with this.

Posted by: Dossy on October 26, 2007 at 07:33 AM | Permalink
3
Gravatar Icon

Hi Dossy,

Really appreciate your quick response!..

Let me make you more clear. I need to store and retrieve some data into mysql database using tcl script, so I installed mysqltcl in order fo me to get access directly into the database from the tcl right?

Ok, actually, after installing mysqltcl, am I suppose to connect both of them via the mysqltcl shell prompt like I said in the previous post (::mysql::connect), or use the command in tcl scripts? I have tried to google on how to connect them both, but very much little info I get..when I type #mysqld_safe -u root mysql, it returned : " Cant connect to localhost through var/lib/mysqld/mysqld.sock" (and this file actually is not exist) even though I didn't installed it here.

And if I type #mysqld_safe, It will returned

"Starting mysqld daemon using var/lib/mysql, STARTED",

but then just a few second, it will stopped by displaying

"STOPPING the server using var/lib/mysql/ns2-box.pid" .

I tried to point to the correct library path by using --with-mysql-var=/path/to/mysql/data during configure, but I dont know why this error still came out (even I have changed the path).

Maybe this is not the correct way of connecting them (that's why I got those errors). Do i need to perform this command at mysqltcl shell prompt? or it should be applied in the tcl script itself? I really need to clarify this out since I have been stucked with this about a week!..I really hope you can help me in this and I really appreciate it!..

Sorry for my bad English, I hope you can understand.

Posted by: newbie36 on October 27, 2007 at 03:19 PM | Permalink
Post a comment

Who are you?

(what is this?)
(what is this?)
(what is this?)
(what is this?)


(required)
(required, not displayed)


Allowed markup: a href title, abbr title, acronym title, b, blockquote cite type, br, code, dd, dl, dt, em, i, li, ol, p, pre, strike, strong, tt, ul.

Please type in the letters shown in the image below:
Graphical CAPTCHA.

A preview of your comment:

Posted by: