-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlcheck.py
More file actions
52 lines (41 loc) · 1.3 KB
/
Copy pathsqlcheck.py
File metadata and controls
52 lines (41 loc) · 1.3 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
#A very simple way to detect column wildcard usage
import os,glob
#path to the folder where the sql files are located
path = '/Users/sutimurturkan/Desktop/SQLCHECK/sqlqueries-master'
def get_sql_files():
result = glob.glob(os.path.join(path, '*.sql'))
return result
def get_file_name(file):
title = file.split('/')[-1]
return(title)
def read_sql_files(file):
f = open(file,"r")
return f.read()
def query_file(index):
x = []
for file in get_sql_files():
x.append(read_sql_files(file))
return x[index]
def get_list_of_lines(array):
array = "".join(array)
array = array.splitlines()
return array
def get_list_of_words(line):
words = line.split(" ")
words = [x.lower() for x in words]
return words
def is_column_wildcard(list):
for i in range(1,len(list)):
if (list[i-1], list[i]) == ('select','*'):
return "Column Wildcard Usage"
else:
return "No Antipatterns Detected"
def main():
for i in range(len(get_sql_files())):
print(get_file_name(get_sql_files()[i]))
for line in get_list_of_lines(query_file(i)):
word_list = get_list_of_words(line)
print(is_column_wildcard(word_list))
print("------------------------------------")
if __name__ == "__main__":
main()