MySQLdb warnings ... what caused them?

Steve Holden sholden at holdenweb.com
Thu May 15 14:40:13 EDT 2003


"Gerhard Häring" <gh at ghaering.de> wrote in message
news:mailman.1052860041.28974.python-list at python.org...
[...]
>
> Better use something like "id auto_increment primary key" for the ID
> column. You can then insert data with just:
>
> cu = cx.cursor()
> cu.execute("""
> INSERT INTO TEST(ID, NAME, PHONE)
> VALUES (NULL, %s, %s)
> """, ("Alice", "4711"))
>
> The NULL for the ID column will be replaced by MySQL with the default
> value for this column. Which is the next-greatest value of the hidden
> sequence for the ID column that "auto_increment" creates. [1]
>

[...]

If you don't provide a value for an attribute then SQL will automatically
assign NULL, so this is normally more simply written as

cu.execute("""
INSERT INTO TEST(NAME, PHONE) VALUES(%s, %s)
""", ("Alice", "4711"))

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list