home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeMySQL and mSQLSearch this book

20.2. Module: mSQL

The 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.

Method: mSQL.connect( )

Signature

connection = mSQL.connect()
connection = mSQL.connect(host)

Synopsis

Connects 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.

Example

connection = mSQL.connect(`carthage.imaginary.com')
Method: connection.selectdb( )

Signature

connection.selectdb(database)

Synopsis

Selects 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.

Example

connection.selectdb(`test');
Method: connection.query( )

Signature

results = connection.query(sql)

Synopsis

Sends 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.

Example

results = conn.query(`SELECT title, year FROM movies');
row1 = results[0];
Method: connection.listdbs( )

Signature

dbs = connection.listdbs()

Synopsis

Provides a Python list of databases available on the server.

Example

dbs = conn.listdbs()
Method: connection.listtables( )

Signature

connection.listtables()

Synopsis

Provides a Python list of tables stored in the selected database.

Example

tables = conn.listtables()
Attribute: connection.serverinfo

Synopsis

Returns the version number of the mSQL instance to which you are currently connected.

Example

info = connection.serverinfo;


Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.