Class: FluentQuery::Drivers::DBI::Prepared

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent-query/drivers/dbi/prepared.rb

Overview

DBI prepared query.

Constant Summary collapse

@@matcher =

Holds directives matcher.

nil

Instance Method Summary collapse

Constructor Details

#initialize(driver, query) ⇒ Prepared

Constructor.



47
48
49
50
# File 'lib/fluent-query/drivers/dbi/prepared.rb', line 47

def initialize(driver, query)
    @driver = driver
    @query = query
end

Instance Method Details

#execute(*args) ⇒ Object

Executes the query.



96
97
98
99
# File 'lib/fluent-query/drivers/dbi/prepared.rb', line 96

def execute(*args)
    self.native.execute(*args)
    self.native
end

#matcherObject

Returns directives matcher.



56
57
58
59
60
61
62
63
# File 'lib/fluent-query/drivers/dbi/prepared.rb', line 56

def matcher
    if @@matcher.nil?
        directives = FluentQuery::Compiler::FORMATTING_DIRECTIVES.map { |s| s.to_s }
        @@matcher = Regexp::new("%%(?:" << directives.join("|") << ")(?:([^\w])|$)")
    end
    
    @@matcher
end

#nativeObject

Returns prepared query in the native form.



83
84
85
86
87
88
89
# File 'lib/fluent-query/drivers/dbi/prepared.rb', line 83

def native
    if @native.nil?
        @native = @driver.native_connection.prepare(self.prepared)
    end
    
    @native
end

#preparedObject

Returns prepared query form.



69
70
71
72
73
74
75
76
77
# File 'lib/fluent-query/drivers/dbi/prepared.rb', line 69

def prepared
    if @prepared.nil?
        string = @driver.build_query(@query, :prepare)
        string.gsub!(self.matcher, '?\1')
        @prepared = string
    end
#p @prepared
    @prepared
end