def __init__(self, column, _constraint=None, use_alter=False, name=None,
onupdate=None, ondelete=None, deferrable=None,
schema=None,
- initially=None, link_to_name=False):
+ initially=None, link_to_name=False, match=None):
"""
Construct a column-level FOREIGN KEY.
generated/dropped externally from the CREATE TABLE/ DROP TABLE
statement. See that classes' constructor for details.
+ :param match: Optional string. If set, emit MATCH <value> when issuing
+ DDL for this constraint. Typical values include SIMPLE, PARTIAL
+ and FULL.
+
"""
self._colspec = column
self.deferrable = deferrable
self.initially = initially
self.link_to_name = link_to_name
+ self.match = match
def __repr__(self):
return "ForeignKey(%r)" % self._get_colspec()
ondelete=self.ondelete,
deferrable=self.deferrable,
initially=self.initially,
- link_to_name=self.link_to_name
+ link_to_name=self.link_to_name,
+ match=self.match
)
fk.dispatch._update(self.dispatch)
return fk
[], [], use_alter=self.use_alter, name=self.name,
onupdate=self.onupdate, ondelete=self.ondelete,
deferrable=self.deferrable, initially=self.initially,
+ match=self.match,
)
self.constraint._elements[self.parent] = self
self.constraint._set_parent_with_dispatch(table)
def __init__(self, columns, refcolumns, name=None, onupdate=None,
ondelete=None, deferrable=None, initially=None, use_alter=False,
- link_to_name=False, table=None):
+ link_to_name=False, match=None, table=None):
"""Construct a composite-capable FOREIGN KEY.
:param columns: A sequence of local column names. The named columns
This is normally used to generate/drop constraints on objects that
are mutually dependent on each other.
+ :param match: Optional string. If set, emit MATCH <value> when issuing
+ DDL for this constraint. Typical values include SIMPLE, PARTIAL
+ and FULL.
+
"""
super(ForeignKeyConstraint, self).\
__init__(name, deferrable, initially)
if self.name is None and use_alter:
raise exc.ArgumentError("Alterable Constraint requires a name")
self.use_alter = use_alter
+ self.match = match
self._elements = util.OrderedDict()
onupdate=self.onupdate,
ondelete=self.ondelete,
use_alter=self.use_alter,
- link_to_name=self.link_to_name
+ link_to_name=self.link_to_name,
+ match=self.match
)
if table is not None:
use_alter=self.use_alter,
deferrable=self.deferrable,
initially=self.initially,
- link_to_name=self.link_to_name
+ link_to_name=self.link_to_name,
+ match=self.match
)
fkc.dispatch._update(self.dispatch)
return fkc
"(a) DEFERRABLE INITIALLY DEFERRED)",
)
+ def test_fk_match_clause(self):
+ t = Table('tbl', MetaData(),
+ Column('a', Integer),
+ Column('b', Integer,
+ ForeignKey('tbl.a', match="SIMPLE")))
+
+ self.assert_compile(
+ schema.CreateTable(t),
+ "CREATE TABLE tbl (a INTEGER, b INTEGER, "
+ "FOREIGN KEY(b) REFERENCES tbl "
+ "(a) MATCH SIMPLE)",
+ )
+
+ self.assert_compile(
+ schema.AddConstraint(list(t.foreign_keys)[0].constraint),
+ "ALTER TABLE tbl ADD FOREIGN KEY(b) "
+ "REFERENCES tbl (a) MATCH SIMPLE"
+ )
+
def test_deferrable_unique(self):
factory = lambda **kw: UniqueConstraint('b', **kw)
self._test_deferrable(factory)
)
c = CheckConstraint(t.c.a > t2.c.b)
assert c not in t.constraints
- assert c not in t2.constraints
\ No newline at end of file
+ assert c not in t2.constraints