On Thursday 09 August 2007 13:04:44 Paul Johnston wrote: > Hi, > > A little update; this code handles the case where columns have a > key attribute: > > model = __import__(sys.argv[1]) > if sys.argv[2] == 'copy': > seng = create_engine(sys.argv[3]) > deng = create_engine(sys.argv[4]) > for tbl in model.metadata.table_iterator(): > print tbl > mismatch = {} > for col in tbl.c: > if col.key != col.name: > mismatch[col.name] = col.key > def rewrite(x, mismatch): > x = dict(x) > for m in mismatch: > x[mismatch[m]] = x[m] > return x > deng.execute(tbl.insert(), [rewrite(x, mismatch) for x in > seng.execute(tbl.select())])
are u sure about the rewrite() part? x will contain both .key and .name with same values on them... wouldn't this be working equivalent? it also copes with empty tables.. ----------- def copy( metadata, src_engine, dst_engine, echo =False ): for tbl in metadata.table_iterator(): if echo: print tbl data = [ dict( (col.key, x[ col.name]) for col in tbl.c) for x in src_engine.execute( tbl.select()) ] if data: dst_engine.execute( tbl.insert(), data) if __name__ == '__main__': arg_model = sys.argv[1] model = import__( arg_model ) copy( model.metadata, src_engine= create_engine( sys.argv[2]), dst_engine= create_engine( sys.argv[3]), ) http://dbcook.svn.sourceforge.net/viewvc/*checkout*/dbcook/trunk/dbcook/misc/copydata.py there is also copyall.py (at same place) that does all in once (autoload + copydata): $ python copyall.py postgres://[EMAIL PROTECTED]/db1 sqlite:///db2 =========== i'm Wondering if all the unicode strings (at least table/column names) should be converted back into plain strings as they have been before autoload reflecting them from database. svil --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---