lundi 23 mars 2015

python sqlite3 cannot receive two table's field in one function

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 code:



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