datatable
index
/home/dlink/vlib/vlib/datatable.py

# $Id: datatable.py 38 2010-06-02 17:06:10Z rlowe $

 
Modules
       
re
sys
types

 
Classes
       
__builtin__.object
DataTable
exceptions.Exception(exceptions.BaseException)
DataTableError

 
class DataTable(__builtin__.object)
    Database table abstraction Layer
 
  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

 
class DataTableError(exceptions.Exception)
    
Method resolution order:
DataTableError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
Functions
       
sqlize(s)
Change single quotes to two single quotes.
This makes strings with single quotes in them suitable for
insertion into sql databases.

 
Data
        DEBUG = 0
DEBUG_SQL = 0
WRITEBACK = 1