Python Forum
String concatenation in SQL update statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String concatenation in SQL update statement
#1
In the following Update statement i get shown Exception. Below are the arguments.
Could it be the parentheses around argg that is causing issue?
If so, i have tried .strip() without success.

fldSet: 'loc=?,aquired=?,disposition=?'
criteria: 'tagNo=? and tagClr=? and tagYr=?'
argg: 'Hermas,Purchased,Died,22,Red,2014'


 def global_cowUpDte(self,fldSet,criteria,argg):
        self.c.execute (f'UPDATE cowTbl SET {fldSet} WHERE {criteria}',(argg))

Exception has occurred: ProgrammingError
Incorrect number of bindings supplied. The current statement uses 6, and there are 35 supplied.
Exception has occurred:
Reply
#2
Hi,

Does the string f'UPDATE cowTbl SET {fldSet} WHERE {criteria}' evaluate as you expect it to?

Reggie
Reply
#3
(Feb-24-2022, 03:22 PM)hammer Wrote: fldSet: 'loc=?,aquired=?,disposition=?'
criteria: 'tagNo=? and tagClr=? and tagYr=?'
argg: 'Hermas,Purchased,Died,22,Red,2014'
...
The current statement uses 6, and there are 35 supplied.
6 bindings is correct, there are 6 placeholders (question marks) in "fldSet" and "criteria". But "argg" seems to have 35 values. It must be the number of characters. "argg" must be a tuple but it arrives as a string parameter and you think you can force it to be a tuple by putting parentheses around it. That does not work. Try this:
values = tuple(argg.split(","))
self.c.execute (f'UPDATE cowTbl SET {fldSet} WHERE {criteria}', values)
BashBedlam likes this post
Reply
#4
ReggieDrax, Yes the fString evaluates as expected.
ibreeden, your recommendation solved the Exception.

Thanks to all.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries i sawtooth500 3 414 Mar-22-2024, 03:08 AM
Last Post: deanhystad
  Trying to compare string values in an if statement israelsattleen 1 519 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  How do you format Update statement with multiple conditions hammer 4 2,040 Dec-16-2021, 10:49 PM
Last Post: hammer
  if statement string match javiopro 2 1,598 Sep-04-2021, 05:56 PM
Last Post: javiopro
  f string concatenation problem growSeb 3 2,214 Jun-28-2021, 05:00 AM
Last Post: buran
  Update Date based on Time/String stevezemlicka 1 1,988 Jan-08-2021, 06:54 PM
Last Post: Gribouillis
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,628 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Concatenation ?? ridgerunnersjw 1 1,672 Sep-26-2020, 07:29 PM
Last Post: deanhystad
  Combining two strings together (not concatenation) DreamingInsanity 6 3,056 Mar-29-2019, 04:32 PM
Last Post: DreamingInsanity
  Regarding concatenation of a list to a string Kedar 2 22,745 Aug-19-2018, 12:57 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020