Class: RDBI::Driver::JDBC::Statement
- Inherits:
-
Statement
- Object
- Statement
- RDBI::Driver::JDBC::Statement
- Defined in:
- lib/caruby/rdbi/driver/jdbc.rb
Instance Attribute Summary collapse
-
#handle ⇒ Object
Returns the value of attribute handle.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(query, dbh) ⇒ Statement
constructor
A new instance of Statement.
- #new_execution(*binds) ⇒ Object
Constructor Details
#initialize(query, dbh) ⇒ Statement
Returns a new instance of Statement.
282 283 284 285 286 287 288 |
# File 'lib/caruby/rdbi/driver/jdbc.rb', line 282 def initialize(query, dbh) super @handle = @dbh.handle.prepareStatement(query) @input_type_map = build_input_type_map @output_type_map = build_output_type_map end |
Instance Attribute Details
#handle ⇒ Object
Returns the value of attribute handle.
280 281 282 |
# File 'lib/caruby/rdbi/driver/jdbc.rb', line 280 def handle @handle end |
Instance Method Details
#finish ⇒ Object
337 338 339 340 |
# File 'lib/caruby/rdbi/driver/jdbc.rb', line 337 def finish @handle.close super end |
#new_execution(*binds) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/caruby/rdbi/driver/jdbc.rb', line 290 def new_execution(*binds) apply_bindings(*binds) if @handle.execute = @handle.getResultSet.getMetaData columns, tables = [], [] (1...getColumnCount).each do |n| newcol = RDBI::Column.new newcol.name = .getColumnName(n).to_sym newcol.type = SQL_TYPES[.getColumnType(n)][:type] newcol.ruby_type = SQL_TYPES[.getColumnType(n)][:ruby_type] newcol.precision = .getPrecision(n) newcol.scale = .getScale(n) newcol.nullable = .isNullable(n) == 1 ? true : false newcol.table = .getTableName(n) #newcol.primary_key = false columns << newcol end tables = columns.map(&:table).uniq.reject{|t| t == ""} # primary_keys = Hash.new{|h,k| h[k] = []} # tables.each do |tbl| # rs = @dbh.handle.getMetaData.getPrimaryKeys(nil, nil, tbl) # while rs.next # primary_keys[tbl] << rs.getString("COLUMN_NAME").to_sym # end # end # columns.each do |col| # col.primary_key = true if primary_keys[col.table].include? col.name # end return [ Cursor.new(@handle), RDBI::Schema.new(columns, tables), @output_type_map ] end return [ Cursor.new(nil), RDBI::Schema.new(nil, nil), @output_type_map ] end |