On Oct 12, 1:21 pm, Jeremy Evans <[email protected]> wrote:
> I still think the suggestions I made in my previous post stand, with
> some small additions:
>
> 1) Add support to Sequel's Oracle adapter to support bound variables
> and prepared statements, using Sequel's existing API.
>
> 2) Add support for placeholder literal strings to accept a single hash
> of arguments and use named placeholders in that case.
>
> 3) Add support for Dataset#bind, for setting bound variables before
> calling Dataset#call.
>
> 4) Create a Sequel extension that adds a method allowing nicer syntax
> for bound variables/prepared statements.  If this extension meets the
> 5 points I mentioned earlier, I wouldn't have a problem shipping it
> with Sequel.
>
> I wouldn't have a problem completing 2) and 3) myself, and I could
> probably help you with 4) if not complete it myself.  Since I don't
> have an Oracle installation, you'll have to complete 1) yourself,
> though I'd be happy to answer any Sequel-related questions.

2) has now been implemented: 
http://github.com/jeremyevans/sequel/commit/1bef4881b3734001d208671fe8c59c2de30fbbe0

You should be able to get most of what you want with the following
extension code:

module Sequel
  module BindFilter
    def bind_filter(string, bind_vars)
      h = {}
      bind_vars.keys.each{|k| h[k] = :"$#{k}"}
      ds = filter(string, h).bind(bind_vars)
      ds.extend(BoundFilter)
      ds
    end
  end

  module BoundFilter
    def all
      @prepared_args ? super : call(:select)
    end
  end
end

Example usage using SQLite:

$ ruby -I lib bin/sequel -E sqlite:/
irb(main):018:0> Sequel::Dataset.send(:include, Sequel::BindFilter)
=> Sequel::Dataset
irb(main):019:0> DB.create_table(:a){Integer :a}
I, [2009-10-12T16:25:24.856223 #6468]  INFO -- : CREATE TABLE `a` (`a`
integer)
=> []
irb(main):020:0> DB[:a].insert(10)
I, [2009-10-12T16:25:35.909031 #6468]  INFO -- : INSERT INTO `a`
VALUES (10)
=> 1
irb(main):021:0> DB[:a].insert(20)
I, [2009-10-12T16:25:37.407358 #6468]  INFO -- : INSERT INTO `a`
VALUES (20)
=> 2
irb(main):022:0> DB[:a].bind_filter('a > :a', :a=>5).all
I, [2009-10-12T16:26:09.990086 #6468]  INFO -- : SELECT * FROM `a`
WHERE (a > :a); {"a"=>5}
=> [{:a=>10}, {:a=>20}]
irb(main):023:0> DB[:a].bind_filter('a > :a', :a=>10).all
I, [2009-10-12T16:26:15.490741 #6468]  INFO -- : SELECT * FROM `a`
WHERE (a > :a); {"a"=>10}
=> [{:a=>20}]

You'll want to extend the BoundFilter module to handle other methods,
but this shows how easy such an extension would be.  Hopefully you'll
have no objections to this approach.  All that should be required now
for what you want is you submitting bound variable support for
Oracle. :)

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to