March 13th, 2017, 06:06 AM
which column of sql table is equal to a variable
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:
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:
i get 'null' when it prints vaznp
self.cur.execute("SELECT vazn FROM billse WHERE id1='f1'")
vaznp = self.cur.fetchall()
March 13th, 2017, 10:30 AM
Your query is searching for the string f1 (literally "f1"), and so will only return records that contain "f1" as you haven't told the database that f1 is a variable and it should use the value that the variable points to. See "Parameterized queries" at SQLite Python tutorial - SQLite programming in Python
Last edited by dwblas; March 13th, 2017 at 10:34 AM.
March 15th, 2017, 03:05 AM
combining 2 tables af a special form
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
**billse** is the first table...**billsf** is the second table
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__
File "/home/pi/start/gui/jus-submeno-image-refreshh.py", line 609, in tozin2
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.
**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**)