Class: ActiveRecord::ConnectionAdapters::OracleEnhancedJDBCConnection::Cursor
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::OracleEnhancedJDBCConnection::Cursor
- Defined in:
- lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb
Instance Method Summary collapse
- #bind_param(position, value, column = nil) ⇒ Object
- #bind_returning_param(position, bind_type) ⇒ Object
- #close ⇒ Object
- #column_names ⇒ Object (also: #get_col_names)
- #column_types ⇒ Object
- #exec ⇒ Object
- #exec_update ⇒ Object
- #fetch(options = {}) ⇒ Object
- #get_returning_param(position, type) ⇒ Object
-
#initialize(connection, raw_statement) ⇒ Cursor
constructor
A new instance of Cursor.
- #metadata ⇒ Object
Constructor Details
#initialize(connection, raw_statement) ⇒ Cursor
Returns a new instance of Cursor.
323 324 325 326 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 323 def initialize(connection, raw_statement) @connection = connection @raw_statement = raw_statement end |
Instance Method Details
#bind_param(position, value, column = nil) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 328 def bind_param(position, value, column = nil) col_type = column && column.type java_value = ruby_to_java_value(value, col_type) case value when Integer @raw_statement.setLong(position, java_value) when Float @raw_statement.setFloat(position, java_value) when BigDecimal @raw_statement.setBigDecimal(position, java_value) when String case col_type when :text @raw_statement.setClob(position, java_value) when :binary @raw_statement.setBlob(position, java_value) when :raw @raw_statement.setString(position, OracleEnhancedAdapter.encode_raw(java_value)) when :decimal @raw_statement.setBigDecimal(position, java_value) else @raw_statement.setString(position, java_value) end when Date, DateTime @raw_statement.setDATE(position, java_value) when Time @raw_statement.setTimestamp(position, java_value) when NilClass if column && column.object_type? @raw_statement.setNull(position, java.sql.Types::STRUCT, column.sql_type) else # TODO: currently nil is always bound as NULL with VARCHAR type. # When nils will actually be used by ActiveRecord as bound parameters # then need to pass actual column type. @raw_statement.setNull(position, java.sql.Types::VARCHAR) end else raise ArgumentError, "Don't know how to bind variable with type #{value.class}" end end |
#bind_returning_param(position, bind_type) ⇒ Object
369 370 371 372 373 374 375 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 369 def bind_returning_param(position, bind_type) @returning_positions ||= [] @returning_positions << position if bind_type == Integer @raw_statement.registerReturnParameter(position, java.sql.Types::BIGINT) end end |
#close ⇒ Object
426 427 428 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 426 def close @raw_statement.close end |
#column_names ⇒ Object Also known as: get_col_names
394 395 396 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 394 def column_names @column_names ||= (1...getColumnCount).map{|i| .getColumnName(i)} end |
#column_types ⇒ Object
390 391 392 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 390 def column_types @column_types ||= (1...getColumnCount).map{|i| .getColumnTypeName(i).to_sym} end |
#exec ⇒ Object
377 378 379 380 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 377 def exec @raw_result_set = @raw_statement.executeQuery true end |
#exec_update ⇒ Object
382 383 384 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 382 def exec_update @raw_statement.executeUpdate end |
#fetch(options = {}) ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 399 def fetch(={}) if @raw_result_set.next get_lob_value = [:get_lob_value] row_values = [] column_types.each_with_index do |column_type, i| row_values << @connection.get_ruby_value_from_result_set(@raw_result_set, i+1, column_type, get_lob_value) end row_values else @raw_result_set.close nil end end |
#get_returning_param(position, type) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 414 def get_returning_param(position, type) rs_position = @returning_positions.index(position) + 1 rs = @raw_statement.getReturnResultSet if rs.next # Assuming that primary key will not be larger as long max value returning_id = rs.getLong(rs_position) rs.wasNull ? nil : returning_id else nil end end |
#metadata ⇒ Object
386 387 388 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb', line 386 def @metadata ||= @raw_result_set.getMetaData end |