Package gmisclib :: Module sqlbase :: Class DBx
[frames] | no frames]

Class DBx

source code

This class is the main interface. Normally, you derive a class from this to represent a table in the database. Each of your derived classes MUST contain an attribute COL_type which specifies what columns are in that table. Each derived class will have a unique ID number called id; this will be a column in the database, and it will be stored in each instance object. The DBx class manages that ID number for you.

Beyond that, a derived class MUST redefine _fromtuple.

Nested Classes
This is used by all the SQL classes, and initializes the class. (Inherited from gmisclib.sqlbase.DB)
Instance Methods
__init__(self, connection)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
get_id(self) source code
source code
__del__(self) (Inherited from gmisclib.sqlbase.DB) source code
is_dirty(self) (Inherited from gmisclib.sqlbase.DB) source code
Changes to an instance are not written to the database unless you call make_dirty() or write(). (Inherited from gmisclib.sqlbase.DB)
source code
This method writes an instance out to its database. (Inherited from gmisclib.sqlbase.DB)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
select(cls, db, where, *args) source code
get_by_id(cls, db, idx) source code
bump_id(cls, delta)
You can call this manually if you want to introduce a gap between ID numbers. (Inherited from gmisclib.sqlbase.DB)
source code
confirm(cls, connection)
This can be called to confirm that the column names in the database matches what the class expects. (Inherited from gmisclib.sqlbase.DB)
source code
create(cls, connection, if_not_exists=True)
This creates the table in the database. (Inherited from gmisclib.sqlbase.DB)
source code
flush_cache(cls) (Inherited from gmisclib.sqlbase.DB) source code
index_nonunique(cls, connection, *columns) (Inherited from gmisclib.sqlbase.DB) source code
index_unique(cls, connection, *columns) (Inherited from gmisclib.sqlbase.DB) source code
set_ID(cls, connection)
This should be called when you first open an existing database when you have the intent to write. (Inherited from gmisclib.sqlbase.DB)
source code
Class Variables
a sequence of (column_name, data_type_name) pairs.
  SQL_name = 'DBx'
the name of the corresponding table in the database.
  S_inDB = 1 (Inherited from gmisclib.sqlbase.DB)
  S_modified = 2 (Inherited from gmisclib.sqlbase.DB)
  S_notinDB = 0 (Inherited from gmisclib.sqlbase.DB)
the lowest unused ID number.
Instance Variables
the instance's ID number.

Inherited from object: __class__

Method Details

__init__(self, connection)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__

(Representation operator)

source code 


Overrides: object.__repr__
(inherited documentation)

Class Variable Details


a sequence of (column_name, data_type_name) pairs. Those name the columns of the table and tell what type of data is in each. data_type_name must be the name of a legal sqlite3 data type OR, it must be "FKEY tablename column_name" where tablename is the name of the table into which the foreign key points and column_name is the name of the column in that table. Typical tuples in COL_type are ("Number_of_dogs", "INTEGER") or ("dog_id", "FKEY dog_info id"). Note that COL_type should not include the ID number, which is always column id; it is added automatically.


the name of the corresponding table in the database. This defaults to the name of the leaf class.

Instance Variable Details


the instance's ID number. Note that an ID number is allocated for every instance you create. Instances you look up with select won't necesarily be new: they bay just be a pointer to an existing, perhaps cached instance. The ID number of an instance is persistant and is written into the database.