20.2. Module: mSQLThe mSQL module is very similar to the MySQL one. The entry point into the module is via the mSQL.connect() method. The return value from this method represents a connection to an mSQL database that you can use for all of your mSQL operations.
Signatureconnection = mSQL.connect() connection = mSQL.connect(host) SynopsisConnects to the mSQL database engine on the specified server. If you call connect with no arguments, the method connects to the database engine on the local machine. It returns an mSQL connection handle that you can use for database access. Exampleconnection = mSQL.connect(`carthage.imaginary.com')
Signatureconnection.selectdb(database) SynopsisSelects the name of the database for your connection to use. Any further operations on that connection will work against that database unless you later select a new database. Exampleconnection.selectdb(`test');
Signatureresults = connection.query(sql) SynopsisSends the specified SQL statement to the currently selected database for execution. The results are returned as a list of tuples, where each tuple represents a row. This method is also used for updates -- you just do not process the return value. Exampleresults = conn.query(`SELECT title, year FROM movies'); row1 = results[0];
Signaturedbs = connection.listdbs() SynopsisProvides a Python list of databases available on the server. Exampledbs = conn.listdbs()
Signatureconnection.listtables() SynopsisProvides a Python list of tables stored in the selected database. Exampletables = conn.listtables()
SynopsisReturns the version number of the mSQL instance to which you are currently connected. Exampleinfo = connection.serverinfo;
SynopsisReturns the name of the server on which the mSQL instance is running. Examplehost = connection.hostname Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|