我使用此代码在python中创建了一个sqlite表
db.execute('CREATE TABLE const (uid INT UNIQUE ,article INT, sub INT, content TEXT)')
我尝试使用此代码在表上执行select-where状态
cursor = db.execute('SELECT sub FROM const WHERE uid = ?', uid)
我得到的就是这个错误:
sqlite3.OperationalError: no such column: uid
我试过搜索,但对于像我这样的新手似乎没有明确的解释和解决这个错误。请帮忙
这里是我的代码
#!/usr/lib/python3m
import sqlite3
article = 0
sub = 0
text = ''
count = 0
flag = False
close_tag = False
def close():
global text
global close_tag
if close_tag:
a = 0
while a < count:
a += 1
text += '</ol>'
close_tag = False
def get():
close()
# out = open('output.txt', 'a')
# print('Article: ' + str(article), end='', file=out)
# print('\n' + 'Sub: ' + str(sub) + '\n', end='', file=out)
# print(text + '\n', file=out, end='')
# print('Article: ' + str(article), end='')
# print('\n' + 'Sub: ' + str(sub) + '\n', end='')
# print(text + '\n', end='')
db = sqlite3.connect('const_enGB')
# if not (article == a and sub == s):
uid = int(str(article) + str(sub))
cursor = db.execute('SELECT sub FROM const WHERE uid = ?', uid)
if not cursor:
db.execute('INSERT INTO const (uid, article, sub, content) VALUES (?,?,?,?)', uid, article, sub, text))
else:
db.execute('UPDATE const SET article = ?, sub =?, content=? WHERE uid = ? ', (article, sub, text))
db.commit()
def main():
file = open('ch1.txt')
global article
global text
global sub
global count
global flag
global close_tag
article = 0
sub = 0
text = ''
count = 0
flag = False
for line in file:
line = line.strip()
if line != '':
if line.isnumeric():
article = line
text = ''
else:
ol = False
start = line.find('(') + 1
end = line.find(')')
t = line[start:end]
if t.isnumeric():
ol = True
sub = int(line[start:end])
text = line[end + 1:len(line)].strip()
elif line[start:end].isalpha():
ol = True
flag = False
close_tag = True
type_of = line[start:end]
if type_of == 'a':
text += '<ol type="a"><li>' + line[end + 1:len(line)].strip() + '</li>'
count = 1
flag = True
elif 'i' == type_of:
text += '<ol type="i"><li>' + line[end + 1:len(line)].strip() + '</li>'
count = 2
flag = True
else:
if not flag:
text += '<li>' + line[end + 1:len(line)].strip() + '</li>'
if not ol:
text += line[end + 1:len(line)].strip()
if sub != 0 and article != 0 and text.strip() != '':
if not flag:
get()
if __name__ == "__main__": main()