简体   繁体   中英

If statement in Flask using string variable from SQL database

I'm creating a program where I need to check if a certain cell in a table equals a string value and, if it does not, to not change that value. Here is some snippet of the code for clarification:

if (db.execute("SELECT :rowchosen FROM userboard WHERE column=:columnchosen", rowchosen = rowchosen, columnchosen = columnchosen)) == '-'):
    #change value of cell
else:
    #go to a new page that displays an error

Yet, whenever I run this code, I always get an error because the value (I believe) prints as a dictionary value, something like {"row" = 'row'} of that sort. Any help/advice as to why this happens?

Are you sure that userboard is the database and not the table?

i think, here is what you want to do

conn = sqlite3.connect(db_file)
cur = conn.cursor()
cur.execute("SELECT * FROM userboard WHERE one=?", (columnchosen,))

rows = cur.fetchall()

for row in rows:
    print(row)

now, in the loop for row in rows: you need to perform your check. For all the rows returned, you need to check each row for - in the appropriate column

also check out http://www.sqlitetutorial.net/sqlite-python/sqlite-python-select/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM