12 from rql import RQLHelper, nodes |
12 from rql import RQLHelper, nodes |
13 from logilab.common.compat import any |
13 from logilab.common.compat import any |
14 |
14 |
15 from cubicweb import Binary |
15 from cubicweb import Binary |
16 from cubicweb.rset import ResultSet |
16 from cubicweb.rset import ResultSet |
17 from cubicweb.goa import mx2datetime, datetime2mx |
|
18 from cubicweb.server import SQL_CONNECT_HOOKS |
17 from cubicweb.server import SQL_CONNECT_HOOKS |
19 |
18 |
20 from google.appengine.api.datastore import Key, Get, Query, Entity |
19 from google.appengine.api.datastore import Key, Get, Query, Entity |
21 from google.appengine.api.datastore_types import Text, Blob |
20 from google.appengine.api.datastore_types import Text, Blob |
22 from google.appengine.api.datastore_errors import EntityNotFoundError, BadKeyError |
21 from google.appengine.api.datastore_errors import EntityNotFoundError, BadKeyError |
248 class AttributeRestriction(RelationRestriction): |
247 class AttributeRestriction(RelationRestriction): |
249 supported_operators = ('=', '>', '>=', '<', '<=', 'ILIKE') |
248 supported_operators = ('=', '>', '>=', '<', '<=', 'ILIKE') |
250 def __init__(self, rel, kwargs): |
249 def __init__(self, rel, kwargs): |
251 RelationRestriction.__init__(self, rel, None) |
250 RelationRestriction.__init__(self, rel, None) |
252 value = self.rhs.eval(kwargs) |
251 value = self.rhs.eval(kwargs) |
253 if isinstance(value, (DateTimeType, DateTimeDeltaType)): |
|
254 #yamstype = self.schema.rschema(self.rtype).objects()[0] |
|
255 value = mx2datetime(value, 'Datetime') |
|
256 self.value = value |
252 self.value = value |
257 if self.operator == 'ILIKE': |
253 if self.operator == 'ILIKE': |
258 if value.startswith('%'): |
254 if value.startswith('%'): |
259 raise NotImplementedError('LIKE is only supported for prefix search') |
255 raise NotImplementedError('LIKE is only supported for prefix search') |
260 if not value.endswith('%'): |
256 if not value.endswith('%'): |
292 class AttributeInRestriction(AttributeRestriction): |
288 class AttributeInRestriction(AttributeRestriction): |
293 def __init__(self, rel, kwargs): |
289 def __init__(self, rel, kwargs): |
294 RelationRestriction.__init__(self, rel, None) |
290 RelationRestriction.__init__(self, rel, None) |
295 values = [] |
291 values = [] |
296 for c in self.rel.children[1].iget_nodes(nodes.Constant): |
292 for c in self.rel.children[1].iget_nodes(nodes.Constant): |
297 value = c.eval(kwargs) |
293 values.append(c.eval(kwargs)) |
298 if isinstance(value, (DateTimeType, DateTimeDeltaType)): |
|
299 #yamstype = self.schema.rschema(self.rtype).objects()[0] |
|
300 value = mx2datetime(value, 'Datetime') |
|
301 values.append(value) |
|
302 self.value = values |
294 self.value = values |
303 |
295 |
304 @property |
296 @property |
305 def operator(self): |
297 def operator(self): |
306 return 'in' |
298 return 'in' |
320 return objs |
312 return objs |
321 |
313 |
322 |
314 |
323 def append_result(res, descr, i, j, value, etype): |
315 def append_result(res, descr, i, j, value, etype): |
324 if value is not None: |
316 if value is not None: |
325 if etype in ('Date', 'Datetime', 'Time'): |
317 if isinstance(value, Text): |
326 value = datetime2mx(value, etype) |
|
327 elif isinstance(value, Text): |
|
328 value = unicode(value) |
318 value = unicode(value) |
329 elif isinstance(value, Blob): |
319 elif isinstance(value, Blob): |
330 value = Binary(str(value)) |
320 value = Binary(str(value)) |
331 if j == 0: |
321 if j == 0: |
332 res.append([value]) |
322 res.append([value]) |