-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_sql_queries.py
33 lines (30 loc) · 1.17 KB
/
delete_sql_queries.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
"""
delete_sql_queries is receiving file_path
file has lots of sql insert queries
it will process file content and generate
delete queries and write them in delete_queries.txt
"""
import re
def generate_sql_file(file_path):
table_lst = []
sql_file = open(file_path, "r").readlines()
for line in sql_file:
if line[0:6] == "INSERT":
tables = re.search("\(.*?\)", line).group()
tables = line.split(tables)
for table in range(len(tables)):
tables[table] = tables[table].replace(" ', '\n'", "")
tables[table] = tables[table].replace("INSERT INTO ", "")
if table == 1:
tables.remove(tables[table])
table_name = tables[0]
query = "DELETE FROM " + tables[0] +"WHERE id=;"
table_lst.append(query)
print(table_lst)
f=open('delete_queries.txt','w')
for t in table_lst:
f.write(t+'\n')
f.close()
if __name__ == "__main__":
file_path = "/home/ehab/uitestautomation/src/test/resources/db-scripts/accounting/vendorinvoice/setup-activate-add-journal-entry(S1).sql"
generate_sql_file(file_path)