[SQL-CVS] r4457 - in SQLObject/trunk: docs sqlobject sqlobject/tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2011-09-26 19:01:18
|
Author: phd Date: Mon Sep 26 13:01:09 2011 New Revision: 4457 Log: Update allows string in WHERE. More tests. Modified: SQLObject/trunk/docs/News.txt SQLObject/trunk/docs/SQLBuilder.txt SQLObject/trunk/sqlobject/sqlbuilder.py SQLObject/trunk/sqlobject/tests/test_sqlbuilder.py Modified: SQLObject/trunk/docs/News.txt ============================================================================== --- SQLObject/trunk/docs/News.txt Sat Sep 24 09:47:26 2011 (r4456) +++ SQLObject/trunk/docs/News.txt Mon Sep 26 13:01:09 2011 (r4457) @@ -14,7 +14,7 @@ -------------------- * Strings are treated specially in Select to allow - Select(['id, 'name'], where='value = 42'). + Select(['id, 'name'], where='value = 42'). Update allows string in WHERE. * A bug caused by psycopg2 recently added a new boolean not callable autocommit attribute was fixed. Modified: SQLObject/trunk/docs/SQLBuilder.txt ============================================================================== --- SQLObject/trunk/docs/SQLBuilder.txt Sat Sep 24 09:47:26 2011 (r4456) +++ SQLObject/trunk/docs/SQLBuilder.txt Mon Sep 26 13:01:09 2011 (r4457) @@ -188,7 +188,7 @@ A dictionary {key: value}; keys are column names. Required. `where`: - An optional SQLExpression, represents the ``WHERE`` clause. + An optional string or SQLExpression, represents the ``WHERE`` clause. Example:: Modified: SQLObject/trunk/sqlobject/sqlbuilder.py ============================================================================== --- SQLObject/trunk/sqlobject/sqlbuilder.py Sat Sep 24 09:47:26 2011 (r4456) +++ SQLObject/trunk/sqlobject/sqlbuilder.py Mon Sep 26 13:01:09 2011 (r4457) @@ -769,7 +769,7 @@ update += "," update += " %s=%s" % (key, sqlrepr(value, db)) if self.whereClause is not NoDefault: - update += " WHERE %s" % sqlrepr(self.whereClause, db) + update += " WHERE %s" % _str_or_sqlrepr(self.whereClause, db) return update def sqlName(self): return "UPDATE" @@ -788,8 +788,7 @@ whereClause = self.whereClause if whereClause is None: return "DELETE FROM %s" % self.table - if isinstance(whereClause, SQLExpression): - whereClause = sqlrepr(whereClause, db) + whereClause = _str_or_sqlrepr(whereClause, db) return "DELETE FROM %s WHERE %s" % (self.table, whereClause) registerConverter(Delete, SQLExprConverter) Modified: SQLObject/trunk/sqlobject/tests/test_sqlbuilder.py ============================================================================== --- SQLObject/trunk/sqlobject/tests/test_sqlbuilder.py Sat Sep 24 09:47:26 2011 (r4456) +++ SQLObject/trunk/sqlobject/tests/test_sqlbuilder.py Mon Sep 26 13:01:09 2011 (r4457) @@ -44,3 +44,21 @@ where='value>0', orderBy='id', lazyColumns=True) assert sqlrepr(select, 'sqlite') == \ 'SELECT id FROM employees WHERE value>0 ORDER BY id' + + insert = Insert('employees', values={'id': 1, 'name': 'test'}) + assert sqlrepr(insert, 'sqlite') == \ + "INSERT INTO employees (id, name) VALUES (1, 'test')" + + update = Update('employees', {'name': 'test'}, where='id=1') + assert sqlrepr(update, 'sqlite') == \ + "UPDATE employees SET name='test' WHERE id=1" + + delete = Delete('employees', where='id=1') + assert sqlrepr(delete, 'sqlite') == \ + "DELETE FROM employees WHERE id=1" + + raises(TypeError, Delete, 'employees') + + delete = Delete('employees', where=None) + assert sqlrepr(delete, 'sqlite') == \ + "DELETE FROM employees" |