Author: phd
Date: 2006-04-05 08:28:37 -0600 (Wed, 05 Apr 2006)
New Revision: 1679
Modified:
SQLObject/trunk/sqlobject/col.py
Log:
A patch by jt...@ud...: sqlite foreign key.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2006-04-05 04:08:03 UTC (rev 1678)
+++ SQLObject/trunk/sqlobject/col.py 2006-04-05 14:28:37 UTC (rev 1679)
@@ -727,6 +727,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)
return sql
|