|
Methods defined here:
- __init__(self, db, tablename)
- Instantiate a DataTable.
- columnDefs(self)
- Read table metadata information from database
return LIST of the form
[{'name': 'adoption_id', 'type': 'int(10) unsigned'},
{'name': 'professor_id', 'type': 'int(10) unsigned'}, ... ]
- commit(self)
- Commit Transaction Bock.
Also see self.autocommit.
- deleteRows(self)
- Performs an SQL DELETE statement.
Use setFilters() prior to calling. Or will raise Error.
Example:
users = DataTable('user')
users.setFilters ( ["date >= '2007-06-01'", "status = 'A'" ] )
users.deleteRows ()
Which is equivalent to:
delete from user where date >= '2007-06-01' and status = 'A'
Returns number of rows deleted.
- describe(self)
- Return output of SQL Describe command as a Dict
- get(self, filter=None)
- Given an optional SQL filter, or None for All
Return rows. (See getTable())
- getTable(self)
- Performs an SQL SELECT statement.
Use setColumns(), setFilters(), setOrderBy(), and setLimits()
prior to calling.
Example: from datatable import DataTable
users = DataTable('user')
users.setColumns (['name', 'color'])
users.setFilters (['group_id = 200', "status = 'A'"])
recordset = users.getTable()
Which is equivalent to:
select name, color from user where group_id = 200 and status = 'A'
Returns tuple sets as a list of Dictionaries
[ { 'name': 'Fred', 'color': 'red'},
{ 'name': 'Barbara', 'color': 'blue'} ]
- insertRow(self, record, replace_cmd=0)
- Performs an SQL INSERT statement.
(or SQL REPLACE if replace_cmd = 1)
Uses dictionary record passed in for column and values
Example:
user = { 'name': 'Ralph', 'color': 'blue' }
users = DataTable('user')
users.insertRow(user)
Which is equivalent to:
insert into user (name, color) values ('Ralph', 'blue')
Returns id of row inserted.
- replaceRow(self, record)
- rollback(self)
- setColumns(self, columns)
- Set User defined column list to be used SELECT CLAUSE of
subsequent SQL statements.
The columns arg can be either a string or a list of strings.
Examples: dobj.setColumns ("username")
dobj.setColumns (["username", "lastname"])
- setFilters(self, filters=None)
- Set filters to be used in WHERE CLAUSES of
subsequent SQL SELECT and UPDATE statements.
The filters arg can be a string, a list of strings, or a dict
containing strings or lists (to use with "W in (X, Y, Z)")
Examples: dobj.setFilters ("email like 'fred%'")
dobj.setFilters (["email like 'fred%'", "name = 'Fred'"])
dobj.setFilters ({'email': '[email protected]', 'name': 'Fred'})
dobj.setFilters ({'name': ['Fred', 'foo', 'bar']})
- setGroupBy(self, group_by)
- Set list of columns used in GROUP BY CLAUSE of
subsequent SQL SELECT statements.
- setLimit(self, limit)
- Set value of LIMIT CLAUSE in subsequent SQL SELECT statements.
- setOrderBy(self, order_by)
- Set list of columns used in ORDER BY CLAUSE of
subsequent SQL SELECT statements.
- setWriteBack(self, switch)
- Set writeback switch.
0 - do not write data to disk
1 - writeback data to disk (DEFAULT)
Allows calling program to turn off writeback, for Debuging.
Example:
if not WRITEBACK: myDataTable.setWriteBack(0)
- startTransaction(self)
- updateRows(self, record)
- Performs an SQL UPDATE statement.
Use setFilters() prior to calling. Or will raise Error.
Example:
modified_columns = { "color": "yellow", "location": "nyc" }
users = DataTable('user')
users.setFilters ( ["date >= '2007-06-01'", "status = 'A'" ] )
users.updateRows (modified_fields)
Which is equivalent to:
update user set color = 'yellow', location = 'nyc'
where date >= '2007-06-01' and status = 'A'
Returns number of rows inserted.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- table_columns
|