- SQLObject 0.6.1
- SQLObject 0.6
- SQLObject 0.5.3
- SQLObject 0.5.2
- SQLObject 0.5.1
- SQLObject 0.5
- SQLObject 0.4
- SQLObject 0.3
- SQLObject 0.2.1
- The long broken and unused
DBMConnectionhas been removed.
- Added a connection parameter to all class methods (patch 974755)
- Connection objects have a
.moduleattribute, which points to the DB-API module. This is useful for getting access to the exception objects.
UnicodeCol()that converts to and from Unicode in the database. See docs.
- Added indexing (from Jeremy Fitzhardinge). See the documentation for more.
- All connections are explicitly closed, not just garbage collected. Many database drivers don’t close database connections properly when the connection object is garbage collected.
distinctoption to selects, like
- You can now do
MyClass.selectBy(joinedTable=joinedTableInstance), where before you had to do
MyClass.selectBy(joinedTableID=joinedTableInstance.id). (From Dave Cook)
- Lazy updates. Add
_lazyUpdate=Trueto your class, and updates will only be written when you call
syncalso refetches the data from the database, which
syncUpdatedoes not do). When enabled, instances have a property
dirty, which indicates if they have pending updates. Inserts are still done immediately.
- Separated database drivers (PostgresConnection, MySQLConnection,
etc.) into separate packages. You can access the driver through
mysql://user:pass@host/dbname– to set drivers after class creation you should use sqlobject.connectionForURI().
SQLObjectpackage has been renamed to
sqlobject. This makes it similar to several other packages, and emphasizes the distinction between the
sqlobjectpackage and the
- Class instantiation now creates new rows (like .new() used to do), and the .get() method now retrieves objects that already have rows (like class instantiation used to do).
- We’re now using a Subversion repository instead of CVS. It is located at http://svn.colorstudy.com/trunk/SQLObject
- If you pass
*Colconstructors, then your column name doesn’t have to be restricted to a-z, 0-9, and _.
*Colconstructors now support cascade:
cascade=None(default) means no constraint;
cascade=Truemeans that if the foreign key is deleted, the object will be deleted;
cascade=Falsemeans that the delete will fail;
cascade="null"means that the column will be set to NULL. The constraints are only implemented in the DBMS, not in SQLObject (i.e., they will not work in databases like MySQL and SQLite).
_create(id, **kw)method that can be overridden to intercept and modify attempts to insert rows in the database.
- You can specify
_idTypein your class, like
_idType = str. The default type is
int; i.e., IDs are coerced to integers. This is a temporary interface; a more general specifier for primary keys will be added later.
- New classmethod
createTableSQL()method for SQLObject classes, which returns the SQL that can be used to create the table. Analog to
- SQLite booleans fixed.
- You can now use
sqlite:/:memory:to store the database in memory.
- Some bugs resolved when caching is turned off (SF 956847)
- Python 2.2 booleans fixed (SF: 903488)
- Longs (e.g.,
1L) get converted properly (SF: 939965)
We’re now using Subversion instead of CVS. The repository is located at svn://colorstudy.com/trunk/SQLObject
- If you commit or rollback a transaction, you must call
trans.begin()to restart the transaction. Any database access on the transaction inbetween commit/rollback and being will result in an AssertionError. (It’s also acceptable to create a new transaction object instead of reusing the old one, but objects in that transaction will be invalid)
- Using .select() would hold on to a connection, and also release it back to the connection pool. Very un-threadsafe and all-around bad.
- Fixed bug which did not release connections after database (query) error.
- When setting columns that use validators, the Pythonic (vs. database) representation wasn’t being stored in the column. Now we roundtrip (through toPython and fromPython) the values when they get set.
- PostgreConnection is back to using sequences for ID generation, instead of oids. Long explanation – oids can be unindexed in some versions of Postgres, or not even exist.
- When turning caching off and using transactions, got an attribute error on rollback.
- Rollback or commit didn’t find objects that were expired from the cache but still in memory.
- Rollback or commit didn’t free the connection object, so as you created more transactions it stole connections and didn’t put them back in the pool.
- Select results no longer have a __len__ method (i.e., you can’t do
len(Person.select(Person.q.firstName=='Bob'))). There is now a
__len__gets called implicitly in several circumstances, like
list(), which causes potentially expensive queries to
- Objects retrieved from a join now respect the transaction context of the original instance.
- Firebird support.
- Database-specific literal quoting (motivation: MySQL and Postgres use backslashes, Firebird and SQLite do not).
- Generic conversion/validation can be added to columns.
- BoolCol for portable boolean columns (BOOL on Postgres, INT on MySQL, etc.)
- Non-integer IDs. (Automatic table creation is not supported for non-integer IDs)
- Explicit IDs for new instances/rows (required for non-integer IDs).
- Instances can be synced with the database (in case there have been updates to the object since it was first fetched).
- Instances can be expired, so that they will be synced when they are next accessed.
- SQLBuilder.sqlRepr renamed to SQLBuilder.sqlrepr, signature
sqlrepr(value, databaseName)to quote
databaseNameis one of
sqlReprmagic method renamed to
__sqlrepr__, and takes new
- When using explicit booleans, use
Col.FALSEfor backward compatibility with Python 2.2. This is not required for
BoolCol, however (which converts all true values to TRUE and false values to FALSE)
- SQLObject has a
sqlreprmethod, so you can construct queries with something like
"WHERE last_name = %s" % Person.sqlrepr('Bob')
- Released all locks with
finally:, so that bugs won’t cause frozen locks.
- Tons of transaction fixes. Transactions pretty much work.
- A class can have multiple foreign keys pointing to the same table
spouse = ForeignKey("Person"); supervisor = ForeignKey("Person"))
You can specify columns in a new, preferred manner:
class SomeObject(SQLObject): someColumn = Col()
class SomeObject(SQLObject): _columns = [Col('someColumn')]
Cache objects have a clear method, which empties all objects. However, weak references to objects are maintained, so the integrity of the cache can be ensured.
SQLObject subclasses can be further subclassed, adding or removing column definitions (as well as changing settings like connection, style, etc). Each class still refers to a single concrete table in the database – the class hierarchy is not represented in the database.
Each SQLObject subclass can have an associated style, as given in the _style attribute. This object is used to map between Python and database names (e.g., the column name for a Python attribute). Some samples are available in the Style module.
Postgres support for _fromDatabase (reading a table definition from the database, and creating a class from that).
Postgres id columns more permissive, you don’t have to create a specially named sequence (or implicitly create that sequence through
SERIAL). lastoid is used instead.
localhostas the default host, and the empty string as the default password.
Added functions for use with queries: ISNULL, ISNOTNULL.
!=can be used with None, and is translated into ISNULL, ISNOTNULL.
Classes can be part of a specific registry. Since classes are referred to by name in several places, the names have to be unique. This can be problematic, so you can add a class variable _registry, the value of which should be a string. Classes references are assumed to be inside that registry, and class names need only be unique among classes in that registry.
SomeClass.select()selects all, instead of using
SomeClass.select('all'). You can also use None instead of
Trying to fetch non-existent objects raises SQLObjectNotFound, which is a subclass of the builtin exception LookupError. This may not be raised if _cacheValues is False and you use the ID to fetch an object (but alternateID fetches will raise the exception in either case).
Can order by descending order, with the reversed option to the select method, or by prefixing the column with a
Ordering with joins works better – you can order with multiple columns, as well as descending ordering.
Col and Join¶
- Join constructors have an argument orderBy, which is the name
of a Python attribute to sort results by. If not given, the
appropriate class’s _defaultOrder will be used. None implies
no sorting (and
orderBy=Nonewill override _defaultOrder).
- ForeignKey class (subclass of Col), for somewhat easier/clearer declaration of foreign keys.
- Col (and subclasses) can take a sqlType argument, which is used
in table definitions. E.g.,
Col(sqlType="BOOLEAN")can be used to create a
BOOLEANcolumn, even though no BooleanCol exists.
- alternateID (a specifier for columns) implies
NOT NULL. Also implies
- unique (a specifier for columns) added.
- DecimalCol and CurrencyCol added.
- EnumCol uses constraints on Postgres (if you use createTable).
- DateTimeCol uses
TIMESTAMPfor Postgres. Note that the Python type name is used for column names, not necessarily the SQL standard name.
- Foreign key column names are slightly more permissive. They still
need to end in
id, but it’s case insensitive.
- _defaultOrder should be the python attribute’s name, not the database name.
- SomeClass.q.colName uses proper Python attributes for colName, and proper database names when executed in the database.
- SQLite select results back to being proper iterator.
- SomeClass.q.colName now does proper translation to database names, using dbName, etc., instead of being entirely algorithm-driven.
- Raise TypeError if you pass an unknown argument to the new method.
- You can override the _get_* or _set_* version of a property without overriding the other.
- Python 2.3 compatible.
- Trying to use
id = Col()will raise an exception, instead of just acting funky.
ForeignKeycolumns return None if the associated column is NULL in the database (used to just act weird).
- Instantiating an object with an id of None will give an error, instead of just acting weird.
- Col class separated into Col and SOCol (and same for all other *Col classes). Col defines a column, SOCol is that definition bound to a particular SQLObject class.
- Instance variable
_SO_columnsholds the SOCol instances.
- Table creation (SQL schema generation) via new class method createTable. And of course a dropTable method to go with.
- Add and remove columns at runtime, optionally modifying the
schema in the database (via
ALTER). (Does not work in SQLite)
- New column classes (see Col module), indicates type
- Classes can be created by parsing an already existant table (MySQL only).
- Objects are not cached indefinitely. Cached objects are expired
into a weak dictionary (it allows objects to be garbage collected if
nowhere else in the program is using the object, but until it is
collected it’s still available to the cache). Some cache control,
nocache=Trueto your connection object to eliminate as much caching as possible. See Cache module for a bit more.
- New DBMConnection, implements a database-like backend without any database to speak of, including queries (so long as you use SQLBuilder and don’t generate your where clauses manually). Actual SQL generation is done entirely by the database connection, allowing portability across very different backends.
- Postgres table IDs should be created with type
SERIAL(which implicitly creates a sequence).
- New _defaultOrder class variable gives a default for the orderBy parameter to select queries.
- LIMIT/OFFSET (select result slicing) works in Postgres and SQLite.
tableExistsmethod from DBConnection works in same.
- mxDateTime not required (never should have been, always just an option).