Class: DBI::DBD::ODBC::Statement
- Inherits:
-
BaseStatement
- Object
- Base
- BaseStatement
- DBI::DBD::ODBC::Statement
- Defined in:
- lib/dbd/odbc/statement.rb
Overview
See DBI::BaseStatement.
Instance Attribute Summary
Attributes inherited from BaseStatement
Instance Method Summary collapse
-
#bind_param(param, value, attribs) ⇒ Object
See DBI::BaseStatement#bind_param.
- #cancel ⇒ Object
-
#column_info ⇒ Object
See DBI::BaseStatement#column_info.
- #execute ⇒ Object
- #fetch ⇒ Object
-
#fetch_scroll(direction, offset) ⇒ Object
See DBI::BaseStatement#fetch_scroll.
- #finish ⇒ Object
-
#initialize(handle, statement) ⇒ Statement
constructor
A new instance of Statement.
-
#rows ⇒ Object
See DBI::BaseStatement#rows.
Methods inherited from BaseStatement
#[], #[]=, #bind_params, #fetch_all, #fetch_many
Constructor Details
#initialize(handle, statement) ⇒ Statement
Returns a new instance of Statement.
5 6 7 8 9 10 |
# File 'lib/dbd/odbc/statement.rb', line 5 def initialize(handle, statement) @statement = statement @handle = handle @params = [] @arr = [] end |
Instance Method Details
#bind_param(param, value, attribs) ⇒ Object
See DBI::BaseStatement#bind_param. This method will also raise DBI::InterfaceError if param
is not a Fixnum, to prevent incorrect binding.
17 18 19 20 |
# File 'lib/dbd/odbc/statement.rb', line 17 def bind_param(param, value, attribs) raise DBI::InterfaceError, "only ? parameters supported" unless param.is_a? Fixnum @params[param-1] = value end |
#cancel ⇒ Object
34 35 36 37 38 |
# File 'lib/dbd/odbc/statement.rb', line 34 def cancel @handle.cancel rescue DBI::DBD::ODBC::ODBCErr => err raise DBI::DatabaseError.new(err.) end |
#column_info ⇒ Object
See DBI::BaseStatement#column_info. These additional attributes are also supported:
-
table: the table this column came from, if available.
-
nullable: boolean, true if NULL is accepted as a value in this column.
-
searchable: FIXME DOCUMENT
-
length: FIXME DOCUMENT
-
unsigned: For numeric columns, whether or not the result value is signed.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/dbd/odbc/statement.rb', line 87 def column_info info = [] @handle.columns(true).each do |col| info << { 'name' => col.name, 'table' => col.table, 'nullable' => col.nullable, 'searchable' => col.searchable, 'precision' => col.precision, 'scale' => col.scale, 'sql_type' => col.type, 'type_name' => DBI::SQL_TYPE_NAMES[col.type], 'length' => col.length, 'unsigned' => col.unsigned } end info rescue DBI::DBD::ODBC::ODBCErr => err raise DBI::DatabaseError.new(err.) end |
#execute ⇒ Object
22 23 24 25 26 |
# File 'lib/dbd/odbc/statement.rb', line 22 def execute @handle.execute(*@params) rescue DBI::DBD::ODBC::ODBCErr => err raise DBI::DatabaseError.new(err.) end |
#fetch ⇒ Object
40 41 42 43 44 |
# File 'lib/dbd/odbc/statement.rb', line 40 def fetch convert_row(@handle.fetch) rescue DBI::DBD::ODBC::ODBCErr => err raise DBI::DatabaseError.new(err.) end |
#fetch_scroll(direction, offset) ⇒ Object
See DBI::BaseStatement#fetch_scroll.
ODBC has a native version of this method and the constnats in the ODBC driver themselves are supported. If you’d prefer to use DBI constants (recommended), you can use these which map to the ODBC functionality:
-
DBI::SQL_FETCH_FIRST
-
DBI::SQL_FETCH_LAST
-
DBI::SQL_FETCH_NEXT
-
DBI::SQL_FETCH_PRIOR
-
DBI::SQL_FETCH_ABSOLUTE
-
DBI::SQL_FETCH_RELATIVE
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dbd/odbc/statement.rb', line 60 def fetch_scroll(direction, offset) direction = case direction when DBI::SQL_FETCH_FIRST then ::ODBC::SQL_FETCH_FIRST when DBI::SQL_FETCH_LAST then ::ODBC::SQL_FETCH_LAST when DBI::SQL_FETCH_NEXT then ::ODBC::SQL_FETCH_NEXT when DBI::SQL_FETCH_PRIOR then ::ODBC::SQL_FETCH_PRIOR when DBI::SQL_FETCH_ABSOLUTE then ::ODBC::SQL_FETCH_ABSOLUTE when DBI::SQL_FETCH_RELATIVE then ::ODBC::SQL_FETCH_RELATIVE else direction end convert_row(@handle.fetch_scroll(direction, offset)) rescue DBI::DBD::ODBC::ODBCErr => err raise DBI::DatabaseError.new(err.) end |
#finish ⇒ Object
28 29 30 31 32 |
# File 'lib/dbd/odbc/statement.rb', line 28 def finish @handle.drop rescue DBI::DBD::ODBC::ODBCErr => err raise DBI::DatabaseError.new(err.) end |
#rows ⇒ Object
See DBI::BaseStatement#rows.
For queries which DBI::SQL.query? returns true, will explicitly return 0. Otherwise, it will return the row processed count.
114 115 116 117 118 119 |
# File 'lib/dbd/odbc/statement.rb', line 114 def rows return 0 if DBI::SQL.query?(@statement) return @handle.nrows rescue DBI::DBD::ODBC::ODBCErr => err raise DBI::DatabaseError.new(err.) end |