On Friday, May 24, 2019 at 6:48:52 AM UTC-7, Allan Peda wrote: > > Hi, > > I am using Sequel mostly for the convenience of bind variables (with > MSSQL/tiny_tds). > > I see positional binds are possible with a straight SQL call, as in: > > arr = [33, 26, 33] > sth = dbh['insert into mytab(a, b, c) values (?, ?, ?)', *arr] > sth.call(:insert) > > Is there any way to set the binds from an array when *calling* the > prepared statement? > > Something like this??: > > sth = dbh['insert into mytab(a, b, c) values (?, ?, ?)'] > records.each |row| > # I do not believe this is possible > sth.call(:insert, *row) > end > > I have some data loads that would be a lot simpler if I could just use an > array that provided binds in the same order as the statement rather than > going through symbols and a a hash. >
First, neither example is actually using a prepared statement. In the first example, the values are interpolated into the query (this is Sequel's default behavior), and in the Sequel example, ? appear as literal values in the query. Sequel does support what you want to do using prepared statements, using a different syntax: sth = dbh['insert into mytab(a, b, c) values (?, ?, ?)', :$a1, :$a2, :$a3].prepare(:insert, :insert_mytab) records.each do |row| sth.call(:a1=>row[0], :a2=>row[1], :a3=>row[2]) end See the prepared statement guide for details: http://sequel.jeremyevans.net/rdoc/files/doc/prepared_statements_rdoc.html Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/9584f3cf-2587-46b5-9734-c50332703353%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
