) |
tables, [includeCreate=True]) |
True
.
Importing the SQL is then simply a matter of executing the SQL. Here is an example:
backup = cursor.export(tables=['testTable']) cursor.drop(table='testTable') for sql in backup.split('\n'): cursor.execute(sql, mode='portable')
The testTable
should be exactly the same as it was before the code was executed.
Cursor
objects have the following attributes:
Column
objects for in the order of the fields from the last SELECT
or None
if the last SQL operation was not a SELECT
. Column
objects contain all the information about a particular field and provide conversion methods for that field.
Cursor
object
web.database compliant databases support qmark style parameters for substitutions as follows:
cursor.execute('SELECT * FROM Test WHERE columnName=?',['textEntry'])
sql[, parameters][,mode]) |
?
variables in the operation. mode can be 'direct'
to pass the parameters to the underlying DB-API 2.0 cursor or 'portable'
to execute the code in a portable fashion.
sql, manyParameters[,mode]) |
All these methods take the parameters format and convert. If they are not specified the values set in the cursor() method of the Connection
object is used.
[format],[convert]) |
An Error (or subclass) exception is raised if the previous call to executeXXX() did not produce any result set or no call was issued yet.
'dict'
to return them as a tuple of dictionary objects, 'tuple'
to return them as a tuple of tuples, 'object'
to return them as a tuple of dtuple
objects which can be treated as a tuple or a dictionary (or via attribute access for the majority of column names) or 'text'
to return tables designed to be displayed in a terminal 80 characters wide. If not specified takes the value specified in the cursor which by default is 'tuple'
True
to convert the results to the correct types, False
to leave the results as they are returned from the base cursor. If not specified takes the value specified in the cursor which by default is True
[format],[convert]) |
An Error (or subclass) exception is raised if the previous call to an execute() method did not produce any result set or no call was issued yet.
The values format and convert are as specified in fetchone()
It is assumed that if execute is True
in the following methods then you wish to be executing the code in portable mode, otherwise it is unlikely you would be using abstraction methods.
If you did wish to execute code in direct mode (through the DB-API 2.0 cursor) you could do the following:
sql = cusror.select(columns=['*'], tables=['table'], execute=False) cursor.execute(sql, mode='direct')
Warning:
It is possible to get the cursor abstraction methods to perform operations they were not designed for. For example, in cursor.select()
you could specify one of the columns as 'AVG(columnName)'
. This would produce an SQL statement which would return the mean value of the column columnName
on some databases but certainly not on all and therefore breaks the specification which states that columns should be a list of column names. To ensure database portability please stick to the published API.
tables, columns, [values=[], ][where=None, ][order=None, ][execute=None, ][fetch=None, ][**params]) |
Build an SQL string according to the options specified and optionally execute the SQL and return the results in the format specified. No error checking on field names if the SQL string is only being built. Strict error checking is only performed when executing the code.
'tableName.columnName'
?
in the WHERE
clause specified by where.
cursor.where()
. If where is a string it is converted to the correct format.
cursor.order()
. If order is a string it is converted to the correct format.
False
the method returns the SQL string needed to perform the desired operations. If True
the SQL is executed and the results converted and returned in the appropriate form. If not specified takes the value specified in the cursor which by default is True
True
and execute is not specified execute is set to True
. If True
and execute False
an error is raised.
True
table, columns, values, _sqlValues, [execute]) |
?
parameters in the _sqlValues sequence.
?
parameters for substitution then values contains the values to be substituted. Otherwise values must be an empty sequence.
False
the method returns the SQL string to perform the desired operations. If True
the SQL is executed. If not specified takes the value specified in the cursor which by default is True
table, columns, values, _sqlValues, [execute]) |
table, columns, values, _sqlValues [, where] [, execute]) |
?
parameters in the _sqlValues sequence. If there are more values specified in values than _sqlValues the remaining values are used to substitute for ?
parameters in where.
?
parameters for substitution then values contains the values to be substituted. Otherwise values must be an empty sequence.
cursor.where()
. If where is a string it is converted to the correct format.
False
the method returns the SQL string to perform the desired operations. If True
the SQL is executed. If not specified takes the value specified in the cursor which by default is True
table, [values=[]][, where] [, execute]) |
?
in the WHERE
clause specified by where.
cursor.where()
. If where is a string it is converted to the correct format.
False
the method returns the SQL string to perform the desired operations. If True
the SQL is executed. If not specified takes the value specified in the cursor which by default is True
table, columns [, values=[]] [, execute] ) |
Create table with fields specified by fields. fields is a tuple of field tuples which can be obtained as follows:
columns = [ cursor.column( field options... ), cursor.column( field options... ), cursor.column( field options... ), cursor.column( field options... ), ]
cursor.column()
False
the method returns the SQL string to perform the desired operations. If True
the SQL is executed. If not specified takes the value specified in the cursor which by default is True
table[, execute] ) |
False
the method returns the SQL string to perform the desired operations. If True
the SQL is executed. If not specified takes the value specified in the cursor which by default is True
function, table, column, [,where=None][, values=[]]) |
'max'
, 'min'
, 'sum'
or 'count'
?
parameters in the WHERE
clause
table, column [,where=None][,values=[]]) |
?
parameters in the where clause.
table, column [,where=None][,values=[]]) |
?
parameters in the where clause.
table, column [,where=None][,values=[]]) |
?
parameters in the where clause.
Helper methods build the data structures which should be passed to the Cursor
abstraction methods.
name, type[, required=0][, unique=0][, primaryKey=0][, foreignKey=None][, default=None]) |
Bool
, Float
, Binary
and Text
columns cannot be used as primary keys or unique columns. Binary
and Text
columns cannot have default values.
'Bool'
, 'String'
, 'Text'
, 'Binary'
, 'Long'
, 'Integer'
, 'Float'
, 'Date'
, 'Time'
, 'Datetime'
True
means the field cannot have NULL
values.
True
if the value must be unique. Two fields in the column cannot have the same value unless that value is NULL
where, [values=[]]) |
WHERE
clause suitable for use in the select(), update() and delete() methods of the cursor
object.
WHERE
clause. Can include the LIKE
operator which is used as follows:
WHERE columnName LIKE %s1%s2%s
Every % sign is matched against zero or more characters.
Note:
where should not include the string 'WHERE'
at the beginning.
?
parameters in the WHERE
clause
order) |
ORDER BY
clause suitable for use in the select() method of the cursor
object.
ORDER BY
clause. Note:
order should not include the string 'ORDER BY'
at the beginning.
) |
Warning: This is a new feature and has not had a lot of testing.