-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSQL.py
119 lines (84 loc) · 2.4 KB
/
TestSQL.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import mysql.connector as msql
db = msql.connect(
host='localhost',
user='root',
password='',
database='stuff',
)
cr = db.cursor()
table = "Test"
# TESTING SCRIPT
showrecs = "SELECT * FROM Test HAVING id2 = 5"
def DoesColExist(value):
cr.execute("SELECT * FROM Test WHERE {} IS NOT NULL".format(value))
return(cr.fetchone)
# LATER Check which of following is better for DoesColExist()
showrecs = "SELECT EXISTS(SELECT * FROM Test WHERE ble IS NOT NULL)"
showrecs = "SELECT * FROM Test WHERE ble IS NOT NULL LIMIT 0, 1"
showrecs = r"ALTER TABLE test ADD COLUMN Link VARCHAR(255)"
# cr.execute(showrecs)
# db.commit()
link = "id2"
llink = []
llink.append(link)
# print(link)
# Check Link existence
populink = r"INSERT INTO Test (Link) VALUES ('{}')".format(link)
# cr.execute(populink)
showrecs = "SELECT * FROM Test WHERE Link = 122"
# cr.execute(showrecs)
# recs = cr.fetchall()
# for i in recs:
# print(i)
dic = {}
cr.execute("select * from test")
dic['table'] = cr.fetchall()
# print(dic['table'])
for row in range(len(dic['table'])):
print(dic['table'][row])
# print dic['table'][row]['colum']
# recs = cr.fetchone()
# print(recs)
columns = []
def showcols():
col = r"DESC {}".format(table)
cr.execute(col)
result = cr.fetchall()
for i in result:
columns.append(i[0])
# showcols()
# print(columns)
def AddTag(table, value):
try:
addcol = r"ALTER TABLE {} ADD COLUMN {} VARCHAR(255)".format(
table, value)
cr.execute(addcol)
except Exception:
return False
def IsNotNull(table, value):
isnotnull = r"SELECT * FROM {} WHERE {} IS NOT NULL".format(table, value)
try:
# print(isnotnull)
cr.execute(isnotnull)
except Exception as e:
print(e)
return False
else:
return True
# If link exists try adding tags to existing record
# Add Main Tags
# tags = ["what"]
# showrecs = "SELECT * FROM Test WHERE Link = 122"
# cr.execute(showrecs)
# recs = cr.fetchall()
# for i in recs:
# print(i)
# value = "name"
# INN = IsNotNull(table, value)
# if INN == False:
# print("No existo")
# else:
# print("exists")
# print(DoesColExist("id2"))
# Sub Query
# SELECT * FROM whateverTable WHERE location IN (SELECT location FROM whateverTable)