-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathutils.py
More file actions
69 lines (61 loc) · 2.69 KB
/
Copy pathutils.py
File metadata and controls
69 lines (61 loc) · 2.69 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
# schema/utils.py
# -----------------
# Definition of various utilities to be used by the schema plugin
#
def __returnChecks(session, schema, table):
# Define the query to get the routines
stmt = """select
concat("select '",c.table_schema,".",c.table_name,"','",c.column_name,"','",c.data_type,
"',","count(*) from ",c.table_schema,".",c.table_name,"
where ",c.column_name," like '0000-00-00%' having count(*) > 0")
from information_schema.columns c,information_schema.tables t
where c.table_schema = t.table_schema and c.table_name = t.table_name
and c.data_type in ('datetime','timestamp','date')
and t.table_type = 'BASE TABLE'
and t.table_schema not in ('performance_schema','information_schema','sys','mysql');"""
if schema is not None:
stmt = stmt + " AND t.table_schema='%s'" % schema
if table is not None:
stmt = stmt + " AND t.table_name='%s'" % table
# Execute the query and check for warnings
result = session.run_sql(stmt)
defaults = result.fetch_all()
if (result.get_warnings_count() > 0):
# Bail out and print the warnings
print("Warnings occurred - bailing out:")
print(result.get_warnings())
return False
return defaults
def __returnDefaults(session, schema, table):
# Define the query to get the routines
stmt = """SELECT COLUMN_NAME ColName, COLUMN_TYPE DataType, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '%s' AND
TABLE_NAME = '%s'""" % (schema, table)
# Execute the query and check for warnings
result = session.run_sql(stmt)
defaults = result.fetch_all()
if (result.get_warnings_count() > 0):
# Bail out and print the warnings
print("Warnings occurred - bailing out:")
print(result.get_warnings())
return False
return defaults
def __returnRoutines(session, schema):
# Define the query to get the routines
if schema is not None:
filters = "WHERE ROUTINE_SCHEMA = '%s'" % schema
stmt = """SELECT ROUTINE_SCHEMA AS SchemaName, ROUTINE_NAME AS RoutineName,
ROUTINE_TYPE AS RoutineType, DEFINE AS RoutineDefine
FROM INFORMATION_SCHEMA.COLUMNS"""
if filters:
stmt = stmt + filters
# Execute the query and check for warnings
result = session.run_sql(stmt)
#routines = result.fetch_all()
defaults = result.fetch_all()
if (result.get_warnings_count() > 0):
# Bail out and print the warnings
print("Warnings occurred - bailing out:")
print(result.get_warnings())
return False
return defaults