[CalendarServer-changes] [6765] CalendarServer/branches/users/glyph/dal/txdav/base/datastore
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jan 19 12:57:20 PST 2011
Revision: 6765
http://trac.macosforge.org/projects/calendarserver/changeset/6765
Author: glyph at apple.com
Date: 2011-01-19 12:57:19 -0800 (Wed, 19 Jan 2011)
Log Message:
-----------
Make sequence test pass.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlmodel.py
CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlparser.py
Modified: CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlmodel.py
===================================================================
--- CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlmodel.py 2011-01-19 20:57:09 UTC (rev 6764)
+++ CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlmodel.py 2011-01-19 20:57:19 UTC (rev 6765)
@@ -92,7 +92,7 @@
def setDefaultValue(self, value):
- self.defaultValue = value
+ self.default = value
def doesReferenceName(self, name):
@@ -150,6 +150,7 @@
self.descriptiveComment = comment
+
class Sequence(object):
"""
A sequence object.
@@ -164,6 +165,7 @@
return '<Sequence %r>' % (self.name,)
+
class Schema(object):
"""
A schema containing tables, indexes, and sequences.
@@ -185,3 +187,12 @@
return table
raise KeyError(name)
+
+ def sequenceNamed(self, name):
+ for sequence in self.sequences:
+ if sequence.name == name:
+ return sequence
+ raise KeyError(name)
+
+
+
Modified: CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlparser.py
===================================================================
--- CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlparser.py 2011-01-19 20:57:09 UTC (rev 6764)
+++ CalendarServer/branches/users/glyph/dal/txdav/base/datastore/sqlparser.py 2011-01-19 20:57:19 UTC (rev 6765)
@@ -14,6 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
+
+"""
+Parser for SQL schema.
+"""
+
from itertools import chain
from sqlparse import parse, keywords
@@ -34,6 +39,8 @@
_fixKeywords()
+
+
def tableFromCreateStatement(schema, stmt):
i = iterSignificant(stmt)
expect(i, ttype=Keyword.DDL, value='CREATE')
@@ -48,6 +55,7 @@
return self
+
def schemaFromPath(path):
schema = Schema(path.basename())
schemaData = path.getContent()
@@ -204,13 +212,25 @@
# XXX add NOT NULL constraint
pass
elif val.match(Keyword, 'DEFAULT'):
- one = self.next()
- two = self.next()
- if isinstance(two, Parenthesis):
- defaultValue = ProcedureCall(one.value, two)
+ theDefault = self.next()
+ if isinstance(theDefault, Function):
+ thingo = theDefault.tokens[0].get_name()
+ parens = expectSingle(
+ theDefault.tokens[-1], cls=Parenthesis
+ )
+ pareniter = iterSignificant(parens)
+ if thingo.upper() == 'NEXTVAL':
+ expect(pareniter, ttype=Punctuation, value="(")
+ seqname = _destringify(
+ expect(pareniter, ttype=String.Single).value)
+ defaultValue = self.table.schema.sequenceNamed(
+ seqname
+ )
+ defaultValue.referringColumns.append(theColumn)
+ else:
+ defaultValue = ProcedureCall(thingo, parens)
else:
- self.pushback(two)
- defaultValue = one.value
+ raise RuntimeError("not sure what to do")
theColumn.setDefaultValue(defaultValue)
elif val.match(Keyword, 'REFERENCES'):
target = nameOrIdentifier(self.next())
@@ -230,7 +250,6 @@
-
class ViolatedExpectation(Exception):
def __init__(self, expected, got):
@@ -259,13 +278,13 @@
if cls is not None:
if nextval.__class__ != cls:
raise ViolatedExpectation(cls, repr(nextval))
+ return nextval
def expect(iterator, **kw):
nextval = iterator.next()
- expectSingle(nextval, **kw)
- return nextval
+ return expectSingle(nextval, **kw)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110119/e26554fe/attachment-0001.html>
More information about the calendarserver-changes
mailing list