merge_all.py

# Merge all tables

import fdb
from fbmerge import merge_table

con_A = fdb.connect(dsn='db1.fdb',user='sysdba',password='masterkey')
con_B = fdb.connect(dsn='db2.fdb',user='sysdba',password='masterkey')
con_final = fdb.connect(dsn='db3.fdb',user='sysdba',password='masterkey')

table_pk = """SELECT rc.RDB$RELATION_NAME, s.RDB$FIELD_NAME
     FROM RDB$INDEX_SEGMENTS s
LEFT JOIN RDB$RELATION_CONSTRAINTS rc ON rc.RDB$INDEX_NAME = s.RDB$INDEX_NAME
LEFT JOIN RDB$RELATIONS r on r.RDB$RELATION_NAME = rc.RDB$RELATION_NAME
WHERE rc.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY'
      AND r.RDB$SYSTEM_FLAG = 0"""

c = con_A.cursor()
c.execute(table_pk)
for (table_name, pk) in c:
    print "Merge", table_name
    merge_table(con_A, con_B, con_final, table_name, pk)

Previous topic

fbmerge.py

Next topic

fblog.py