Class: RDO::Driver
- Inherits:
-
Object
- Object
- RDO::Driver
- Defined in:
- lib/rdo/driver.rb
Overview
Abstract class that is subclassed by each specific driver.
Driver developers should be able to subclass this, then write specs and override the behaviours they need to change.
Ideally all instance method will be overridden by really robust drivers.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Options passed to initialize.
Instance Method Summary collapse
-
#close ⇒ Boolean
Close the current connection, if it is open.
-
#execute(statement, *bind_values) ⇒ Result
Execute a statement against the RDBMS.
-
#initialize(options = {}) ⇒ Driver
constructor
Initialize the Driver with the given options.
-
#interpolate(stmt, params) ⇒ Object
Takes String stmt, which contains ? markers and interpolates the values in Array params.
-
#open ⇒ Boolean
Open a connection to the RDBMS, if it is not already open.
-
#open? ⇒ Boolean
Check if the connection is currently open or not.
-
#prepare(statement) ⇒ StatementExecutor
Create a prepared statement to later be executed with some inputs.
-
#quote(value) ⇒ String
Escape a given value for safe interpolation into a statement.
Constructor Details
#initialize(options = {}) ⇒ Driver
Initialize the Driver with the given options.
Drivers SHOULD call super if overriding.
25 26 27 |
# File 'lib/rdo/driver.rb', line 25 def initialize( = {}) @options = .dup end |
Instance Attribute Details
#options ⇒ Object (readonly)
Options passed to initialize.
17 18 19 |
# File 'lib/rdo/driver.rb', line 17 def @options end |
Instance Method Details
#close ⇒ Boolean
Close the current connection, if it is open.
Drivers MUST override this.
57 58 59 |
# File 'lib/rdo/driver.rb', line 57 def close false end |
#execute(statement, *bind_values) ⇒ Result
Execute a statement against the RDBMS.
The statement can either be a read, or a write operation. Placeholders marked by ‘?’ may be interpolated in the statement, so that bind parameters can be safely provided.
Where the RDBMS natively supports bind parameters, this functionality is used; otherwise, the values are quoted using #quote.
Drivers MUST override this.
96 97 98 |
# File 'lib/rdo/driver.rb', line 96 def execute(statement, *bind_values) Result.new([]) end |
#interpolate(stmt, params) ⇒ Object
Takes String stmt, which contains ? markers and interpolates the values in Array params.
Each value in Array params that is not NilClass, Fixnum or Float is passed to #quote on the Driver.
Non-numeric values are surrounded by String quote.
140 141 142 |
# File 'lib/rdo/driver.rb', line 140 def interpolate(sql, params) # implemented in ext/rdo/rdo.c end |
#open ⇒ Boolean
Open a connection to the RDBMS, if it is not already open.
If it is not possible to open a connection, an RDO::Exception is raised.
This is a no-op: subclasses MUST override this.
37 38 39 |
# File 'lib/rdo/driver.rb', line 37 def open false end |
#open? ⇒ Boolean
Check if the connection is currently open or not.
Drivers MUST override this.
47 48 49 |
# File 'lib/rdo/driver.rb', line 47 def open? false end |
#prepare(statement) ⇒ StatementExecutor
Create a prepared statement to later be executed with some inputs.
Not all drivers support this natively, but it is emulated by default.
This is a default implementation for emulated prepared statements: drivers SHOULD override it if possible.
73 74 75 |
# File 'lib/rdo/driver.rb', line 73 def prepare(statement) emulated_statement_executor(statement) end |
#quote(value) ⇒ String
Escape a given value for safe interpolation into a statement.
The value may be any type of Object and will be formatted to a String as needed.
This should be avoided where the driver natively supports bind parameters.
Drivers MUST override this with a RDBMS-specific solution.
114 115 |
# File 'lib/rdo/driver.rb', line 114 def quote(value) end |