- sql
+ - the "shortname" keyword parameter on bindparam() has been
+ deprecated.
+
- Added contains operator (generates a "LIKE %<other>%" clause).
- Removed regular expression step from most statement compilations.
if should_bind(leftcol, rightcol):
col = leftcol
binary.left = binds.setdefault(leftcol,
- sql.bindparam(None, None, shortname=leftcol.name, type_=binary.right.type, unique=True))
+ sql.bindparam(None, None, type_=binary.right.type, unique=True))
reverse[rightcol] = binds[col]
# the "left is not right" compare is to handle part of a join clause that is "table.c.col1==table.c.col1",
if leftcol is not rightcol and should_bind(rightcol, leftcol):
col = rightcol
binary.right = binds.setdefault(rightcol,
- sql.bindparam(None, None, shortname=rightcol.name, type_=binary.left.type, unique=True))
+ sql.bindparam(None, None, type_=binary.left.type, unique=True))
reverse[leftcol] = binds[col]
lazywhere = primaryjoin
def visit_bindparam(self, bindparam, **kwargs):
# apply truncation to the ultimate generated name
- if bindparam.shortname != bindparam.key:
- self.binds.setdefault(bindparam.shortname, bindparam)
-
if bindparam.unique:
count = 1
key = bindparam.key
return TableClause(name, *columns)
-def bindparam(key, value=None, type_=None, shortname=None, unique=False):
+def bindparam(key, value=None, shortname=None, type_=None, unique=False):
"""Create a bind parameter clause with the given key.
value
a default value for this bind parameter. a bindparam with a
value is called a ``value-based bindparam``.
- shortname
- an ``alias`` for this bind parameter. usually used to alias the
- ``key`` nd ``label`` of a column, i.e. ``somecolname`` and
- ``sometable_somecolname``
-
type
a sqlalchemy.types.TypeEngine object indicating the type of this
bind param, will invoke type-specific bind parameter processing
+ shortname
+ deprecated.
+
unique
if True, bind params sharing the same name will have their
underlying ``key`` modified to a uniquely generated name.
"""
if isinstance(key, _ColumnClause):
- return _BindParamClause(key.name, value, type_=key.type, shortname=shortname, unique=unique)
+ return _BindParamClause(key.name, value, type_=key.type, unique=unique, shortname=shortname)
else:
- return _BindParamClause(key, value, type_=type_, shortname=shortname, unique=unique)
+ return _BindParamClause(key, value, type_=type_, unique=unique, shortname=shortname)
def outparam(key, type_=None):
"""Create an 'OUT' parameter for usage in functions (stored procedures), for databases which support them.
if element is None:
return null()
else:
- return _BindParamClause(name, element, shortname=name, type_=type_, unique=True)
+ return _BindParamClause(name, element, type_=type_, unique=True)
else:
return element
return lambda other: self.__operate(operator, other)
def _bind_param(self, obj):
- return _BindParamClause('literal', obj, shortname=None, type_=self.type, unique=True)
+ return _BindParamClause('literal', obj, type_=self.type, unique=True)
def _check_literal(self, other):
if isinstance(other, Operators):
__visit_name__ = 'bindparam'
- def __init__(self, key, value, shortname=None, type_=None, unique=False, isoutparam=False):
+ def __init__(self, key, value, type_=None, unique=False, isoutparam=False, shortname=None):
"""Construct a _BindParamClause.
key
compilation/execution.
shortname
- Defaults to the key, a *short name* that will also identify
- this bind parameter, similar to an alias. the bind
- parameter keys sent to a statement compilation or compiled
- execution may match either the key or the shortname of the
- corresponding ``_BindParamClause`` objects.
-
+ deprecated.
+
type\_
A ``TypeEngine`` object that will be used to pre-process the
value corresponding to this ``_BindParamClause`` at
self.key = key or "{ANON %d param}" % id(self)
self.value = value
- self.shortname = shortname or key
self.unique = unique
self.isoutparam = isoutparam
-
+ self.shortname = shortname
+
if type_ is None:
self.type = self.type_map.get(type(value), sqltypes.NullType)()
elif isinstance(type_, type):
return []
def _bind_param(self, obj):
- return _BindParamClause(self._label, obj, shortname=self.name, type_=self.type, unique=True)
+ return _BindParamClause(self._label, obj, type_=self.type, unique=True)
def _make_proxy(self, selectable, name = None):
# propigate the "is_literal" flag only if we are keeping our name,
except exceptions.AssertionError, e:
assert str(e).startswith("Dependency rule tried to blank-out primary key column 'B.id' on instance ")
- def test_no_nullPK_sBtoA(self):
+ def test_no_nullPK_BtoA(self):
class A(object):pass
class B(object):pass
mapper(B, tableB, properties={
except exceptions.AssertionError, e:
assert str(e).startswith("Dependency rule tried to blank-out primary key column 'B.id' on instance ")
- def test_nullPKsOK_sBtoA(self):
+ @testing.supported('sqlite', 'mysql')
+ def test_nullPKsOK_BtoA(self):
+ # postgres cant handle a nullable PK column...?
+ tableC = Table('tablec', tableA.metadata,
+ Column('id', Integer, primary_key=True),
+ Column('a_id', Integer, ForeignKey('A.id'), primary_key=True, autoincrement=False, nullable=True))
+ tableC.create()
+
class A(object):pass
- class B(object):pass
- mapper(B, tableB, properties={
+ class C(object):pass
+ mapper(C, tableC, properties={
'a':relation(A, cascade="save-update")
}, allow_null_pks=True)
mapper(A, tableA)
- b1 = B()
- b1.a = None
+ c1 = C()
+ c1.id = 5
+ c1.a = None
sess = create_session()
- sess.save(b1)
+ sess.save(c1)
+ # test that no error is raised.
sess.flush()
def test_delete_cascade_BtoA(self):
self.assert_compile(update(table1, table1.c.myid == 7), "UPDATE mytable SET name=:name WHERE mytable.myid = :mytable_myid", params = {table1.c.name:'fred'})
self.assert_compile(update(table1, table1.c.myid == 7), "UPDATE mytable SET name=:name WHERE mytable.myid = :mytable_myid", params = {'name':'fred'})
self.assert_compile(update(table1, values = {table1.c.name : table1.c.myid}), "UPDATE mytable SET name=mytable.myid")
- self.assert_compile(update(table1, whereclause = table1.c.name == bindparam('crit'), values = {table1.c.name : 'hi'}), "UPDATE mytable SET name=:name WHERE mytable.name = :crit", params = {'crit' : 'notthere'})
- self.assert_compile(update(table1, table1.c.myid == 12, values = {table1.c.name : table1.c.myid}), "UPDATE mytable SET name=mytable.myid, description=:description WHERE mytable.myid = :mytable_myid", params = {'description':'test'})
+ self.assert_compile(update(table1, whereclause = table1.c.name == bindparam('crit'), values = {table1.c.name : 'hi'}), "UPDATE mytable SET name=:name WHERE mytable.name = :crit", params = {'crit' : 'notthere'}, checkparams={'crit':'notthere', 'name':'hi'})
+ self.assert_compile(update(table1, table1.c.myid == 12, values = {table1.c.name : table1.c.myid}), "UPDATE mytable SET name=mytable.myid, description=:description WHERE mytable.myid = :mytable_myid", params = {'description':'test'}, checkparams={'description':'test', 'mytable_myid':12})
self.assert_compile(update(table1, table1.c.myid == 12, values = {table1.c.myid : 9}), "UPDATE mytable SET myid=:myid, description=:description WHERE mytable.myid = :mytable_myid", params = {'mytable_myid': 12, 'myid': 9, 'description': 'test'})
+ self.assert_compile(update(table1, table1.c.myid ==12), "UPDATE mytable SET myid=:myid WHERE mytable.myid = :mytable_myid", params={'myid':18}, checkparams={'myid':18, 'mytable_myid':12})
s = table1.update(table1.c.myid == 12, values = {table1.c.name : 'lala'})
c = s.compile(column_keys=['mytable_id', 'name'])
self.assert_compile(update(table1, table1.c.myid == 12, values = {table1.c.name : table1.c.myid}).values({table1.c.name:table1.c.name + 'foo'}), "UPDATE mytable SET name=(mytable.name || :mytable_name), description=:description WHERE mytable.myid = :mytable_myid", params = {'description':'test'})
self.assert_(cc == result, "\n'" + cc + "'\n does not match \n'" + result + "'")
if checkparams is not None:
- self.assert_(c.params == checkparams, "params dont match" + repr(c.params))
+ self.assert_(c.construct_params(params) == checkparams, "params dont match" + repr(c.params))
class AssertMixin(PersistTest):
"""given a list-based structure of keys/properties which represent information within an object structure, and