-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDatabase.py
More file actions
36 lines (28 loc) · 920 Bytes
/
CreateDatabase.py
File metadata and controls
36 lines (28 loc) · 920 Bytes
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
import pyodbc
def InitalizedDB():
CreateDatabase(".\sqlCreateBusState.sql")
CreateStoredProcedures(".\sqlCreateStoredProcedures.sql")
return 0
def CreateDatabase(SQLFile):
executeScriptsFromFile(SQLFile)
return 0
def CreateStoredProcedures(SQLFile):
# executeScriptsFromFile(SQLFile)
return 0
def executeScriptsFromFile(filename):
# Open and read the file as a single buffer
conn = pyodbc.connect('DSN=BuswareLogs')
c = conn.cursor()
fd = open(filename, 'r')
sqlFile = fd.read()
fd.close()
# all SQL commands (split on ';')
sqlCommands = sqlFile.split(';')
# Execute every command from the input file
for command in sqlCommands:
# This will skip and report errors
# For example, if the tables do not yet exist, this will skip over
# the DROP TABLE commands
print(command)
c.execute(command)
c.close()