-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoreSQL.py
148 lines (109 loc) · 2.95 KB
/
MoreSQL.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import mysql.connector as msql
db = msql.connect(
host='localhost',
user='root',
password='',
database='stuff',
)
cr = db.cursor()
table = "test"
###
# MORE TESTING
###
having = "artist"
thistag = "'Arti'"
optquotes = r"'{thistag}'"
col2add = ""
col2addafter = ""
rows = r"ALTER TABLE test ADD COLUMN ble VARCHAR(255) AFTER artist"
rows = r"ALTER TABLE test ADD COLUMN id2 INTEGER AUTO_INCREMENT PRIMARY KEY AFTER id"
addcol = r"ALTER TABLE test ADD COLUMN {} AFTER {}".format(
col2add, col2addafter)
# col2addafter =
# delcol = r"ALTER TABLE test DROP COLUMN id"
# print(rows)
# cr.execute(rows)
link = []
tag = "eloe"
link.append(tag)
# link.append('muk')
# print(link)
# Add Following Tags
populink = r"INSERT INTO test (name) VALUES (%s)"
# cr.execute(populink, link)
# db.commit()
ins = r"INSERT INTO test (name, artist, ble) VALUES (%s, %s, %s)"
record = ("Jonn", "Arti", 6)
# cr.execute(ins, record)
# db.commit()
# Show Records
showrecs = "SELECT * FROM {} WHERE {} = {}".format(table, having, thistag)
showrecs = "SELECT * FROM Test WHERE artist = 'Arti'"
# cr.execute(showrecs)
# recs = cr.fetchone()
# print(recs)
def showtables(x):
for i in x:
if i <= 1:
print(i)
else:
for i in x:
print(i)
# showtables()
###
showrecs = r"ALTER TABLE test ADD COLUMN munk VARCHAR(255)"
# cr.execute(showrecs)
showrecs = r"ALTER TABLE test ADD COLUMN cat VARCHAR(255)"
# cr.execute(showrecs)
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 showlastcol():
col = r"DESC {}".format(table)
cr.execute(col)
result = cr.fetchall()
return(result[-1][0])
lastcol = showlastcol()
print(lastcol)
# Last ID
def showlastid():
getlastid = r"SELECT LAST_INSERT_ID()"
cr.execute(getlastid)
lastid = list(cr.fetchall()[0])[0]
return(lastid)
lastid = showlastid()
print(lastid)
# Auto Add Tags to their Classes
# INSERT INTO `table_name`(column_1,column_2,...) VALUES (value_1,value_2,...)
# UPDATE employees SET lastname = 'Hill', email = '[email protected]' WHERE employeeNumber = 1056
def IsNotNull(value):
isnotnull = "SELECT * FROM Test WHERE {} IS NOT NULL"
try:
cr.execute(isnotnull.format(value))
except Exception:
return False
else:
# testing
print("coucou")
return True
# If link exists try adding tags to existing record
# Add Main Tags
finally:
pass
# TESTING
value = "ble"
test = IsNotNull(value)
if test == True:
print("hoooray")
else:
print("that")
# isnotnull = "SELECT * FROM Test WHERE {} IS NOT NULL"
# cr.execute(isnotnull.format(value))
# res = cr.fetchone()
# print(res)