Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3342058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:47:39+00:00 2026-05-18T00:47:39+00:00

I noticed a few posts on SO regarding MySQL updates using python and still

  • 0

I noticed a few posts on SO regarding MySQL updates using python and still cannot seem to get this correct.

def updateEmployee(employee):
    print employee["firstName"]+" "+employee["lastName"]+" "+employee["nameN"]
    cursor = db.cursor()
    if(len(employee["nameN"]) > 0):
        cursor.execute("""
                UPDATE `employee` 
                SET `employeeID`=%s, `parentID`=%s, `firstName`=%s, `title`=%s, `locCode`=%s, 

(25)

                WHERE  `employee`.`nameN`=%s 
                """, (employee["employeeID"], employee["parentID"], employee["firstName"], employee["title"], employee["locCode"], employee["nameN"]))
        if(cursor.rowcount > 0 ):
            print "updated"
        else:
            c.execute("""
                INSERT INTO `employee`
                (`employeeID`, `parentID`, `nameN`, `firstName`, `alias`, `lastName`, `title`, `department`, `phone`, `areaMission`, `leadershipStyle`, `employeeType`, `coreFunc1`, `coreFunc2`, `coreFunc3`, `address`, `locCode`,`posOrg`)
                VALUES 
                (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
                """, (employee["employeeID"], employee["parentID"], employee["nameN"], employee["firstName"], "", employee["lastName"], employee["title"], "", employee["phone"], '', '', '', '', '', '', '', employee["locCode"], ''))

            if(c.rowcount > 0):
                db.commit()
                print "inserted"
            else:
                print "insert failed"
    else:
        print "missing nameN"

Resulting Error which appaers on line 25 (updateEmployee) which for reference has (25) in front of the line above.

[chris@apps ~]$ ./adjust.py
Linda Adam adam.804
Traceback (most recent call last):
  File "./adjust.py", line 89, in <module>
    processCSV(fileName)
  File "./adjust.py", line 14, in processCSV
    updateEmployee(employee)
  File "./adjust.py", line 25, in updateEmployee
    WHERE  `employee`.`nameN`=%s """, (employee["employeeID"], employee["parentID"], employee["firstName"], employee["title"], employee["locCode"], employee["nameN"]))
  File "/usr/lib/python2.5/site-packages/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.5/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE  `employee`.`nameN`='adam.804'' at line 3")

It appears I am ending up with an extra ‘ at the “WHERE clause” but I do not understand how this could be?

The employee object I am using when this fails is defined as:

{
    'employeeID': '1111', 
    'firstName': 'Linda', 
    'title': 'Systems Manager', 
    'nameN': 'adam.804', 
    'lastName': 'Adam', 
    'locCode': 'TNC', 
    'phone': '555-555-5555', 
    'parentID': '2222', 
    'room': ''
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:47:40+00:00Added an answer on May 18, 2026 at 12:47 am

    I think you have an extra comma before your WHERE clause.

    An update should look like this:

    update foo
    set a = 1,
    b = 2
    where type = 0
    

    I think yours looks like this:

    update foo
    set a = 1,
    b = 2,
    where type = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed that a few Wordpress blogs have query statistics present in their footer
I've noticed there are a few solutions to allow the use of memcached on
After hitting a few StackOverflowExceptions in .NET I noticed they completely bypass the unhandled
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed some posts here on string matching, which reminded me of an old
I want to create an SSH Tunnel in Java. I noticed quite a few
This thing was not noticed to be slow at first because there were not
I noticed a few strange behaviors in a Windows Forms scenario which involves threads
Hi have noticed a few sites that give the style tag an id such
As I noticed in the answers of another question there are a few problems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.