-
Notifications
You must be signed in to change notification settings - Fork 5
/
EngineMySQL.py
59 lines (54 loc) · 1.72 KB
/
EngineMySQL.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
class EngineMySQL():
"""
"""
def __init__(self):
"""
"""
def server_info(self, connection):
"""
Shows the server info
"""
server_info = connection.get_server_info()
server_status = connection.stat()
server_connection_id = connection.thread_id()
server_data = [server_info, server_status, server_connection_id]
return server_data
def get_databases(self, cursor):
"""
Get the names of the databases in the server.
"""
query = 'SELECT SCHEMA_NAME FROM information_schema.SCHEMATA'
cursor.execute(query)
result = cursor.fetchall()
databases = []
for db in result:
databases.append(db[0])
return databases
def get_tables(self, cursor, db):
"""
Get the tables names
"""
query = '''SELECT information_schema.TABLES.TABLE_NAME
FROM information_schema.TABLES
WHERE information_schema.TABLES.TABLE_SCHEMA = "%s"''' % db
cursor.execute(query)
result = cursor.fetchall()
tables = []
for table in result:
tables.append(table[0])
return tables
def get_columns(self, cursor, db):
"""
Get the fields names
"""
query = '''SELECT information_schema.COLUMNS.COLUMN_NAME
FROM information_schema.COLUMNS
WHERE information_schema.COLUMNS.TABLE_SCHEMA = "%s"''' % db
cursor.execute(query)
result = cursor.fetchall()
columns = []
for column in result:
columns.append(column[0])
return columns