which column of sql table is equal to a variable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: which column of sql table is equal to a variable (/thread-2389.html) |
which column of sql table is equal to a variable - gray - Mar-13-2017 i want to find the value of 'vazn' (one column of sql table) where 'id' column is equal to f1. f1 is a variable as following: f1=int(enter3.get()) enter3 is an entry. i entered the variable in enter3 that is equal to one of the existing 'id's in the sql table('bills') this is my code: why?????please helpppp RE: which column of sql table is equal to a variable - Larz60+ - Mar-13-2017 vazno, id1 are variables billsa is the table (or view) name It's telling you nothing matches id1 RE: which column of sql table is equal to a variable - gray - Mar-13-2017 (Mar-13-2017, 12:48 PM)Larz60+ Wrote: vazno, id1 are variables the table name is "billse" "vazn" & "id1" are the columns of this table... "f1" is a variable RE: which column of sql table is equal to a variable - Larz60+ - Mar-13-2017 Of course you are correct: bottom line is still correct: It's telling you nothing matches id1 (f1) suggest a print statement to see contents of f1 RE: which column of sql table is equal to a variable - gray - Mar-14-2017 (Mar-13-2017, 01:40 PM)Larz60+ Wrote: Of course you are correct: i have seen contents of f1...it's "789"...one of values from "id1" column is "789" too...but i get "null" for "self.cur.fetchall()" or the same "vaznp" why??????????? help RE: which column of sql table is equal to a variable - zivoni - Mar-14-2017 But you are trying to get rows with id = "f1", not rows with id = "789" - you have no variable substitution/expansion in your select string. So you are getting the correct response (unless you have row with id "f1" in your table ... ). Either format/construct your select string with your variable - you can do something like: select_string = 'select * from bla where id = "{}";'.format(f1)or use (and thats better solution, if its available) a variable substitution provided by a database connection - its usually something like: cur.execute("select * from bla where id = ?", (f1,))exact syntax might vary according to the database used. RE: which column of sql table is equal to a variable - gray - Mar-15-2017 ok.my problem was solved...but i have a new problem..please help again...i want to add **vazne** into another table(it maeans **vazne** will becomes one of the the second table columns )...when i print **vazne** , it returns correct value but as this format : [(360,)]...so when i add it into the second table, i get the following error Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__ return self.func(*args) File "/home/pi/start/gui/jus-submeno-image-refreshh.py", line 609, in tozin2 self.whtable() File "/home/pi/start/gui/jus-submeno-image-refreshh.py", line 645, in whtable c.execute("INSERT INTO billsf (vaznf, id1, firs1,las1, yekdo, vaznemp) VALUES (?, ?, ?, ?, ?, ?)",(counter, f1, d1, e1, yord, vazne)) sqlite3.InterfaceError: Error binding parameter 5 - probably unsupported type. **billse** is the first table...**billsf** is the second table... **vazne** is selected based on 2 items in the first second...after calling **vazne** from the first table, it shoud be added to the second table(**billsf**) RE: which column of sql table is equal to a variable - nilamo - Mar-20-2017 (Mar-15-2017, 07:58 AM)gray Wrote: ok.my problem was solved...but i have a new problem..please help again... You already opened a new thread for that: https://python-forum.io/Thread-combining-2-tables-af-a-special-form Any discussion of the new question, should take place in the new thread. I'm not closing this thread in case someone still wants to discuss this topic. |