数据库浏览器精简版查询数据

时间:2019-12-21 08:11:06

标签: python sqlite

 column_2 = 'Equipment_Taken'
 table_name = 'Personal_Information'
 column_3 = 'Client_Name'

 dbCursor.execute('SELECT ({coi}) FROM {tn} WHERE {cn1}= "Bob"'.\
            format(coi=column_2, tn=table_name, cn1=column_3))
        all_rows = dbCursor.fetchall()
        print('2):', all_rows)

我想知道如何用用户输入切换出“ Bob”字符串,而当我用诸如userinput [2]之类的用户输入代替Bob时,它给了我一个语法错误。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

column_2 = 'Equipment_Taken'
table_name = 'Personal_Information'
column_3 = 'Client_Name'

userinput = input('Enter user name:')

dbCursor.execute('SELECT ({coi}) FROM {tn} WHERE {cn1}= "{input}"'.\
            format(coi=column_2, tn=table_name, cn1=column_3, input = userinput))
all_rows = dbCursor.fetchall()
print('2):', all_rows)