-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
executable file
·69 lines (53 loc) · 1.62 KB
/
db.py
File metadata and controls
executable file
·69 lines (53 loc) · 1.62 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from dbConnect import *
import time
start_time = time.time()
SCHEMA = "AirlineTrackingSystem"
filesToRead = [
"sql/_CREATE_TABLE.sql",
"sql/country.sql",
"sql/airport.sql",
"sql/airline.sql",
"sql/flight.sql",
"sql/airVehicle.sql",
"sql/fliesOn.sql",
"sql/status.sql",
"sql/flightStatus.sql",
]
connection = db_connect()
# Dropping the whole schema for testing purposes
# cursor = connection.cursor()
# cursor.execute("DROP SCHEMA IF EXISTS \"" + SCHEMA + "\" CASCADE")
# connection.commit()
# cursor.close()
total_text = ""
total_counter = 0
for file in filesToRead:
cursor = connection.cursor()
counter = 0
cursor.execute("SET search_path = \"" + SCHEMA + "\", pg_catalog;")
connection.commit()
query = ""
for row in open(file, "r", encoding='utf8'):
row = row.replace("\n", "")
if row == "" or row.startswith("# ") or row.startswith("--"):
continue
query += row
if row.endswith(";"):
query = query.replace("\n", " ")
print("%s: %s" % (counter, query))
cursor.execute(query)
query = ""
counter += 1
connection.commit()
cursor.close()
total_counter += counter
text = "Operations in '" + str(file) + "': " + str(counter) + "\n"
total_text += text
print(text)
counter = 0
connection.close()
print("==========================")
print(total_text)
print("Total operations: " + str(total_counter))
end_time = time.time()
print("Total time: %.2f mins" % ((end_time - start_time)/60))