Python Forum
Query Syntax Error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Query Syntax Error (/thread-35951.html)



Query Syntax Error - hammer - Jan-02-2022

I have compared this code with similar queries that work. Can anyone see what I am missing that is causing the Syntax Error?

Error:
Exception has occurred: OperationalError (note: full exception trace is shown but execution is paused at: <module>) near "tagNo": syntax error File "/home/mark/Python Environments/FirstEnvProject/Bovine8.py", line 92, in insert_Cow self.c.execute(""" INSERT INTO cowTbl File "/home/mark/Python Environments/FirstEnvProject/Bovine8.py", line 665, in cow_saveAdd self.db.insert_Cow( File "/home/mark/Python Environments/FirstEnvProject/Bovine8.py", line 1316, in <module> (Current frame) CreateApp().run()
def insert_Cow(self,tagNo,tagClr,tagYr,type,des,
                        loc,locDte,birthDte,birthWt,weanDte,weanWt,sex,status,aquired,
                        aquiredDte,aquiredCst,disposition,dispDte,soldAmt,bredDte,
                        bullTagNo,bullTagClr,bullTagYr,actCalvDte,calfTagNo,calfTagClr,calfTagYr):
        self.c.execute(""" INSERT INTO cowTbl 

                           VALUES
                           tagNo=?,
                           tagClr=?,
                           tagYr=?,
                           type=?,
                           desc=?,
                           loc=?,
                           locDte=?,
                           birthDte=?,
                           birthWt=?,
                           weanDte=?,
                           weanWt=?,
                           sex=?,
                           status=?,
                           aquired=?,
                           aquiredDte=?,
                           aquiredCst=?,
                           disposition=?,
                           dispositionDte=?,
                           soldAmt=?,
                           bredDte=?,
                           bredByTag=?,
                           bredByTagClr=?,
                           bredByTagYr=?,
                           actCalvDte=?,
                           calfTagNo=?,
                           calfTagClr=?,
                           calfTagYr=?
                           """,
                           (tagNo,tagClr,tagYr,type,des,loc,locDte,birthDte,birthWt,weanDte,weanWt,sex,status,aquired,
                           aquiredDte,aquiredCst,disposition,dispDte,soldAmt,bredDte,
                           bullTagNo,bullTagClr,bullTagYr,actCalvDte,calfTagNo,calfTagClr,calfTagYr))
        self.con.commit()



RE: Query Syntax Error - menator01 - Jan-02-2022

Probable should look a little closer at your query structure. I've tried unsuccessfully inserting data with that structure.
Doing something like:

def insert(*args):
    cur.execute('insert into cowTbl values (?,?,?,?)', args) # This structure works
    conn.commit()

insert(34, 'data45', 'data29', 'data34')
worked for me.


RE: Query Syntax Error - hammer - Jan-03-2022

Problem resolved using your structure. thank you.