On May 4, 1:28 am, deepak <[email protected]> wrote:
> hi,
> is there a equivalent of executeBatch() of
> java.http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#execu...
>
> the algorithm in java is:
> 1) make a prepared statement for making an update
> 2) make a batch by calling addBatch(), add 1000 records
> 3) execute the prepared statement, will update 1000 records, by
> calling executeBatch()
> 4) executeBatch() will return an array of integers, 1 for successful
> update or 0 otherwise. If we get a zero we will insert a record with
> the INSERT IGNORE option.
>
> note that.
> 1) while making the prepared statement we do not give multiple values.
> the sql we give is for inserting a single record, but the sql for
> multiple records is auto-generated ie. batch inserts.
> 2) returns the status of the individual statements in the batch insert
>
> how can this be done in sequel?
>
> could update multiple records by saying:
> Foo = DB[:Foo]
> Foo.insert_ignore.multi_insert(records) # this is not a prepared
> statement
>
> but did not get the result of each update.
> also cannot make a prepared statement for batch insert.
>
> i think i can patch for making the prepared statement, will generate
> the code.
> but cannot see how to get the result of each update in the batch
> insert.
> can i use some other driver?
Your best bet currently would be something like:
ps = DB[:Foo].prepare(:insert, :ins, :i=>$i)
records.map{|r| (ps.call(:i=>r[:i]); 1) rescue 0}
This is assuming a bad insert will raise an exception, and if no
exception was raised, the insert was successful.
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.