-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
98 lines (77 loc) · 2.08 KB
/
controller.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
import json
from model import *
class Controller( Model):
Host_Name = ""
User_Name = ""
Password = ""
Database_Name = ""
def __init__( self ):
pass
def check_conn(self):
self.variable_connection()
r = self.connection()
if r == None:
self.close()
return 1
else:
return r
def get_databases(self):
# Ok
result = self.return_data("SHOW SCHEMAS")
return result
def get_tables(self, database):
# Ok
result = self.return_data("SHOW TABLES", database)
return result
def get_columns_from_table(self,table,database):
self.variable_connection()
result = self.return_data("SHOW COLUMNS FROM "+table+" IN "+database+";")
return result
def get_data(self, table, database):
self.variable_connection()
sql = "select * from " + table
r = self.return_data(sql, database)
return r
def create_new_database(self, db):
self.variable_connection()
sql = "CREATE DATABASE " + db
r = self.execute_sql(sql,'')
return r
def drop_database(self, db):
self.variable_connection()
sql = "DROP DATABASE " + db
r = self.execute_sql(sql,'')
return r
def create_new_table(self, sql, db):
self.variable_connection()
r = self.execute_sql(sql,db)
return r
def delete_data(self, table, database):
pass
def truncate(self, table, database):
pass
""" ========> Json files administrator """
def read_json(self):
json_data=open('connection.json')
data = json.load(json_data)
return data['conn']
def variable_connection(self):
json_data=open('connection.json')
data = json.load(json_data)
self.Host_Name = data['conn'][0]
self.User_Name = data['conn'][1]
self.Password = data['conn'][2]
def write_json_connection(self):
data_list = []
data_list.append(self.Host_Name)
data_list.append(self.User_Name)
data_list.append(self.Password)
data_list.append(self.Database_Name)
data_json = {}
json_data = json.dumps(data_list)
data_json['conn'] = json.loads(json_data)
json_data = json.dumps(data_json)
decoded = json.loads(json_data)
with open('connection.json', 'w') as outfile:
json.dump(decoded, outfile)