MySQLdb warnings ... what caused them?

Neil Padgen neil.padgen at mon.bbc.co.uk
Wed May 14 06:32:04 EDT 2003


On Tuesday 13 May 2003 4:47 pm, Sheila King wrote:

> On Tue, 13 May 2003 07:20:37 -0400, Dave Reed <dreed at capital.edu>
> wrote in comp.lang.python in article
> <mailman.1052825240.7510.python-list at python.org>:
> 
>> On Tuesday 13 May 2003 02:12, Sheila King wrote:
>> > c.executemany("""INSERT INTO test (ID, name, phone) VALUES (%s,
>> > %s,
>> %s)""",
>> >     [ (1, "mary", "111-222-3333"),
>> >       (2, "john", "444-555-6666"),
>> >       (3, "steve", "777-888-9999")] )
>> > 
>> > Which gave me the following error/warning message(s):
>> > 
>> > 
>> > Traceback (most recent call last):
>> >   File "sqltest.py", line 13, in ?
>> >     [ (1, "mary", "111-222-3333"),
>> >   File
>> "/big/dom/xexample/lib/python2.2/site-packages/MySQLdb/cursors.py",
>> > line 162, in executemany
>> >     r = self._query(join(q,',\n'))
>> >   File
>> "/big/dom/xexample/lib/python2.2/site-packages/MySQLdb/cursors.py",
>> > line 249, in _query
>> >     rowcount = self._BaseCursor__do_query(q)
>> >   File
>> "/big/dom/xexample/lib/python2.2/site-packages/MySQLdb/cursors.py",
>> > line 176, in __do_query
>> >     self._check_for_warnings()
>> >   File
>> "/big/dom/xexample/lib/python2.2/site-packages/MySQLdb/cursors.py",
>> > line 231, in _check_for_warnings
>> >     raise Warning, info
>> > _mysql_exceptions.Warning: cords: 3  Duplicates: 0  Warnings: 3
>> 
>> <snip>
>> 
>> What are the types for your table columns?
> 
> They are all VARCHAR types.
> 
> mysql> DESCRIBE test;
> +-------+-------------+------+-----+---------+-------+
> | Field | Type        | Null | Key | Default | Extra |
> +-------+-------------+------+-----+---------+-------+
> | ID    | varchar(4)  | YES  |     | NULL    |       |
> | name  | varchar(8)  | YES  |     | NULL    |       |
> | phone | varchar(10) | YES  |     | NULL    |       |
> +-------+-------------+------+-----+---------+-------+
> 3 rows in set (0.00 sec)

The warnings are caused because your 'phone' data is longer than the
field width.

>>> len("111-222-3333")
12

mysql> insert into test values (1, 'mary', '111-222-3333');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM test;
+------+------+------------+
| ID   | name | phone      |
+------+------+------------+
| 1    | mary | 111-222-33 |
+------+------+------------+
1 row in set (0.00 sec)

It's a bit of a shame that MySQL doesn't give a warning, but MySQLdb
does.  (I'd prefer the warning!)

-- Neil




More information about the Python-list mailing list