[CalendarServer-changes] [9565] CalendarServer/branches/users/glyph/q
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 11 01:54:12 PDT 2012
Revision: 9565
http://trac.macosforge.org/projects/calendarserver/changeset/9565
Author: glyph at apple.com
Date: 2012-08-11 01:54:12 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
a failing test for insert/returning using sqlite
Modified Paths:
--------------
CalendarServer/branches/users/glyph/q/twext/enterprise/dal/syntax.py
CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/q/
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/syntax.py 2012-08-11 08:54:11 UTC (rev 9564)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/syntax.py 2012-08-11 08:54:12 UTC (rev 9565)
@@ -28,8 +28,9 @@
from twisted.internet.defer import succeed
from twext.enterprise.dal.model import Schema, Table, Column, Sequence
-from twext.enterprise.ienterprise import POSTGRES_DIALECT, ORACLE_DIALECT
-from twext.enterprise.ienterprise import IDerivedParameter
+from twext.enterprise.ienterprise import (
+ POSTGRES_DIALECT, ORACLE_DIALECT, SQLITE_DIALECT, IDerivedParameter
+)
from twext.enterprise.util import mapOracleOutputType
try:
@@ -1280,9 +1281,14 @@
@return: the C{stmt} parameter.
"""
retclause = self.Return
+ if retclause is None:
+ return stmt
if isinstance(retclause, (tuple, list)):
retclause = _CommaList(retclause)
- if retclause is not None:
+ if queryGenerator.dialect == SQLITE_DIALECT:
+ # sqlite does this another way.
+ return stmt
+ elif retclause is not None:
stmt.text += ' returning '
stmt.append(retclause.subSQL(queryGenerator, allTables))
if queryGenerator.dialect == ORACLE_DIALECT:
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py 2012-08-11 08:54:11 UTC (rev 9564)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py 2012-08-11 08:54:12 UTC (rev 9565)
@@ -30,7 +30,8 @@
from twext.enterprise.dal.syntax import Function
from twext.enterprise.dal.syntax import SchemaSyntax
from twext.enterprise.dal.test.test_parseschema import SchemaTestHelper
-from twext.enterprise.ienterprise import POSTGRES_DIALECT, ORACLE_DIALECT
+from twext.enterprise.ienterprise import (POSTGRES_DIALECT, ORACLE_DIALECT,
+ SQLITE_DIALECT)
from twext.enterprise.test.test_adbapi2 import ConnectionPoolHelper
from twext.enterprise.test.test_adbapi2 import NetworkedPoolHelper
from twext.enterprise.test.test_adbapi2 import resultOf
@@ -943,6 +944,43 @@
)
+ def test_insertMultiReturnSQLite(self):
+ """
+ In SQLite's SQL dialect, there is no 'returning' clause, but given that
+ SQLite serializes all SQL transactions, you can rely upon 'select'
+ after a write operation to reliably give you exactly what was just
+ modified. Therefore, although 'toSQL' won't include any indication of
+ the return value, the 'on' method will execute a 'select' statement
+ following the insert to retrieve the value.
+ """
+ insertStatement = Insert({self.schema.FOO.BAR: 39,
+ self.schema.FOO.BAZ: 82},
+ Return=(self.schema.FOO.BAR, self.schema.FOO.BAZ)
+ )
+ qg = lambda : QueryGenerator(SQLITE_DIALECT, NumericPlaceholder())
+ self.assertEquals(insertStatement.toSQL(qg()),
+ SQLFragment("insert into FOO (BAR, BAZ) values (:1, :2)",
+ [39, 82])
+ )
+ execed = []
+ counter = [0]
+ class CatchSQL(object):
+ dialect = SQLITE_DIALECT
+ paramstyle = 'numeric'
+ def execSQL(self, sql, args, rozrc):
+ execed.append([sql, args])
+ counter[0] += 1
+ return succeed(counter[0])
+ result = []
+ insertStatement.on(CatchSQL()).addCallback(result.append)
+ self.assertEqual(
+ execed,
+ [["insert into FOO (BAR, BAZ) values (:1, :2)", [39, 82]],
+ ["select BAR, BAZ from FOO where rowid = last_insert_rowid()"]]
+ )
+ self.assertEqual(result, [2])
+
+
def test_insertMismatch(self):
"""
L{Insert} raises L{TableMismatch} if the columns specified aren't all
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/a37d0e14/attachment.html>
More information about the calendarserver-changes
mailing list