-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (38 loc) · 1.38 KB
/
Copy pathmain.py
File metadata and controls
44 lines (38 loc) · 1.38 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
from db_importing import import_from_db
from sql_parsing import parse_sql
from table_management import execute_statement
project_name = 'Prime SGBD'
print('Running {0}...'.format(project_name))
print('Type \'help\' for command options.\n')
in_str = input('> ')
while in_str :
in_list = in_str.split()
if in_list[0] == 'help' :
print('help *: List all available commands.')
print('quit *: Quit the application.')
print('import <server> <user> <password> <database>: Import tables from database.')
print('sql <statement>: Execute SQL statement.')
elif in_list[0] == 'quit' :
break
elif in_list[0] == 'import' :
try :
import_from_db(in_list[1], in_list[2], in_list[3], in_list[4])
except Exception :
print('Error: could not import!')
elif in_list[0] == 'sql' :
try :
parsed_statement = parse_sql(in_str[4:])
if parsed_statement[0] == 'ERROR' :
print('Error: could not parse!')
else :
try :
execute_statement(parsed_statement)
except Exception :
print('Error: could not execute!')
except Exception :
print('Error: could not parse!')
else :
print('Unknown command.')
print()
in_str = input('> ')
print('Shutting {0}...\n'.format(project_name))