summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-09-04 00:08:57 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-09-04 00:08:57 +0000
commit3126d464e7124cde24b18ba7efc318913d2ac40d (patch)
tree33dd8fdda1ea8a3aae5c75cfbbdded60a1b01997 /test
parentc9924a4a145f06eac427fe60c54d4c58b894167f (diff)
downloadsqlalchemy-3126d464e7124cde24b18ba7efc318913d2ac40d.tar.gz
- removed "parameters" argument from clauseelement.compile(), replaced with
"column_keys". the parameters sent to execute() only interact with the insert/update statement compilation process in terms of the column names present but not the values for those columns. produces more consistent execute/executemany behavior, simplifies things a bit internally.
Diffstat (limited to 'test')
-rw-r--r--test/sql/query.py20
-rw-r--r--test/sql/select.py18
-rw-r--r--test/testlib/testing.py9
3 files changed, 26 insertions, 21 deletions
diff --git a/test/sql/query.py b/test/sql/query.py
index 4e68fb980..a519dd974 100644
--- a/test/sql/query.py
+++ b/test/sql/query.py
@@ -32,6 +32,14 @@ class QueryTest(PersistTest):
users.insert().execute(user_id = 7, user_name = 'jack')
assert users.count().scalar() == 1
+ def test_insert_heterogeneous_params(self):
+ users.insert().execute(
+ {'user_id':7, 'user_name':'jack'},
+ {'user_id':8, 'user_name':'ed'},
+ {'user_id':9}
+ )
+ assert users.select().execute().fetchall() == [(7, 'jack'), (8, 'ed'), (9, None)]
+
def testupdate(self):
users.insert().execute(user_id = 7, user_name = 'jack')
@@ -353,9 +361,9 @@ class QueryTest(PersistTest):
)
meta.create_all()
try:
- t.insert().execute(value=func.length("one"))
+ t.insert(values=dict(value=func.length("one"))).execute()
assert t.select().execute().fetchone()['value'] == 3
- t.update().execute(value=func.length("asfda"))
+ t.update(values=dict(value=func.length("asfda"))).execute()
assert t.select().execute().fetchone()['value'] == 5
r = t.insert(values=dict(value=func.length("sfsaafsda"))).execute()
@@ -363,14 +371,14 @@ class QueryTest(PersistTest):
assert t.select(t.c.id==id).execute().fetchone()['value'] == 9
t.update(values={t.c.value:func.length("asdf")}).execute()
assert t.select().execute().fetchone()['value'] == 4
-
+ print "--------------------------"
t2.insert().execute()
- t2.insert().execute(value=func.length("one"))
- t2.insert().execute(value=func.length("asfda") + -19, stuff="hi")
+ t2.insert(values=dict(value=func.length("one"))).execute()
+ t2.insert(values=dict(value=func.length("asfda") + -19)).execute(stuff="hi")
assert select([t2.c.value, t2.c.stuff]).execute().fetchall() == [(7,None), (3,None), (-14,"hi")]
- t2.update().execute(value=func.length("asdsafasd"), stuff="some stuff")
+ t2.update(values=dict(value=func.length("asdsafasd"))).execute(stuff="some stuff")
assert select([t2.c.value, t2.c.stuff]).execute().fetchall() == [(9,"some stuff"), (9,"some stuff"), (9,"some stuff")]
t2.delete().execute()
diff --git a/test/sql/select.py b/test/sql/select.py
index 5eaea7480..edca33bc0 100644
--- a/test/sql/select.py
+++ b/test/sql/select.py
@@ -567,10 +567,9 @@ WHERE mytable.myid = myothertable.otherid) AS t2view WHERE t2view.mytable_myid =
def testtextbinds(self):
self.assert_compile(
- text("select * from foo where lala=:bar and hoho=:whee"),
+ text("select * from foo where lala=:bar and hoho=:whee", bindparams=[bindparam('bar', 4), bindparam('whee', 7)]),
"select * from foo where lala=:bar and hoho=:whee",
checkparams={'bar':4, 'whee': 7},
- params={'bar':4, 'whee': 7, 'hoho':10},
)
self.assert_compile(
@@ -582,10 +581,9 @@ WHERE mytable.myid = myothertable.otherid) AS t2view WHERE t2view.mytable_myid =
dialect = postgres.dialect()
self.assert_compile(
- text("select * from foo where lala=:bar and hoho=:whee"),
+ text("select * from foo where lala=:bar and hoho=:whee", bindparams=[bindparam('bar',4), bindparam('whee',7)]),
"select * from foo where lala=%(bar)s and hoho=%(whee)s",
checkparams={'bar':4, 'whee': 7},
- params={'bar':4, 'whee': 7, 'hoho':10},
dialect=dialect
)
self.assert_compile(
@@ -598,10 +596,9 @@ WHERE mytable.myid = myothertable.otherid) AS t2view WHERE t2view.mytable_myid =
dialect = sqlite.dialect()
self.assert_compile(
- text("select * from foo where lala=:bar and hoho=:whee"),
+ text("select * from foo where lala=:bar and hoho=:whee", bindparams=[bindparam('bar',4), bindparam('whee',7)]),
"select * from foo where lala=? and hoho=?",
checkparams=[4, 7],
- params={'bar':4, 'whee': 7, 'hoho':10},
dialect=dialect
)
@@ -936,11 +933,6 @@ EXISTS (select yay from foo where boo = lar)",
except exceptions.CompileError, err:
assert str(err) == "Bind parameter 'mytable_myid_1' conflicts with unique bind parameter of the same name"
- # check that the bind params sent along with a compile() call
- # get preserved when the params are retreived later
- s = select([table1], table1.c.myid == bindparam('test'))
- c = s.compile(parameters = {'test' : 7})
- self.assert_(c.get_params().get_original_dict() == {'test' : 7})
def testbindascol(self):
t = table('foo', column('id'))
@@ -1134,7 +1126,7 @@ class CRUDTest(SQLCompileTest):
self.assert_compile(table.insert(inline=True), "INSERT INTO sometable (foo) VALUES (foobar())", params={})
def testinsertexpression(self):
- self.assert_compile(insert(table1), "INSERT INTO mytable (myid) VALUES (lala())", params=dict(myid=func.lala()))
+ self.assert_compile(insert(table1, values=dict(myid=func.lala())), "INSERT INTO mytable (myid) VALUES (lala())")
def testupdate(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'})
@@ -1144,7 +1136,7 @@ class CRUDTest(SQLCompileTest):
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, 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'})
s = table1.update(table1.c.myid == 12, values = {table1.c.name : 'lala'})
- c = s.compile(parameters = {'mytable_id':9,'name':'h0h0'})
+ 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_(str(s) == str(c))
diff --git a/test/testlib/testing.py b/test/testlib/testing.py
index 0038fddfe..26873b25f 100644
--- a/test/testlib/testing.py
+++ b/test/testlib/testing.py
@@ -211,8 +211,13 @@ class SQLCompileTest(PersistTest):
def assert_compile(self, clause, result, params=None, checkparams=None, dialect=None):
if dialect is None:
dialect = getattr(self, '__dialect__', None)
-
- c = clause.compile(parameters=params, dialect=dialect)
+
+ if params is None:
+ keys = None
+ else:
+ keys = params.keys()
+
+ c = clause.compile(column_keys=keys, dialect=dialect)
print "\nSQL String:\n" + str(c) + repr(c.get_params())