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

Class DB

source code


Base class for all persistent objects in a sqlite database. Not the normal API. Derived classes need to define a write() method.

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

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

Class Methods
 
bump_id(cls, delta)
You can call this manually if you want to introduce a gap between ID numbers.
source code
None
confirm(cls, connection)
This can be called to confirm that the column names in the database matches what the class expects.
source code
None
create(cls, connection, if_not_exists=True)
This creates the table in the database.
source code
 
set_ID(cls, connection)
This should be called when you first open an existing database when you have the intent to write.
source code
 
index_unique(cls, connection, *columns) source code
 
index_nonunique(cls, connection, *columns) source code
 
flush_cache(cls) source code
Class Variables
  S_notinDB = 0
  S_inDB = 1
  S_modified = 2
  SQL_name = 'DB'
  idx = 0
Properties

Inherited from object: __class__

Method Details

__init__(self, connection)
(Constructor)

source code 

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

Parameters:
  • connection (sqlite3.Connection)
Overrides: object.__init__

write(self)

source code 

This method writes an instance out to its database. This method should assemble its attributes to form an argument list for _write, and then call _write with that argument list. It should be used like this:

       def write(self):
               return self._write(self.something, self.other, self.stuff, self.misc)
Returns: int
the return value of _write.
Notes:
  • write() forces an immediate write or an update of the database, whether or not you have called make_dirty(). make_dirty() simply arranges for a write to occur when the object is eventually destroyed.
  • The instance remembers the database from which it came.
  • Do not pass self.id to self._write(). That's handled automatically.

make_dirty(self)

source code 

Changes to an instance are not written to the database unless you call make_dirty() or write(). write() forces an immediate write, whereas make_dirty() simply marks the instance so that it will eventually be written out when the destructor is called.

Note: Global variables are destroyed very late, possibly after other necessary objects have already been destroyed, so you may not want to trust that make_Dirty() will behave well on global variables.

confirm(cls, connection)
Class Method

source code 

This can be called to confirm that the column names in the database matches what the class expects.

Parameters:
Returns: None
None
Raises:

create(cls, connection, if_not_exists=True)
Class Method

source code 

This creates the table in the database. It is harmless if the table already exists.

Parameters:
Returns: None
None

set_ID(cls, connection)
Class Method

source code 

This should be called when you first open an existing database when you have the intent to write. It sets the initial ID number to be larger than the largest ID in the database.