1.4.3 Cursor Options

Once you have connected to the database you will need a Cursor object with which to manipulate the database. Cursor stands for a "CURrent Set Of Results".

import web, web.database
connection = web.database.connect(type="mysql", database="test")
cursor = connection.cursor()

Once we have the connection to the database, connection, we can easily create a cursor by calling the connection's cursor() method.

Note: The cursor produced passes any calls to unknown attributes or function directly to the underlying DB-API 2.0 cursor. This means the cursor produced in the code above will behave exaclty like the cursor on which it is based but will also have additional methods.

The cursor() method takes the following options and will return the appropriate cursor object:

cursor( [autoExecute,][convertMode,][colTypesName,][types])
autoExecute
If set to False the SQL generated by methods like select() or create() is never executed but instead the SQL is returned as a String. If set to True the functions will execute the SQL and then return the SQL, or in the case of the select() method, will return the result of calling fetchRows(). The default is True.

convertMode
How to store the information about what type each column of the database should be converted to. Can be 'table' to store the data in a table whose name is specified by the colTypesName option. Can be 'description' to retrieve the type information from the cursor.description object. Not all databases support both options.
colTypesName
The name of the table use to store the column types information, if required. Default is 'ColTypes'.
types
A dictionary containg column type information used to pre-populate the _typesCache. Each table should have a dictionary where the field names are the keys and the field code integers are the values. The types dictionary should be a dictionary of these dictionaries where the keys are the table names.
debug
Should a log of SQL statements and ColTypes data be stored to self.debug? Can be either True or False. Default is False.

See About this document... for information on suggesting changes.