Module orngMySQL is Orange's gateway to MySQL DBMS. It sits on a top of a MySQL for Python that provides for a package called MySQLpy for interface between MySQL and Python. While MySQLpy enables you to manipulate data in MySQL DBMS from Python, orngMySQL takes care that the Orange's data tables can be transferred to and from MySQL data bases. orngMySQL implements a single class called Connect, which establishes a link with the data base and provides means for communication.
establishes a connection with a data base and
provides for a number of methods that are used for interchange of the
data between Orange and MySQL.
Attributes
Methods
statement
and returns
the data in the form of Orange's example table
(ExampleTable
). If the return data has to conform to
some existing data domain, this has to be passed using
use
argument.table
in the form of Orange's example table. The same can be obtained
by calling query
with SELECT * FROM statement, which
is in fact exactly what this method does. Like in
query
, the domain of Orange's table to be used with
returned data set can be passed using the argument use
.data
to the MySQL table
table
. If the table already exists, throws
exception. To overwrite, use overwrite=0
.While there are few (or almost no) restrictions for attribute names in Orange, names of the fields in SQL tables have to comply to quite a few restrictions. When writing data to MySQL, orngMySQL replaces any special characters (like blanks, slashes, ...) with underscores, and if an attribute name in Orange data set is an SQL keyword, it will appear in the tables with a "$" prefix.
Following type conversion between SQL field types and Orange's attribute types is used when reading from mySQL:
When writing to mySQL, ENUM will be used for discrete attributes, FLOAT for continuous attributes and CHAR(200) for string attributes.
There are two special kinds of attributes in Orange: class attributes and meta attributes. In each data set, there can be only one class attribute but any number of meta attributes. When reading the data from MySQL, orngMySQL parses the field names: those preceded with "m$" will be stored as meta attribute in Orange's data table, and "c$" will be treated as an Orange's class attribute.
When orngMySQL writes to mySQL, the prefix notation as described above will be used if there are any class or meta attributes in Orange's data table.
The example below will only work if you have installations of MySQL and MySQLpy on your computer; neither are included in Orange distribution.
We start with setting-up a small data table in MySQL to be used in our examples:
If you already have a table called bus in the data base test and want to replace it with the data above, uncomment the line "-- DROP TABLE bus;" (remove leading "--").
If everything goes well, running the script from shell by something like
should have the following output:
Let us now write the script that reads this table from mySQL and in Orange data table stores, say, only the rows that concern bus line 10:
Running this script reports on four data instances and lists the attributes (with types) in new Orange data table:
Say that our script that stores the data set in MySQL would be a little different and would
busclass.sql (uses bus.txt)
Notice that now we have prefixed the id field of the table letting orngMySQL know this will be used as meta attribute. We did similar to arrival field, this time dedicating this field to a class attribute. The script below should reveal the effects of these subtle changes:
By running it, we get:
Once we have a class attribute, we can run some learner on our data set. Let us read the complete data on buses from MySQL, and construct a classification tree to predict when the busses will be late:
Here's our newly induced model (numbers in brackets are number of instances that reached a specific node in the tree):
For our final example, we load Iris data set in Orange, write it to MySQL data base, and read from it only those data records whose sepal length is below 5 mm.
The output of the script above is: