Hi again,
I found another small problem when working with a database with mixed case
columns. This one deals with foreign keys. Here is the portion of
sqlobject that generates the error (line 751 of col.py). Another
occurrence is on line 776.
class SOForeignKey(SOKeyCol):
def __init__(self, **kw):
foreignKey = kw['foreignKey']
style = kw['soClass'].sqlmeta.style
if not kw.get('name'):
kw['name'] =
style.instanceAttrToIDAttr(style.pythonClassToAttr(foreignKey))
else:
kw['origName'] = kw['name']
if not kw['name'].upper().endswith('ID'):
kw['name'] = style.instanceAttrToIDAttr(kw['name'])
super(SOForeignKey, self).__init__(**kw)
def postgresCreateSQL(self):
sql = SOKeyCol.postgresCreateSQL(self)
other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
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
the offending line is this:
constraint = ('CONSTRAINT %(colName)s_exists '
if you have a mixed-case column, it has to be enclosed by douple quotes.
This you can do in sqlobject like so:
foo = ForeignKey('MagicTable', dbName='"idFoo"')
Note the double quotes inside the single quotes! Otherwise postgresql will
complain. This however generates the following SQL code:
[...] "idFoo" INT, CONSTRAINT "idFoo"_exists FOREIGN KEY ("idFoo")
REFERENCES "MagicTable" ("idFoo") [...]
Note the badly quoted constraint name. Instead of "idFoo"_exists it should
read "idFoo_exists".
The question: Is there a way to explicitly tell sqlobject the constraint
name (like you do with the sequence-name with _idSequence), or should this
be fixed inside col.py?
Best regards,
Mich
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss