Home > Mobile >  Database queries with SELECT xxx FROM database WHERE Relay = "value from a string"
Database queries with SELECT xxx FROM database WHERE Relay = "value from a string"

Time:12-13

I'm wondering about if it's possible to get data from a database with this query: SELECT Name FROM fraleon WHERE Relay = "value from a string"? When I try to put in a string in the query it comes with a message that the column doesn't exists.

I have just started with programming, so hope my question isn't to stupid ;-) I'm trying to make an app where i have a QtableWidget and a QScrollbar where the value from the scrollbar (1 - 100) is used to change to the next relay.

con = sqlite3.connect("C:\Leonclient\LocalDB\LeonDBlite.db")cur = con.cursor()
value = 5
       
for row in cur.execute('SELECT Name FROM fraleon where Relay = value'):
    print(row)

Traceback (most recent call last):

  File "C:\Users\xxx\AppData\Local\Temp/ipykernel_10292/3072186007.py", line 1, in <module>
    for row in cur.execute('SELECT Name FROM fraleon where Relay = (Value)'):

OperationalError: no such column: Value

CodePudding user response:

You may need to concatenate the query string with variable value otherwise it will be considered literally 'value'

for row in cur.execute('SELECT Name FROM fraleon where Relay = '   str(value)):

CodePudding user response:

You can try to write the query - SELECT Name FROM fraleon WHERE Relay like '%somevalue%'

That way you will specify a sub-string of the Relay's column values

  • Related