MySQLdb warnings ... what caused them?

Sheila King sheila at spamcop.net
Tue May 13 13:36:00 EDT 2003


On Tue, 13 May 2003 09:36:57 -0500, Jeff Epler <jepler at unpythonic.net>
wrote in comp.lang.python in article
<mailman.1052836700.591.python-list at python.org>:

> Please refer to the mysql manual..
> http://www.mysql.com/doc/en/SHOW_WARNINGS.html

Hmmm. Well, I would try that except that it appears the SHOW WARNINGS
command is implemented first in MySQL 4.1 and I'm using MySQL 3.23.56

> it appears that the warning shold actually read
>     Records: 3  Duplicates ...
> and that the warnings themselves can be found by a special query "show
> warnings".

Interesting about the "Records" being shown as "cords". Thanks. Makes a bit
more sense...

> You could also refer to the mysql-python documentation (on my system,
> /usr/share/doc/MySQL-python-0.9.1/MySQLdb-4.html) to see how to create a
> cursor that does not raise an exception when a sql command has warnings.

I do see that there are other cursor classes, such as CursorNW, that would
not raise the warnings. That isn't my question though. I guess I wasn't
clear enough.

I'm curious about why my query is even generating a warning at all. If it
is because of my MySQL query, and I need to go study MySQL a bit more,
fine. However, what puzzles me is that I am practically copying an example
from the MySQLdb documentation, as shown on this page of the docs:
/MySQL-python-0.9.2/doc/MySQLdb-3.html#ss3.4

to whit:

-----------(begin pasted example from docs)---------------

The only other method you are very likely to use is when you have to do a
multi-row insert:

c.executemany(
    """INSERT INTO breakfast (name, spam, eggs, sausage, price)
    VALUES (%s, %s, %s, %s, %s)""",
    [
      ("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ),
      ("Not So Much Spam Plate", 3, 2, 0, 3.95 ),
      ("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 )
    ] )

Here we are inserting three rows of five values. Notice that there is a mix
of types (strings, ints, floats) though we still only use %s. And also note
that we only included format strings for one row. MySQLdb picks those out
and duplicates them for each row.

---------(end pasted example from docs)----------------

When I perform this same type of query at the command line in the MySQL
monitor, I raise no warnings:

---------(begin CLI MySQL example)---------------
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)

mysql> SELECT * from test;
+------+-------+------------+
| ID   | name  | phone      |
+------+-------+------------+
| 1    | mary  | 111-222-33 |
| 2    | john  | 444-555-66 |
| 3    | steve | 777-888-99 |
+------+-------+------------+
3 rows in set (0.00 sec)

mysql> INSERT INTO test (ID, name, phone) VALUES (4, "martha",
"000-512-5555");
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * from test;
+------+--------+------------+
| ID   | name   | phone      |
+------+--------+------------+
| 1    | mary   | 111-222-33 |
| 2    | john   | 444-555-66 |
| 3    | steve  | 777-888-99 |
| 4    | martha | 000-512-55 |
+------+--------+------------+
4 rows in set (0.00 sec)

mysql>
--------(end CLI MySQL example)--------------

Since the query from the command line for inserting as shown raises no
warnings, I'm really puzzled why I'm getting warning from MySQLdb
"executemany" command, as I'm following exactly the format in the
documentation. I know I can suppress the warning, but I'd rather understand
the cause and decide whether I should address the cause or not.

Thanks,


-- 
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list