FastBase MySQL + Tcl Interface Program
|
Summary
This Tcl extension provides access to MySQL database servers using simple Tcl commands.
I wrote this extension because my main Tcl application (fully integrated accounting system) was requiring
more flexibility than the current extensions allowed, I also wanted to increase performance (I had
too many wrapper programs for performing basic queries).
Documentation
The documentation is provided here (right click to download).
Here is a sample piece of code using fbsql:
# load the fbsql package and connect to a database
load fbsql.dll
sql connect 192.168.3.8 root ""
sql selectdb test
# retrieve a result set as a list of records, each list is a sub-list of all fields
set data [sql "SELECT BRANCH_ID, NAME FROM BRANCH ORDER BY NAME"]
# process a result set, one record at a time - method #1
foreach row [sql "SELECT BRANCH_ID, NAME FROM BRANCH ORDER BY NAME"] {
set id [lindex $row 0]
set name [lindex $row 1]
puts "id = $id, name = $name"
}
# process a result set, one record at a time - method #1
sql startquery "SELECT BRANCH_ID, NAME FROM BRANCH ORDER BY NAME" -array branch
while {[sql fetchrow] != ""} {
puts "id = $branch(BRANCH_ID), name = $branch(NAME)"
}
sql endquery
Notes
The main differences with this extension and the others can be summarised as follows;
- fbsql.dll does not leak memory like the other programs have done (mytcl, tcl-sql).
- fbsql takes care of the database handlers in a different way making programming easier - see the documentation.
- fbsql provides the facility for executing very large queries (without using much memory).
- fbsql can retrieve entire result sets with one command.
- fbsql can retrieve individual records and store the result in easy to use arrays.
- The entire fbsql.c program is in one "C" source file for easy reading and understanding.
Download
Download the source or DLL files as required. (you may need to right click to save the files)
- fbsql.c (21k), this file should also compile on Unix platforms with some minor modifications.
- fbsql.dll (26k), this DLL is built with stubs and should work on all Tcl 8.x versions.
- libmysql.dll (210k), this DLL is also required, download if you don't have it already. Copy it to same directory as fbsql.dll.
- Makefile, use this makefile for building on Unix platforms, see Build notes below.
- fbsql_solaris.tar.gz, download this for Solaris 8, includes source, makefile & compiled
binary.
Note: You may need to manually edit the Solaris Makefile.
Note: Don't forget to enhance your LD_LIBRARY_PATH with mysql-lib-home before testing.
Note: This file was provided by bossung@danet.de.
Build Notes
Windows
See readme.txt, this file contains build information for windows/mingw. Provided by Eckhard Arnold.
Unix
Create a new directory and save fbsql.c & Makefile. Typing make should be enough.
The above will work but assumes that you have already installed the mysql development libraries and that the files will
be found in the include & lib directories specified in the Makefile - you may need to manually edit this for your purposes.
Once you have built fbsql.so you can include it in your tcl programs via load ./fbsql.so
.
Author
Written by Peter Campbell for the FastBase Development Company Ltd.
License
Copyright (c) 2003, Peter Campbell Software Ltd.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Peter Campbell Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History
- 1.06 released 17th June 2003 (sorry same version no.)
- The library has now been built using the stubs library so should work with different Tcl versions.
- 1.06 released 20th November 2002
- Modified the "sql connect" command, adding database_name and port to the end of the available options. See documentation for example.
- 1.05 released 12th April 2001
- Modified the source code to build on Unix platforms without modification.
- Included a "Makefile" for building on Unix platforms.
- Note: the version number on the DLL files has not been updated.
- 1.04 released 14th March 2001
- Added support for UTF encoding for extended character set support (provided by Mats Peterson, mats_peterson@swipnet.se).
This has not been tested by myself.
Note: The compiled DLL does not support this by default, you need to edit the source code and maintain the
line reading #define UTF_ENCODING 0
(change this to 1), then re-compile (or see the download link above).
- 1.03 released 16th October 2000
- Added checking in the system for connection and query status to ensure that commands are not executed out of
sequence. This includes starting a query and trying to perform another one with the same connection command.
- 1.02 released 6th October 2000
- Fixed bug when using the -array option for queries that had traces or linked variables (-textvariable), the system
was returning from the query prematurely because the return value from "sql fetchrow" was null.
- 1.01 released 28th September 2000
- Fixed bug when using the extra sql comamnds (sql1-sql5) causing exception faults.
- 1.00 released 27th September 2000