con = lite.connect(db) # connects to the database
cur = con.cursor()
for item in self.button_array:
if item.isChecked():
productName = item.text()
custCommand = '''SELECT COUNT(*) FROM Customers''' # counts the number of rows in the table Customers
cur.execute(custCommand)
newCustomerID = cur.fetchall()[0][0] + 1000 # gives the order an CustomerID that is +1
print(newCustomerID)
con.close()
print(productName)
con = lite.connect(db)
cur = con.cursor()
findProductID = '''SELECT ProductID FROM Products WHERE ProductName = ''' + productName #searches for ProductID from the database and compares it to the product name
cur.execute(findProductID)
resultProductID = cur.fetchall()
print(resultProductID)
con.close()
Я пытаюсь получить его, чтобы он сравнивал столбец ProductName (просто столбец с именами цветов в нем) в таблице с текстом меток для цветов, но он продолжает придумывать следующее:
<class 'sqlite3.OperationalError'> no such column: Tulips <traceback object at 0x03FAA4E0>
(Тюльпаны - это всего лишь пример имеющегося цветка)
Поэтому кажется, что текст должен быть именем столбца, а не элементом в столбце, и я ' Я не очень уверен, как заставить это работать, я извиняюсь за плохое объяснение, но я действительно не знаю, что еще делать, так как я не настолько опытен с этим.
Править : Итак, я попытался поместить оператор в исполнение и использовать 'LIKE?' вместо этого
con = lite.connect(db)
cur = con.cursor()
findProductID = '''SELECT ProductID FROM Products WHERE ProductName = LIKE ?''' #searches for ProductID from the database and compares it to the product name
cur.execute('''SELECT ProductID FROM Products WHERE ProductName = LIKE ?''',(productName))
resultProductID = cur.fetchall()
print(resultProductID)
con.close()
Но в итоге получилось следующее:
<class 'sqlite3.OperationalError'> near "?": syntax error <traceback object at 0x0356A2D8>