Module database :: Class Database
[hide private]
[frames] | no frames]

Class Database

source code

Instance Methods [hide private]
 
__enter__(self) source code
 
__exit__(self, ex_type, ex_value, tb) source code
 
__del__(self) source code
 
__init__(self, filename, virtualtables=None)
@param filename: database filename...
source code
 
_sqltrace(self, cmd, bindings) source code
 
_rowtrace(self, *row) source code
 
sql(self, statement, params=())
Executes statement and return a generator of the results
source code
 
sqlmany(self, statement, params)
execute statements repeatedly with params
source code
 
doestableexist(self, tablename) source code
 
getcolumns(self, tablename, onlynames=False) source code
 
savemajordict(*args, **kwargs)
This is the entrypoint for saving a first level dictionary such as the phonebook or calendar.
source code
 
updateindirecttable(self, tablename, indirects) source code
 
getmajordictvalues(*args, **kwargs) source code
 
_getindirect(self, what)
Gets a list of values (indirect) as described by what
source code
 
_altertable(self, tablename, columnstoadd, columnstodel, createindex=0)
Alters the named table by deleting the specified columns, and adding the listed columns
source code
 
deleteold(*args, **kwargs)
Deletes old entries from the database.
source code
 
savelist(*args, **kwargs)
Just save a list of items (eg categories).
source code
 
loadlist(*args, **kwargs)
Loads a list of items (eg categories)
source code
 
getchangescount(*args, **kwargs)
Return the number of additions, deletions, and modifications made to this table over time.
source code
Method Details [hide private]

__init__(self, filename, virtualtables=None)
(Constructor)

source code 

@param filename: database filename
@param virtualtables: a list of dict specifying the virtual tables
    Each dict is expected to have the following keys:
    'tablename': the name of the virtual table
    'modulename': the name of the module that implements this virtual
        table
    'moduleclass': the ModuleBase subclass that implements this
        virtual table
    'args': arguments passed to instantiaion of the module class

savemajordict(*args, **kwargs)

source code 

This is the entrypoint for saving a first level dictionary such as the phonebook or calendar.

Parameters:
  • tablename - name of the table to use
  • dict - The dictionary of record. The key must be the uniqueid for each record. The @extractbitpimserials function can do the conversion for you for phonebook and similar formatted records.
  • timestamp - the UTC time in seconds since the epoch. This is
Decorators:
  • @ExclusiveWrapper

getmajordictvalues(*args, **kwargs)

source code 
Decorators:
  • @ExclusiveWrapper

_getindirect(self, what)

source code 

Gets a list of values (indirect) as described by what

Parameters:
  • what - what to get - eg phonebook_serials,1,3,5, (note there is always a trailing comma)

_altertable(self, tablename, columnstoadd, columnstodel, createindex=0)

source code 

Alters the named table by deleting the specified columns, and adding the listed columns

Parameters:
  • tablename - name of the table to alter
  • columnstoadd - a list of (name,type) of the columns to add
  • columnstodel - a list name of the columns to delete
  • createindex - what sort of index to create. 0 means none, 1 means on just __uid__ and 2 is on all data columns

deleteold(*args, **kwargs)

source code 

Deletes old entries from the database. The deletion is based on either criterion of maximum values or age of values matching.

Parameters:
  • uids - You can limit the items deleted to this list of uids, or None for all entries.
  • minvalues - always keep at least this number of values
  • maxvalues - maximum values to keep for any entry (you can supply None in which case no old entries will be removed based on how many there are).
  • keepoldest - values older than this number of days before now are removed. You can also supply None in which case no entries will be removed based on age.
Returns:
number of rows removed,number of rows remaining
Decorators:
  • @ExclusiveWrapper

savelist(*args, **kwargs)

source code 

Just save a list of items (eg categories). There is no versioning or transaction history.

Internally the table has two fields. One is the actual value and the other indicates if the item is deleted.

Decorators:
  • @ExclusiveWrapper

loadlist(*args, **kwargs)

source code 

Loads a list of items (eg categories)

Decorators:
  • @ExclusiveWrapper

getchangescount(*args, **kwargs)

source code 

Return the number of additions, deletions, and modifications made to this table over time. Expected fields containted in this table: __timestamp__,__deleted__, __uid__ Assuming that both __rowid__ and __timestamp__ values are both ascending

Decorators:
  • @ExclusiveWrapper