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: , , , ,

Enough of the politics, on with the geeking!

Okay, I’m sorry I indulged myself the last few days with the spurt of political blogging. I’ve gotten it out of my system now. Time to get back to the hardcore geeking!

Here’s a short list of things that are either on my mind or somewhere in my to-do list:

  • Commit my changes to AOLserver to build easily with MinGW/MSYS on Win32. I even put together a quick NSIS script, so there’s a nice one-click installer for AOLserver 4.0.10 on Win32, now.
  • Commit my changes to Gnash to build and link correctly using MinGW/MSYS on Win32. No fancy installer, but here’s my previous blog post about it.
  • Do some more work on nsjsapi, the AOLserver module to integrate Mozilla SpiderMonkey into AOLserver for server-side JavaScript. I’d like to get it working well enough to load and use jQuery so I can show it off at jQueryCamp07 this October.
  • Work with the community to put together a list of “Top 5 Goals” for AOLserver, then assemble a real plan to get those things done. A big bonus would be if I didn’t have to do everything myself.
  • Find someone who wants to check out Gobby with me. It’s a free, open source, multi-platform, collaborative real-time file editing application with chat and syntax highlighting. Think: World of Notepad. Could be a nice way to do remote paired programming with two or more people. Or, a good way to do code reviews with a geographically distributed team.

If you’d like to hear more about any of these things–or better yet, do them together with me, let me know!

OTRS SQL query to show most recent ticket activity

 OTRS, the Open Ticket Request System, is a GPL’ed open source request tracking application. Here’s a screenshot of the Queue View:

OTRS Queue View screenshot
(click for full size)

This is fine if you’re a CSR managing your own queue of tickets, but when you’re monitoring the activity of everyone’s tickets, the Queue View doesn’t help you quickly identify which tickets have had activity.

Fortunately, the Admin interface has a Select Box link under the Misc heading which provides you an ad-hoc SQL query screen. I took a look at the database schema for OTRS, and came up with a query that lists new and open tickets sorted by most recent activity:

SELECT  q.name AS queue_name, t.tn, t.customer_id, t.title,
        a.id, a_t.name AS article_type_name, a.create_time, a.a_from
FROM    queue AS q, ticket AS t, article AS a, article_type AS a_t, (
            SELECT  _a.ticket_id, MAX(_a.create_time) AS create_time
            FROM    ticket AS _t, ticket_state AS _t_s, article AS _a
            WHERE   _t_s.name IN ('new', 'open')
            AND     _t.ticket_state_id = _t_s.id
            AND     _a.ticket_id = _t.id
            GROUP   BY _a.ticket_id
        ) a_max
WHERE   q.id = t.queue_id
AND     t.id = a_max.ticket_id
AND     a.create_time = a_max.create_time
AND     a_t.id = a.article_type_id
GROUP   BY t.id
ORDER   BY a.create_time DESC

Here’s a screenshot of what the query results look like (I’ve sanitized out sensitive information):

OTRS tickets with recent activity query screenshot
(click for full size)

The Select Box doesn’t display the column names as headings, but they are: Queue Name, Ticket#, Customer ID, Ticket Title, Article ID, Article Type, Article Create Time, Article From Header. The results are sorted in descending order by Article Create Time, so the most recently created articles appear at the top.

I can periodically refresh this page and execute the query to watch for new activity to pop up at the top of the list. This way, I can monitor activity and see new activity in a ticket, at a glance.

Do you use OTRS? Do you have any good tips or tricks that you’ve created? Share them with me in the comments below!

Tags: , ,

Unofficial Gnash 0.8.1 build for Win32

Back in July, I ranted about Flash and mentioned Gnash, the GNU Flash movie player. Since then, I’ve gotten into the source and have been working on producing Win32 builds Gnash. You can try these unofficial builds out, if you’re interested:

As of this moment, 0.8.1 is the latest release. Everything “works” although not very well (jittery sound, etc.) — it’s a great start, though.

To get started, just unzip the archive into your Program Files directory–the archive contains the files in a Gnash subdirectory. There’s no self-executing installer for Win32 yet, nor have I built the npgnash.dll browser plugin for Win32, either. I’ll work on those for a future release.

I just discovered that on Win32 in MSYS and/or Cygwin, executing fltk-gnash.exe with no arguments gives you program usage output but under WinXP’s cmd.exe, you get nothing. So, here’s the text you should have gotten from the 0.8.1 build:

Error: no input file was specified.

usage: gnash [options] movie_file.swf

Plays a SWF (Shockwave Flash) movie
options:

  -h, --help    Print this info.
  -s <factor>   Scale the movie up/down by the specified factor
  -c            Produce a core file instead of letting SDL trap it
  -d num        Number of milliseconds to delay in main loop
  -v            Be verbose; i.e. print log messages to stdout
  -va           Be verbose about movie Actions
  -vp           Be verbose about parsing the movie
  -m <bias>     Specify the texture LOD bias (float, default is -1.0)
  -x <id>       X11 Window ID for display
  -w            Produce the disk based debug log
  -j <width>   Set window width
  -k <height>   Set window height
  -1            Play once; exit when/if movie reaches the last frame
  -g            Turn on the Flash debugger
  -r <0|1|2|3>
                0 disables both rendering & sound (good for batch tests)
                1 enables rendering & disables sound
                2 enables sound & disables rendering
                3 enables both rendering & sound (default)
  -t <sec>      Timeout and exit after the specified number of seconds
  -b <bits>     Bit depth of output window (16 or 32, default is 16)
  -u <url>      Set "real" url of the movie
                (useful for downloaded movies)
  -U <url>      Set "base" url for this run
                (used to resolve relative urls, defaults to movie url)
  -P <param>    Set parameter (ie. "FlashVars=A=1&b=2")
  -V, --version Print gnash's version number and exit

keys:
  CTRL-Q, CTRL-W, ESC   Quit/Exit
  CTRL-P          Toggle Pause
  CTRL-R          Restart the movie
  CTRL-[ or kp-   Step back one frame
  CTRL-] or kp+   Step forward one frame
  CTRL-B          Toggle background color

Feel free to give the 0.8.1 binaries a try–I’d love to hear how it works for you.

Tags: , , ,