MatLab Resources

SQL DB Library | XML Generator | WebBot | Input Dialog | Program Statistics | Triangular Random | Fractals Explorer ]
© CSE, 2003-2004


CSE SQL Database Library 1.0/1.5b

An SQL Database access library for Matlab

Ever needed to access an SQL database from Matlab? This library fulfill this purpose with a short and simple collection of m-files.

Why a database Library for Matlab?

It has been implemented because the
database toolbox of Mathworks requires to have databases registered in the "ODBC Data Sources" dialog, which is cumbersome when a Matlab program needs to access different, ever changing databases that for instance result from third party software like AspenTech's BatchPlus, or needs to create new databases and of course write/modify them.


This library is a collection of functions to read and write data via SQL commands in and from an SQL Database.
It features an error checking and trapping and custom-removable warnings instead of most errors.

It contains the following functions:

General Functions:
DBInitializeInitialize toolbox
DBOpen Open SQL Database
DBClose Release SQL Database
DBFinish Finish all SQL connections

Table Management:
DBTableDef Get information about a Table
DBRead Read a Table
DBWrite Write a Table

Query Management:
DBQuery Run an SQL query and obtain resulting table
DBCreateQuery Creates an SQL query table for permanent use
DBDeleteQuery Deletes a previously created permanent query

SQL Execution:
DBExecute Execute an SQL command

Library version and download

Version 1.0 - Release 22.09.03 [Legal Stuff]
Download the library as a .m installer (43 Kb). [Generated with MakeInstall]

Version 1.5b - Under development, compatible with R12. [Legal Stuff]
This version should mostly work correctly under both R12 and R13. Take care however, some function signatures did change from version 1.0!
It does not contain any "new" features.

Download the library as a .zip (21 Kb).


Obviously Matlab must be installed. This library has been created and tested with the Release 13 of Matlab. No external toolboxes are requested.
CSE SQL Database Library uses Access' ActiveX components and therefore must run on a PC where MS Access is installed.

top of page

generateXML v.1.0

XML Generation

GenerateXML outputs an XML string representing a Matlab variable; it is mainly intended for exporting structures for later import in a database.

It features the following specificities:
  • Cell-array and substructure linking:
    Most database systems generate new tables for each substructure (or cell array, that are sort of structures also) present in the XML file (e.g. Access). Importing the XML results in several tables without relations... With generateXML, when cell arrays or sub-structures are encountered, a "foreign key" is added in the parent object. The child cell array or structure recieve a corresponding "primary key". This allows keeping the relationships...

  • Blowing up the matrices:
    Most database systems cannot import a matrix in one step. Each element is a single number, and in the best case, the whole matrix is imported as a long, space-separated string. With generateXML, matrices are devided into single elements, which each get a new label (e.g. mymatrix_1, mymatrix_2, ...). Thus matrices are correctly imported (with one value per column in the record).

Version and download

Version 1.0 - Release 10.10.04 [
Legal Stuff]

Download the function as a .m matlab file (7 Kb).


This XML format generates a HUGE overhead, mostly because of the matrix blow-up, and is probably not usable when the structure contains very large matrices. It is however efficient for rather intrigate structures containing relatively small datasets.

If you do not intend to import the data in a database, but only to save in human-readable form the data for further use in MatLab or other custom software, it is advised to use the more efficient XML Toolbox by Marc Molinari, available on Matlab exchange website.
GenerateXML is a one-way function and it does not feature an import fonctionality [yet]... to reimport data, or to work on the resulting database, use SQL and the CSE SQL Library, available on this website.

The data types supported are: char, numeric (also complex), struct, cell, logical/boolean only. Sparse matrices are not supported.

top of page

Legal blahblah & Conditions of use
© CSE - L.Cavin, 2003, 2004
These libraries and functions (THE PROGRAM) are provided "as is" without warranty, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program is with the person downloading or running the program (THE USER). Should the program prove defective, the user assumes the cost of all necessary servicing, repair or correction.
In no event will the Author or the Copyright holder be liable to the user for damages, including any general, special, incidental or consequential damages arising out of the use, peruse or inability to use the program (including, but not limited to loss of data or data being rendered inaccurate or losses sustained by the user or third parties or a failure of the program to operate with any other programs), even if the Author or the Copyright holder has been advised of the possibility of such damages.
The fact of downloading or running the program implies acceptation of the present liability limitation by the user.
These libraries and functions are free to use for non-commercial purposes and can be distributed (free of charge) as long as the copyrights notices are kept intact. In particular, if the program is distributed further by the user, the user is responsible for including this legal warning and liability limitation to the distribution.
It is also encouraged to improve these functions; please send to the author any improvements - we may want to include them in this distribution under the same conditions.

Do not be afraid, I am confident that the program will work - without warranties of course ;-)
Thanks to the Free Software Foundation for inspiring this nice little legal blahblah... My favorite part is the "inability to use"... even if the "general, special, incidental or consequential" part is also quite fun!

Page ©
Cavin Softwares Engineering, 2003-2004.
[last updated: 23.10.04]