- q = ("select distinct n.path, v.serial "
- "from attributes a, versions v, nodes n "
- "where v.serial = (select max(serial) "
- "from versions "
- "where node = v.node and mtime < ?) "
- "and v.cluster != ? "
- "and v.node in (select node "
- "from nodes "
- "where parent = ?) "
- "and a.serial = v.serial "
- "and n.node = v.node "
- "and n.path > ? and n.path < ?")
- args = [before, except_cluster, parent, start, nextling]
-
- subq, subargs = self._construct_paths(pathq)
- if subq is not None:
- q += subq
- args += subargs
- subq, subargs = self._construct_filters(filterq)
- if subq is not None:
- q += subq
- args += subargs
- else:
- q = q.replace("attributes a, ", "")
- q = q.replace("and a.serial = v.serial ", "")
- q += " order by n.path"
+ a = self.attributes.alias('a')
+ v = self.versions.alias('v')
+ n = self.nodes.alias('n')
+ s = select([n.c.path, v.c.serial]).distinct()
+ s = s.where(v.c.serial == select([func.max(self.versions.c.serial)],
+ and_(self.versions.c.node == v.c.node,
+ self.versions.c.mtime < before)))
+ s = s.where(v.c.cluster != except_cluster)
+ s = s.where(v.c.node.in_(select([self.nodes.c.node],
+ self.nodes.c.parent == parent)))
+ if filterq:
+ s = s.where(a.c.serial == v.c.serial)
+
+ s = s.where(n.c.node == v.c.node)
+ s = s.where(and_(n.c.path > bindparam('start'), n.c.path < nextling))
+ conj = []
+ for x in pathq:
+ print '#', x
+ conj.append(n.c.path.like(x + '%'))
+
+ if conj:
+ s = s.where(or_(*conj))
+
+ if filterq:
+ s = s.where(a.c.key.in_(filterq.split(',')))
+
+ s = s.order_by(n.c.path)