def gen_default(cls, ctx):
return "hi"
+ class MyType(TypeDecorator):
+ impl = String(50)
+
+ def process_bind_param(self, value, dialect):
+ if value is not None:
+ value = "BIND" + value
+ return value
+
# select "count(1)" returns different results on different DBs also
# correct for "current_date" compatible as column default, value
# differences
server_default='ddl'),
# python method w/ context
- Column('col10', String(20), default=MyClass.gen_default)
+ Column('col10', String(20), default=MyClass.gen_default),
+
+ # fixed default w/ type that has bound processor
+ Column('col11', MyType(), default='foo')
)
t.create()
today = datetime.date.today()
eq_(l.fetchall(), [
(x, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, 'py', 'hi')
+ 12, today, 'py', 'hi', 'BINDfoo')
for x in range(51, 54)])
t.insert().execute(col9=None)
eq_(t.select(t.c.col1 == 54).execute().fetchall(),
[(54, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, None, 'hi')])
+ 12, today, None, 'hi', 'BINDfoo')])
def test_insertmany(self):
t.insert().execute({}, {}, {})
today = datetime.date.today()
eq_(l.fetchall(),
[(51, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, 'py', 'hi'),
+ 12, today, 'py', 'hi', 'BINDfoo'),
(52, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, 'py', 'hi'),
+ 12, today, 'py', 'hi', 'BINDfoo'),
(53, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, 'py', 'hi')])
+ 12, today, 'py', 'hi', 'BINDfoo')])
@testing.requires.multivalues_inserts
def test_insert_multivalues(self):
today = datetime.date.today()
eq_(l.fetchall(),
[(51, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, 'py', 'hi'),
+ 12, today, 'py', 'hi', 'BINDfoo'),
(52, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, 'py', 'hi'),
+ 12, today, 'py', 'hi', 'BINDfoo'),
(53, 'imthedefault', f, ts, ts, ctexec, True, False,
- 12, today, 'py', 'hi')])
+ 12, today, 'py', 'hi', 'BINDfoo')])
def test_no_embed_in_sql(self):
"""Using a DefaultGenerator, Sequence, DefaultClause
today = datetime.date.today()
eq_(l.fetchall(),
[(51, 'im the update', f2, ts, ts, ctexec, False, False,
- 13, today, 'py', 'hi'),
+ 13, today, 'py', 'hi', 'BINDfoo'),
(52, 'im the update', f2, ts, ts, ctexec, True, False,
- 13, today, 'py', 'hi'),
+ 13, today, 'py', 'hi', 'BINDfoo'),
(53, 'im the update', f2, ts, ts, ctexec, True, False,
- 13, today, 'py', 'hi')])
+ 13, today, 'py', 'hi', 'BINDfoo')])
@testing.fails_on('firebird', 'Data type unknown')
def test_update(self):
l = l.first()
eq_(l,
(pk, 'im the update', f2, None, None, ctexec, True, False,
- 13, datetime.date.today(), 'py', 'hi'))
+ 13, datetime.date.today(), 'py', 'hi', 'BINDfoo'))
eq_(11, f2)
@testing.fails_on('firebird', 'Data type unknown')
from sqlalchemy.dialects import mysql, postgresql
from sqlalchemy.engine import default
from sqlalchemy.testing import AssertsCompiledSQL,\
- assert_raises_message, fixtures
+ assert_raises_message, fixtures, eq_
from sqlalchemy.sql import crud
'foo_2': None # evaluated later
}
+ stmt = table.insert().values(values)
+
+ eq_(
+ dict([
+ (k, v.type._type_affinity)
+ for (k, v) in
+ stmt.compile(dialect=postgresql.dialect()).binds.items()]),
+ {
+ 'foo': Integer, 'data_2': String, 'id_0': Integer,
+ 'id_2': Integer, 'foo_1': Integer, 'data_1': String,
+ 'id_1': Integer, 'foo_2': Integer, 'data_0': String}
+ )
+
self.assert_compile(
- table.insert().values(values),
+ stmt,
'INSERT INTO sometable (id, data, foo) VALUES '
'(%(id_0)s, %(data_0)s, %(foo)s), '
'(%(id_1)s, %(data_1)s, %(foo_1)s), '
'foo_2': None, # evaluated later
}
+ stmt = table.insert().values(values)
+ eq_(
+ dict([
+ (k, v.type._type_affinity)
+ for (k, v) in
+ stmt.compile(dialect=postgresql.dialect()).binds.items()]),
+ {
+ 'foo': Integer, 'data_2': String, 'id_0': Integer,
+ 'id_2': Integer, 'foo_1': Integer, 'data_1': String,
+ 'id_1': Integer, 'foo_2': Integer, 'data_0': String}
+ )
+
self.assert_compile(
- table.insert().values(values),
+ stmt,
"INSERT INTO sometable (id, data, foo) VALUES "
"(%(id_0)s, %(data_0)s, %(foo)s), "
"(%(id_1)s, %(data_1)s, %(foo_1)s), "