-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertion_script.py
50 lines (41 loc) · 1.38 KB
/
insertion_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import fdb
conn1 = fdb.connect(
host="host1", database='database1.fdb', user='user', password='pasw')
cur1 = conn_eg.cursor()
conn2 = fdb.connect(
host='host2', database='database2.fdb', user='user', password='pass')
# Cursor
cur2 = conn_sc.cursor()
cur_eg.execute("""SELECT column1,column2,
FROM table1 t1
JOIN table2 t2 ON t1.id=t2.id;""")
records = cur_eg.fetchall()
for r in records:
if str(r[2]) == '':
pass
else:
r1 = str(r[2])
cur_sc.execute("""SELECT * FROM table2 WHERE column1 = ?""", (r1[4:], ))
entry = cur_sc.fetchone()
if entry is None:
cur_sc.execute("""UPDATE OR INSERT INTO table3 (column1,column2)
VALUES (?,?) MATCHING (column1,column2);""",
(r1[4:], r[3]))
print("Added")
else:
print("Found entry")
if str(r[2]) == '':
r1 = str(r[2])
cur_sc.execute("""SELECT * FROM table3 WHERE object = ?""", (r[0],))
entry = cur_sc.fetchone()
if entry is None:
cur_sc.execute("""UPDATE OR INSERT INTO table3 (column1,column2)
VALUES (?,?) MATCHING (column1,column2);""",
(r1[4:], r[3]))
print("Added 1")
else:
print("Found entry 1")
conn1.commit()
conn2.commit()
conn1.close()
conn2.close()