Component xdobry::sql

XOSql base component

currently supported base interfaces: mysqltcl, postgres, odbctcl and dbitotcl.

Base Usage Example
1) Connecting mysql
set obj [Sqlinterface loadInterface mysqltcl]
$obj connect {user root dbank mydb}
puts [$obj queryList {select * from mytab}]

2) Connection per tk dialog
set obj [IDEDBConnectDialog setConnectionOn]

See documentation of all methods and classes to get all informations


XOSql is GPL Software 
See the GNU General Public License for more details.

See file LICENSE for more details 
Classes Classes Hierarchy

Class IDEDBConnectDialog

parameter: {type okcancel} {interface {}} {connectArgs {}} connectionObject
Dialog frame for connection dialog


setConnectionOn {object connectArgs}
Offer Tk GUI dialog to establish sql connection if interface object are specified this interface will be used Example: For connect mysql IDEDBConnectDialog setConnectionOn MySql If object is empty the user can choose the interface IDEDBConnectDialog setConnectionOn {} You can also pass some default values (as returned from getconnectionargs) IDEDBConnectDialog setConnectionOn MySql {user root host}

Class IDEDBConnectFrame

parameter: win connectionObject connectArgs {writefile 0}
The inner connection frame.
It can be used if you want to have connection dialog inside
of windows of your control

Class Sqlinterface

parameter: dbank {connected 0} {errorMessage {}}
Sqlite PgSql ODBC MySql
Abstract interface (abstract wrapper interface)
to sql commands handle such function as

1. sql queries
2. sql execute
3. connecting database
4. query metainformation as tables names
5. inserting row (handle primary key)

The interface use so called query objects that are normal xotcl objects.

Following methods are public API


All interface errors can be read from parameter errorMessage


connect {par_list}
Await a list of connection parameter for example {user root db xotcllib} Use array get to generate such list from array
disconnect {}
disconnect the database connection The destroing interface object also desconnct from database
escape {string}
mask all sql string by replacing string delmiter with \ for example sder"ewr - adef\"eer
execute {sql}
execute sql command if returnAffectedRows anser 1 (yes) the the result is the number of rows that are affected by the command
getconnectargs {}
return information about connection parameters list of list with elements
hasfunction {func}
check if the interface or query object support function with name
insertRow {table columns values}
confort api to sql command INSERT INTO table (col1,col2,..) VALUES (val1,val2,..)
insertRowAutoId {table columns values primarykey sequenzer}
Insert row and try to compute the autoid for primary key. The implementation is dependend from undelying base interface mysql supports autoid, postgres has sequencer by odbc und sqlite special sequencer database are used
isConnected {}
return the state of connection
query {sql}
return query object see API to MySql::SqlQuerry to get all documentation

empty string is return if error occurs. The error message can be retrieve by interface parameter ($interface errorMessage)

Warning! All queries must be destroyed to free query resource

queryList {sql}
Return result of query statement as Tcl list
returnAffectedRows {}
inform with 1 or 0 if method execute returns the number of affected rows by DELETE, UPDATE or INSERT statements
getInterfaces {}
Return list of list of all supported interfaces the sublists have elements: tcl-interface name xosql name xosql interface class base interface package
getInterfacesCleaned {}
Same as getInterfaces method but not return interfaces that are not installed on the system
getInterfacesNames {}
Get names of all supported interfaces
getInterfacesNamesCleaned {}
Same as getInterfacesNames method but not return interfaces that are not installed on the system
loadInterface {name}
Load interface with name (same as specified returned from getInterfacesNames) and return the interface class. It is factory method for sql interfaces