[CalendarServer-changes] [6771] CalendarServer/branches/users/glyph/dal/txdav/base/datastore
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jan 19 12:58:23 PST 2011
Revision: 6771
http://trac.macosforge.org/projects/calendarserver/changeset/6771
Author: glyph at apple.com
Date: 2011-01-19 12:58:23 -0800 (Wed, 19 Jan 2011)
Log Message:
-----------
pluggable quoting / placeholder support, for different paramstyles
Modified Paths:
--------------
CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlsyntax.py
CalendarServer/branches/users/glyph/dal/txdav/base/datastore/test/test_sqlsyntax.py
Modified: CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlsyntax.py
===================================================================
--- CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlsyntax.py 2011-01-19 20:58:12 UTC (rev 6770)
+++ CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlsyntax.py 2011-01-19 20:58:23 UTC (rev 6771)
@@ -94,8 +94,8 @@
self.b = b
- def toSQL(self):
- return (' '.join([self.a, self.op, '?']), [self.b])
+ def toSQL(self, placeholder, quote):
+ return (' '.join([self.a, self.op, placeholder]), [self.b])
@@ -109,15 +109,15 @@
self.Where = Where
- def toSQL(self):
+ def toSQL(self, placeholder="?", quote=lambda x: x):
"""
@return: a 2-tuple of (sql, args).
"""
- sql = "select * from " + self.From.model.name
+ sql = quote("select * from ") + self.From.model.name
args = []
if self.Where is not None:
- moreSQL, moreArgs = self.Where.toSQL()
- sql += (" where " + moreSQL)
+ moreSQL, moreArgs = self.Where.toSQL(placeholder, quote)
+ sql += (quote(" where ") + moreSQL)
args.extend(moreArgs)
return (sql, args)
Modified: CalendarServer/branches/users/glyph/dal/txdav/base/datastore/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/branches/users/glyph/dal/txdav/base/datastore/test/test_sqlsyntax.py 2011-01-19 20:58:12 UTC (rev 6770)
+++ CalendarServer/branches/users/glyph/dal/txdav/base/datastore/test/test_sqlsyntax.py 2011-01-19 20:58:23 UTC (rev 6771)
@@ -30,13 +30,14 @@
s = Schema(self.id())
addSQLToSchema(schema=s, schemaData="""
create table FOO (BAR integer);
+ create table BAZ (QUX integer);
""")
self.schema = SchemaSyntax(s)
def test_simplestSelect(self):
"""
- L{Select} will generate a 'select' statement, by default, asking for all
+ L{Select} generates a 'select' statement, by default, asking for all
rows in a table.
"""
self.assertEquals(Select(From=self.schema.FOO).toSQL(),
@@ -45,10 +46,23 @@
def test_simpleWhereClause(self):
"""
- L{Select} will generate a 'select' statement with a 'where' clause
+ L{Select} generates a 'select' statement with a 'where' clause
containing an expression.
"""
self.assertEquals(Select(From=self.schema.FOO,
Where=self.schema.FOO.BAR == 1).toSQL(),
("select * from FOO where BAR = ?", [1]))
+
+ def test_quotingAndPlaceholder(self):
+ """
+ L{Select} generates a 'select' statement with the specified placeholder
+ syntax and quoting function.
+ """
+
+ self.assertEquals(Select(From=self.schema.FOO,
+ Where=self.schema.FOO.BAR == 1).toSQL(
+ placeholder="*",
+ quote=lambda partial: partial.replace("*", "**")),
+ ("select ** from FOO where BAR = *", [1]))
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110119/17012629/attachment-0001.html>
More information about the calendarserver-changes
mailing list