[SQL-CVS] r1680 - SQLObject/branches/0.7-bugfix/sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2006-04-05 14:29:03
|
Author: phd
Date: 2006-04-05 08:28:56 -0600 (Wed, 05 Apr 2006)
New Revision: 1680
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/col.py
Log:
A patch by jt...@ud...: sqlite foreign key.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/col.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/col.py 2006-04-05 14:28:37 UTC (rev 1679)
+++ SQLObject/branches/0.7-bugfix/sqlobject/col.py 2006-04-05 14:28:56 UTC (rev 1680)
@@ -734,6 +734,31 @@
kw['name'] = style.instanceAttrToIDAttr(kw['name'])
super(SOForeignKey, self).__init__(**kw)
+ def sqliteCreateSQL(self):
+ sql = SOKeyCol.sqliteCreateSQL(self)
+ other = findClass(self.foreignKey)
+ tName = other.sqlmeta.table
+ idName = other.sqlmeta.idName
+ if self.cascade is not None:
+ if self.cascade == 'null':
+ action = 'ON DELETE SET NULL'
+ elif self.cascade:
+ action = 'ON DELETE CASCADE'
+ else:
+ action = 'ON DELETE RESTRICT'
+ else:
+ action = ''
+ constraint = ('CONSTRAINT %(colName)s_exists '
+ #'FOREIGN KEY(%(colName)s) '
+ 'REFERENCES %(tName)s(%(idName)s) '
+ '%(action)s' %
+ {'tName': tName,
+ 'colName': self.dbName,
+ 'idName': idName,
+ 'action': action})
+ sql = ' '.join([sql, constraint])
+ return sql
+
def postgresCreateSQL(self):
sql = SOKeyCol.postgresCreateSQL(self)
other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
|