Ejemplo n.º 1
0
 def postgresCreateSQL(self):
     from main import findClass
     sql = SOKeyCol.postgresCreateSQL(self)
     other = findClass(self.foreignKey)
     tName = other._table
     idName = other._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
Ejemplo n.º 2
0
 def maxdbCreateSQL(self):
     from main import findClass
     other = findClass(self.foreignKey)
     fidName = self.dbName
     #I assume that foreign key name is identical to the id of the reference table
     sql = ' '.join([fidName, self._maxdbType()])
     tName = other._table
     idName  = other._idName
     sql=sql + ',' + '\n' 
     sql=sql + 'FOREIGN KEY (%s) REFERENCES %s(%s)'%(fidName,tName,idName)
     return sql
Ejemplo n.º 3
0
 def sybaseCreateSQL(self):
     from sqlobject.main import findClass
     sql = SOKeyCol.sybaseCreateSQL(self)
     other = findClass(self.foreignKey)
     tName = other._table
     idName = other._idName
     reference = ('REFERENCES %(tName)s(%(idName)s) ' %
                  {'tName':tName,
                   'idName':idName})
     sql = ' '.join([sql, reference])
     return sql