On Aug 26, 2009, at 5:36 AM, menuge wrote:

>
> Hi all,
>
> I d like to insert a list of dictionary in a simple MySQL table but, I
> have a problem, in my case, the MySQL default values are not
> supported...
>
> The table is very simple; 2 columns and a default value on the col2:
> ######
> CREATE TABLE `test` (
>  `col1` int(11) default NULL,
>  `col2` int(11) default '3'
> )
> ######
>
> Here is the python code:
> ##################################
> from sqlalchemy import *
> db = create_engine("mysql://r...@localhost/test")
> meta = MetaData(db)
> meta.echo = True
>
> table = Table("test", meta, autoload=True)
> i = table.insert()
> i.execute([{"col1" : 2, "col2" : 5}, {"col1" : 1}])
> print list(db.execute("SELECT * FROM test"))
> ##################################
>
> The result is:
> [(2L, 5L), (1L, None)]
>
> I don't understand... In my opinion, the result should be: [(2L, 5L),
> (1L, 3L)]
>
> I use Python 2.5.2 and sqlalchemy 0.4.7
>
> Can someone help me please?

the executemany is inserting a NULL.   take a look at the generated  
output to see.   the statement is compiled only once and it has both  
columns in it due to your first set of parameters.  you should be  
sending {"col1":1, "col2":None}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to