Author: phd
Date: 2007-04-20 07:43:10 -0600 (Fri, 20 Apr 2007)
New Revision: 2571
Modified:
SQLObject/trunk/sqlobject/dbconnection.py
SQLObject/trunk/sqlobject/tests/test_joins_conditional.py
Log:
Fixed a bug with absent comma in JOINs.
Modified: SQLObject/trunk/sqlobject/dbconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/dbconnection.py 2007-04-20 13:42:42 UTC (rev 2570)
+++ SQLObject/trunk/sqlobject/dbconnection.py 2007-04-20 13:43:10 UTC (rev 2571)
@@ -476,7 +476,7 @@
if type(join) is str:
join_str = ' ' + join
elif isinstance(join, sqlbuilder.SQLJoin):
- if tables and join.table1:
+ if join.table1:
join_str = ", "
else:
join_str = ' '
@@ -484,11 +484,13 @@
else:
join_str = ""
for j in join:
- if tables and j.table1:
+ if j.table1:
sep = ", "
else:
sep = ' '
join_str += sep + self.sqlrepr(j)
+ if not tables and join_str.startswith(','):
+ join_str = join_str[1:].strip()
return join_str
def _addWhereClause(self, select, startSelect, limit=1, order=1):
Modified: SQLObject/trunk/sqlobject/tests/test_joins_conditional.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_joins_conditional.py 2007-04-20 13:42:42 UTC (rev 2570)
+++ SQLObject/trunk/sqlobject/tests/test_joins_conditional.py 2007-04-20 13:43:10 UTC (rev 2571)
@@ -41,7 +41,7 @@
on_condition=(TestJoin1.q.col1 == TestJoin2.q.col2))
)
assert str(select) == \
- "SELECT test_join1.id, test_join1.col1 FROM test_join1 LEFT JOIN test_join2 ON ((test_join1.col1) = (test_join2.col2)) WHERE 1 = 1"
+ "SELECT test_join1.id, test_join1.col1 FROM test_join1 LEFT JOIN test_join2 ON ((test_join1.col1) = (test_join2.col2)) WHERE 1 = 1"
def test_3perform_join():
setup()
@@ -76,6 +76,12 @@
assert str(select) == \
"SELECT test_join1.id, test_join1.col1 FROM test_join1 LEFT JOIN test_join2 LEFT JOIN test_join3 WHERE 1 = 1"
+ select = TestJoin1.select(
+ join=(LEFTJOIN(TestJoin1, TestJoin2), LEFTJOIN(TestJoin1, TestJoin3))
+ )
+ assert str(select) == \
+ "SELECT test_join1.id, test_join1.col1 FROM test_join1 LEFT JOIN test_join2, test_join1 LEFT JOIN test_join3 WHERE 1 = 1"
+
def test_6join_using():
setup()
setupClass(TestJoin3)
|