Menu

Passing locals() as parameters to execute()?

Roy Smith
2008-01-10
2013-04-29
  • Roy Smith

    Roy Smith - 2008-01-10

    I'm using:

    pymssql-0.8.0
    freetds-0.64
    Python 2.3.4
    RedHat Linux AS4
    Talking to MS SQL Server 2005

    This code works fine:

            c = self.db.cursor()
            params = {'name': name}
            c.execute ("""select bf_pid from bf_projects                                      
                          where bf_description = %(name)s""",
                       params
                       )

    but if I try to avoid having to build the temporary params dict by just passing locals(), I get:

    Traceback (most recent call last):
      File "./getsteps.py", line 43, in <module>
        main()
      File "./getsteps.py", line 11, in main
        pid = db.get_project_id ("CMP-DMT80-main-wsb")
      File "./getsteps.py", line 30, in get_project_id
        params
      File "/usr/local/lib/python2.5/site-packages/pymssql.py", line 126, in execute
        self.executemany(operation, (params,))
      File "/usr/local/lib/python2.5/site-packages/pymssql.py", line 152, in executemany
        raise DatabaseError, "internal error: %s" % self.__source.errmsg()
    pymssql.DatabaseError: internal error: None

    The dict returned by locals() has a 'name' entry.  What magic is going on that's causing this?

     
    • A

      A - 2008-01-11

      Hello,

      if you could paste the code that doesn't work.

      Regards,
      Andrzej

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.