Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#153 warnings on data truncation

MySQLdb-1.2
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2005-09-19
Davide Alberani
No

Hi,
I think I've found a little bug or at least an inconsistent
behavior in the executemany() method.

Using the execute() method to insert an overflowing string
in a VARCHAR field (e.g.: inserting a 256 chars string in
a VARCHAR(255) field) will not raise any Warning, while
the string is - obviously - truncated.
The same behavior can be seen using the executemany()
method,
with just a single value.

On the other side, using the executemany() method to insert
more than one row (with at least one of them too long),
will
raise a Warning.

In the attachment I've put a very simple example.

Discussion

  • bug example

     
    Attachments
  • Logged In: YES
    user_id=170840

    Pardon, I've forgot some information: I'm running Linux on
    x86; I've tried with both Python 2.3 and 2.4; I'm running
    MySQL 4.0.16 and I've tested both mysqldb 1.1.6 and 1.2.1c3.

     
  • Andy Dustman
    Andy Dustman
    2006-03-05

    Logged In: YES
    user_id=71372

    I added unit tests for this (test_capabilities) and the
    output for testmybug.py now looks like this:

    testmybug.py:22: Warning: Data truncated for column
    'varcfield' at row 1
    curs.execute(sqlq, data)
    testmybug.py:23: Warning: Data truncated for column
    'varcfield' at row 1
    curs.executemany(sqlq, [data])
    testmybug.py:28: Warning: Data truncated for column
    'varcfield' at row 1
    curs.executemany(sqlq, data)

    However, the new expanded warning messages will only work if
    you have a 4.1 or newer server.