[CalendarServer-changes] [8782] CalendarServer/branches/users/glyph/case-insensitive-uid
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 29 10:15:25 PST 2012
Revision: 8782
http://trac.macosforge.org/projects/calendarserver/changeset/8782
Author: glyph at apple.com
Date: 2012-02-29 10:15:25 -0800 (Wed, 29 Feb 2012)
Log Message:
-----------
support for anonymous check constraints, more explicit static SQL generation
Modified Paths:
--------------
CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_tables.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/case-insensitive-uid/
Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_tables.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_tables.py 2012-02-29 18:15:21 UTC (rev 8781)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_tables.py 2012-02-29 18:15:25 UTC (rev 8782)
@@ -295,24 +295,40 @@
continue # already done inline, skip
writeConstraint("unique", uniqueColumns)
- out.write('\n);\n\n')
-
- fakeQueryGenerator = QueryGenerator(ORACLE_DIALECT, FixedPlaceholder('%s'))
def quoted(x):
if isinstance(x, (str, unicode)):
return ''.join(["'", x.replace("'", "''"), "'"])
else:
return str(x)
+ def staticSQL(sql, doquote=False):
+ qgen = QueryGenerator(ORACLE_DIALECT, FixedPlaceholder('%s'))
+ if doquote:
+ qgen.shouldQuote = lambda name: True
+ if hasattr(sql, 'subSQL'):
+ fragment = sql.subSQL(qgen, [])
+ else:
+ fragment = sql.toSQL(qgen)
+ params = tuple([quoted(param) for param in fragment.parameters])
+ result = fragment.text % params
+ return result
+
+ for checkConstraint in table.model.constraints:
+ if checkConstraint.type == 'CHECK':
+ out.write(", \n")
+
+ out.write(" check(%s)" %
+ (staticSQL(checkConstraint.expression, True)))
+
+ out.write('\n);\n\n')
+
for row in table.model.schemaRows:
cmap = dict(
[(getattr(table, cmodel.name), val)
for (cmodel, val) in row.items()]
)
- fragment = Insert(cmap).toSQL(fakeQueryGenerator)
out.write(
- fragment.text % tuple([quoted(param)
- for param in fragment.parameters]),
+ staticSQL(Insert(cmap))
)
out.write(";\n")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120229/730b9761/attachment.html>
More information about the calendarserver-changes
mailing list