I can return commands in my return function but something need to improve: 1. I am trying to get "enable" and "conf t"command in "function" field everytime.
B4(select function and type)(I can return my commands):
def readrouter(x, y):
conn = sqlite3.connect('server.db')
cur = conn.cursor()
cur.execute("SELECT DISTINCT command FROM router WHERE function =? or type = ? ORDER BY key ASC",(x, y))
read = cur.fetchall()
return read;
a = raw_input("x:")
b = raw_input("y:")
for result in readrouter(a,b):
print (result[0])
After:(select enable, conf t, and "commands")
def readrouter(x):
conn = sqlite3.connect('server.db')
cur = conn.cursor()
cur.execute("SELECT DISTINCT command FROM router WHERE function =? or function='configure terminal' or function='enable' ORDER BY key ASC",(x))
read = cur.fetchall()
return read;
a = raw_input("x:")
for result in readrouter(a):
print (result[0])
Hope you know what I mean but now I cant do what I want. It presents:
x:create vlan
Traceback (most recent call last):
File "C:/Users/f0449492/Desktop/2015225/database.py", line 323, in <module>
for result in readrouter(a):
File "C:/Users/f0449492/Desktop/2015225/database.py", line 318, in readrouter
cur.execute("SELECT command FROM router WHERE function =? or function='configure terminal' or function='enable' ORDER BY key ASC",(x))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 7 supplied.
Process finished with exit code 1
(x,)instead of(x). The former is a 1-length tuple, the latter is justx.