我已经仔细检查了我的数据库,并确认我没有将记录两次输入到我的数据库中
我认为问题应该是我的功能,我希望你能帮助我纠正它。
在使用功能之前我只打印一个结果: 代码:
conn = sqlite3.connect('server.db')
cur = conn.cursor()
cur.execute('SELECT command FROM router WHERE type ="global" or function = "create vlan" ORDER BY key ASC')
for row in cur:
print(row)
结果:
('enable',)
('configure terminal',)
('vlan (number)',)
('name (vlan name)',)
使用我的功能后:
x="create vlan"
y="global"
#
def readswitch(x,y):
conn = sqlite3.connect('server.db')
with conn:
cur = conn.cursor()
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
read = cur.fetchall()
return read;
import database
print (database.readswitch(x,y))
结果:
[('enable',), ('configure terminal',), ('vlan (number)',), ('name (vlan name)',)]
[('enable',), ('configure terminal',), ('vlan (number)',), ('name (vlan name)',)]
如果我一起运行代码和我的功能:
conn = sqlite3.connect('server.db')
cur = conn.cursor()
cur.execute('SELECT command FROM router WHERE type ="global" or function = "create vlan" ORDER BY key ASC')
for row in cur:
print(row)
x="create vlan"
y="global"
#
def readswitch(x,y):
conn = sqlite3.connect('server.db')
with conn:
cur = conn.cursor()
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
read = cur.fetchall()
return read;
import database
print (database.readswitch(x,y))
结果:
('enable',)
('configure terminal',)
('vlan (number)',)
('name (vlan name)',)
('enable',)
('configure terminal',)
('vlan (number)',)
('name (vlan name)',)
[('enable',), ('configure terminal',), ('vlan (number)',), ('name (vlan name)',)]
[('enable',), ('configure terminal',), ('vlan (number)',), ('name (vlan name)',)]
如果我一起使用我的功能,它也会打印我的基本结果两次 所以我认为主要问题应该是功能 有人可以帮帮我吗?