Menu

time functions, executemany & bind variable

garonnev
2007-07-31
2012-09-19
  • garonnev

    garonnev - 2007-07-31

    Hello,

    I'm trying to do multi-insertions with executemany but i have a problem when using NOW or sysdate function, i.d:

    > python
    Python 2.3.4 (#1, May 3 2007, 08:58:36)
    [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import MySQLdb
    >>> print MySQLdb.version
    1.2.2
    >>> db=MySQLdb.connect(host="xxxxx",user="xxxx", passwd="xxxx",db="xxx")
    >>> c=db.cursor()

    >>> l = [('e70fcb90-9dd9-46b7-ae0b-22c4bf7d5cf5', '2bfe4e90-ae05-476e-9d79-0cf792555680')]

    >>> c.executemany ("""INSERT IGNORE INTO t_files3(stamp, guid, originalvuid) VALUES ("2007-07-31 22:52:35",%s,%s)""",l)
    1L

    it works but with sysdate() or NOW() i get:

    >>> c.executemany ("""INSERT IGNORE INTO t_files3(stamp, guid, originalvuid) VALUES (sysdate(),%s,%s)""",l)
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 212, in executemany
    self.errorhandler(self, TypeError, msg)
    File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
    TypeError: not all arguments converted during string formatting

    The schema used for the t_files3 table is:
    CREATE TABLE t_files3 (
    guid CHAR(36), originalVuid CHAR(36),
    size INTEGER DEFAULT -1,
    checksum VARCHAR(100),
    stamp DATETIME DEFAULT NULL )ENGINE=InnoDB;

    If someone has any idea, i will appreciate.

    Vincent.

     
    • garonnev

      garonnev - 2007-07-31

      Sorry i will post this message in the help section instead.

      Vincent

       

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.