Methods
add_table_column(self, table, column, initval=None)
Add a column to a table.
- table
- Table name
- column
- (name, type)
- initval
- Initial value to fill column
change_table_column(self, table, oldname, newname, newtype=None)
Rename a column and/or change the datatype of a column.
- table
- Name of table
- oldname
- Name of column to change
- newname
- New name for column (can equal oldname).
- newtype
- New type for column, or None to keep original.
close(self)
Close connection, releasing any locks.
create_table(self, name, columns)
Create a table, (only) if it does not already exist.
- name
- Name of table
- columns
- list of tuples: (name, type)
Where 'type' is one of the basic types (INTEGER, REAL, etc.)
delete_table(self, name)
Permanently delete a table (if it exists) from the named database.
delete_table_column(self, table, colname)
Delete named column from table.
get_table_colnames(self, table)
Get a list of just the column names from table.
get_table_columns(self, table)
Get a list of column names & types for the given table.
Returns a list of tuples
(colname, coltype) where:
- colname
- Name of column
- coltype
- The SQL type string (not INTEGER, etc., so that arbitrary tables are supported)
The list will be in the same order as the order of the SQL statements used to create the table.
Returns [] if table doesn't exist.
get_tables(self, special=False)
Get a list of all tables in the given SQL database. If special==False, removes special names (database-specific).
has_table(self, name)
Convenience - does database contain table?
last_insert_id(self)
Returns the last autoincrement id generated
rename_table(self, oldname, newname)
Rename a table from oldname to newname.
run(self, stmt, bindings=())
Run query and returns
SqlResultSet or raises:
- SqlBusy: Database busy and timed-out waiting.
- Other: API error etc. Should not retry.
If called from
runfunc(), runs as part of current transaction.
Else, runs in its own transaction.
runfunc(self, func, args=(), kwargs={})
Run a user-supplied function inside a transaction.
- func
- Function, will be called as: func(sql, *args, **kwargs)
Where sql is an SqlProxy for func() to use. - args, kwargs
- Args to pass to func.
No return value. On error, raises:
- SqlBusy: Database busy and timed-out.
- Other: API error or other error in func().