I 've written two function for each table to receive field's command. And my teammate needs me to remix two function into one. Finally I make this function but it cannot receive my router table 's command. this is my two functions:
# 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 = input("x:")
# for result in readrouter(a):
# print (result[0])
# def readswitch(x):
# conn = sqlite3.connect('server.db')
# cur = conn.cursor()
# cur.execute("SELECT DISTINCT command FROM switch WHERE function =? or function='configure terminal' or function='enable' ORDER BY key ASC",(x,))
# read = cur.fetchall()
# return read;
This is my function after combine two function into one:
def readciscodevice(x):
conn = sqlite3.connect('server.db')
cur = conn.cursor()
if x:
cur.execute(
"SELECT DISTINCT command FROM switch WHERE function =? or function='configure terminal' or function='enable' ORDER BY key ASC",
(x,))
read = cur.fetchall()
return read
else:
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 readciscodevice(a):
print(result[0])
I use my if-statement and it can read my switch table 's command but cannot get commands from switch table. Do I need to write boolean or something else to ensure that it can access my router table?
Aucun commentaire:
Enregistrer un commentaire