对于我的函数,我想从搜索命令函数
访问db和get命令这是我的代码:
x="create vlan"
y="global"
def readswitch(x,y):
conn = sqlite3.connect('server.db')
with conn:
cur = conn.cursor()
run= 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))
现在,我可以打印出我的答案,但结果上的错误很少如下:
C:\Python34\python.exe C:/Users/tommy/PycharmProjects/2015122/database.py
[('enable',), ('configure terminal',), ('vlan (number)',), ('name (vlan name)',)]
[('enable',), ('configure terminal',), ('vlan (number)',), ('name (vlan name)',)]
处理完成,退出代码为0
我打印出我的答案两次,但我不知道为什么我要打印两次。
答案 0 :(得分:0)
您是否使用sqlite数据库查询工具仔细检查了此查询的结果?也许您在数据库中有两条匹配的记录。
SELECT command FROM switch WHERE function = 'create vlan' or type = 'global' ORDER BY key ASC
P.S。您可能想要修复问题的格式,这有点难以理解。