Class: DBI::DBD::SQLite3::Statement
- Inherits:
-
BaseStatement
- Object
- BaseStatement
- DBI::DBD::SQLite3::Statement
- Defined in:
- lib/dbd/sqlite3/statement.rb
Overview
See DBI::BaseStatement.
Instance Method Summary collapse
-
#bind_param(param, value, attribs = nil) ⇒ Object
See DBI::BaseStatement#bind_param.
- #bind_params(*bindvars) ⇒ Object
- #cancel ⇒ Object
- #column_info ⇒ Object
- #execute ⇒ Object
- #fetch ⇒ Object
- #finish ⇒ Object
-
#initialize(sql, db) ⇒ Statement
constructor
A new instance of Statement.
- #rows ⇒ Object
Constructor Details
#initialize(sql, db) ⇒ Statement
Returns a new instance of Statement.
5 6 7 8 9 10 11 12 13 |
# File 'lib/dbd/sqlite3/statement.rb', line 5 def initialize(sql, db) sql.gsub!(/\\\\/) { '\\' } # sqlite underneath does this for us automatically, and it's causing trouble with the rest of the system. @sql = sql @db = db @stmt = db.prepare(sql) @result = nil rescue ::SQLite3::Exception, RuntimeError => err raise DBI::ProgrammingError.new(err.) end |
Instance Method Details
#bind_param(param, value, attribs = nil) ⇒ Object
See DBI::BaseStatement#bind_param. This method will also raise DBI::InterfaceError if param
is not a Fixnum, to prevent incorrect binding.
20 21 22 23 |
# File 'lib/dbd/sqlite3/statement.rb', line 20 def bind_param(param, value, attribs=nil) raise DBI::InterfaceError, "Bound parameter must be an integer" unless param.kind_of? Fixnum @stmt.bind_param(param, value) end |
#bind_params(*bindvars) ⇒ Object
70 71 72 |
# File 'lib/dbd/sqlite3/statement.rb', line 70 def bind_params(*bindvars) @stmt.bind_params(bindvars) end |
#cancel ⇒ Object
74 75 76 77 |
# File 'lib/dbd/sqlite3/statement.rb', line 74 def cancel() @result = nil @index = 0 end |
#column_info ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dbd/sqlite3/statement.rb', line 41 def column_info() @stmt.columns.zip(@stmt.types).map{|name, type_name| m = DBI::DBD::SQLite3.parse_type(type_name) h = { 'name' => name, 'type_name' => m[1], 'sql_type' => begin DBI.const_get('SQL_'+m[1].upcase) rescue NameError DBI::SQL_OTHER end, } h['precision'] = m[3].to_i if m[3] h['scale'] = m[5].to_i if m[5] case h['type_name'] when 'double' h['dbi_type'] = DBI::Type::Float end h } end |
#execute ⇒ Object
25 26 27 28 |
# File 'lib/dbd/sqlite3/statement.rb', line 25 def execute() @result = @stmt.execute @rows = DBI::SQL.query?(@sql) ? 0 : @db.changes end |
#fetch ⇒ Object
35 36 37 38 39 |
# File 'lib/dbd/sqlite3/statement.rb', line 35 def fetch() ret = @result.next return ret unless ret [ret].flatten end |
#finish ⇒ Object
30 31 32 33 |
# File 'lib/dbd/sqlite3/statement.rb', line 30 def finish() @stmt.close rescue nil @result = nil end |
#rows ⇒ Object
66 67 68 |
# File 'lib/dbd/sqlite3/statement.rb', line 66 def rows() @rows end |