OK.

thanks for these answers



On Aug 26, 3:42 pm, Mike Conley <mconl...@gmail.com> wrote:
> Look at the generated SQL. The Python DBAPI uses one INSERT statement for
> all rows inserted when using executemany(). In this case,
> INSERT INTO test (col1, col2) VALUES (?, ?)
> SA created the column list from the first set of values provided to
> i.insert(), and so supplied a NULL value for col2 in the second row. SA had
> no choice, the code must provide values for each column and since your code
> did not supply a value, SA used None.
>
> i.execute([{"col1" : 2, "col2" : 5}, {"col1" : 1}])
> x...94f0 INSERT INTO test (col1, col2) VALUES (?, ?)
> x...94f0 [[2, 5], [1, None]]
> x...94f0 COMMIT
>
> Implied rule is: when inserting many records, provide same value list for
> each row.
>
> --
> Mike Conley
>
> On Wed, Aug 26, 2009 at 5:36 AM, menuge <men...@gmail.com> 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?
>
> > thks
--~--~---------~--~----~------------~-------~--~----~
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