constraints = gen_constraints.toengine(table.engine)
column_constraints = gen_column_constraints.toengine(table.engine)
- s = columns.select(columns.c.table_name==table.name, order_by=[columns.c.ordinal_position])
-
- s.append_from(sql.join(columns, column_constraints,
- sql.and_(
- columns.c.table_name==column_constraints.c.table_name,
- columns.c.table_schema==column_constraints.c.table_schema,
- columns.c.column_name==column_constraints.c.column_name,
- ),
- isouter=True).join(constraints,
- sql.and_(
- column_constraints.c.table_schema==constraints.c.table_schema,
- column_constraints.c.constraint_name==constraints.c.constraint_name,
- constraints.c.constraint_type=='PRIMARY KEY'
- ), isouter=True)),
-
- s.append_column(constraints.c.constraint_type)
+ s = select([columns, constraints.c.constraint_type],
+ columns.c.table_name==table.name,
+ order_by=[columns.c.ordinal_position],
+ from_obj=[sql.join(columns, column_constraints,
+ sql.and_(
+ columns.c.table_name==column_constraints.c.table_name,
+ columns.c.table_schema==column_constraints.c.table_schema,
+ columns.c.column_name==column_constraints.c.column_name,
+ ),
+ isouter=True).join(constraints,
+ sql.and_(
+ column_constraints.c.table_schema==constraints.c.table_schema,
+ column_constraints.c.constraint_name==constraints.c.constraint_name,
+ constraints.c.constraint_type=='PRIMARY KEY'
+ ), isouter=True)])
if table.schema is not None:
s.append_whereclause(columns.c.table_schema==table.schema)
if c.rowcount != len(update):
raise "ConcurrencyError - updated rowcount %d does not match number of objects updated %d" % (c.cursor.rowcount, len(update))
if len(insert):
+ import sys
statement = table.insert()
for rec in insert:
(obj, params) = rec
if primary_keys is not None:
i = 0
for col in self.primary_keys[table]:
+ # print "col: " + table.name + "." + col.key + " val: " + repr(self._getattrbycolumn(obj, col))
if self._getattrbycolumn(obj, col) is None:
- self._setattrbycolumn(obj, col, primary_keys[i])
+ try:
+ self._setattrbycolumn(obj, col, primary_keys[i])
+ except IndexError:
+ print "LALALA col: " + table.name + "." + col.key + " val: " + repr(self._getattrbycolumn(obj, col))
+ raise
i+=1
self.extension.after_insert(self, obj)
s += "\n" + indent + " Save Dependencies:"
s += self._dump_dependencies(save_dep, indent)
if len(self.childtasks) > 0:
- s += "\n" + indent + " Child Tasks:"
+ s += "\n" + indent + " Child Tasks:(%d)" % len(self.childtasks)
for t in self.childtasks:
s += t.dump(indent + " ")
delete_dep = self.delete_dependencies()
raise NotImplementedError(repr(self))
def _get_from_objects(self):
raise NotImplementedError(repr(self))
+ def _process_from_dict(self, data):
+ for f in self._get_from_objects():
+ data[f.id] = f
+ data[self.id] = self
def accept_visitor(self, visitor):
raise NotImplementedError(repr(self))
visitor.visit_join(self)
engine = property(lambda s:s.left.engine or s.right.engine)
+
+ def _process_from_dict(self, data):
+ for f in self._get_from_objects():
+ data[f.id] = f
+ data[self.id] = self
def _get_from_objects(self):
m = {}
if type(fromclause) == str:
fromclause = FromClause(from_name = fromclause)
+ fromclause._process_from_dict(self.froms)
+ return
+
self.froms[fromclause.id] = fromclause
for r in fromclause._get_from_objects():
self.froms[r.id] = r
- def append_join(self, joinon, right, whereclause, **params):
- self.append_from(self.froms[joinon], right, whereclause, **params)
-
def append_clause(self, keyword, clause):
if type(clause) == str:
clause = TextClause(clause)
# now see, if the parent is an ancestor of the child
c = childnode
while c is not None and c is not parentnode:
+ root = c
c = c.parent
# nope, so we have to move the child down from whereever
# it currently is to a child of the parent
if c is None:
- parentnode.append(childnode)
+ for c in parentnode.children:
+ c.parent = root
+ root.children.append(c)
+ del parentnode.children[c]
+ root.parent = parentnode
+ parentnode.children.append(root)
+ print str(parentnode)
# now we have a collection of subtrees which represent dependencies.
# go through the collection root nodes wire them together into one tree
head = None
for node in nodes.values():
+ print "hi1:" + str(node)
if node.parent is None:
if head is not None:
head.append(node)
head = util.DependencySorter(tuples, [node7]).sort()
print "\n" + str(head)
+ def testsort3(self):
+ ['Mapper|Keyword|keywords,Mapper|IKAssociation|itemkeywords', 'Mapper|Item|items,Mapper|IKAssociation|itemkeywords']
+ node1 = thingy('keywords')
+ node2 = thingy('itemkeyowrds')
+ node3 = thingy('items')
+ tuples = [
+ (node1, node2),
+ (node3, node2)
+ ]
+ head1 = util.DependencySorter(tuples, [node1, node2, node3]).sort()
+ head2 = util.DependencySorter(tuples, [node3, node1, node2]).sort()
+ head3 = util.DependencySorter(tuples, [node3, node2, node1]).sort()
+
+ # TODO: figure out a "node == node2" function
+ #self.assert_(str(head1) == str(head2) == str(head3))
+ print "\n" + str(head1)
+ print "\n" + str(head2)
+ print "\n" + str(head3)
+ def testsort4(self):
+ node1 = thingy('keywords')
+ node2 = thingy('itemkeyowrds')
+ node3 = thingy('items')
+ node4 = thingy('lala')
+ node5 = thingy('hoho')
+
+ tuples = [
+ (node1, node2),
+ (node5, node3),
+ (node4, node2),
+ (node3, node2),
+
+ ]
+ head = util.DependencySorter(tuples, []).sort()
+ print "\n" + str(head)
if __name__ == "__main__":
unittest.main()
ECHO = testbase.echo
-#DBTYPE = 'sqlite_memory'
-DBTYPE = 'postgres'
+DBTYPE = 'sqlite_memory'
+#DBTYPE = 'postgres'
#DBTYPE = 'sqlite_file'
if DBTYPE == 'sqlite_memory':