Class: ActiveRecord::ConnectionAdapters::IBM_DataServer
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::IBM_DataServer
- Defined in:
- lib/active_record/connection_adapters/ibm_db_adapter.rb
Overview
This class contains common code across DB’s (DB2 LUW, zOS, i5 and IDS)
Instance Method Summary collapse
- #change_column_default(table_name, column_name, default) ⇒ Object
- #change_column_null(table_name, column_name, null, default) ⇒ Object
- #check_reserved_words(col_name) ⇒ Object
- #create_index_after_table(table_name, cloumn_name) ⇒ Object
-
#execute(sql, _name = nil) ⇒ Object
Akhil Tcheck for if_exits added so that it will try to drop even if the table does not exit.
- #get_datetime_mapping ⇒ Object
- #get_double_mapping ⇒ Object
- #get_time_mapping ⇒ Object
-
#initialize(adapter, ar3) ⇒ IBM_DataServer
constructor
A new instance of IBM_DataServer.
- #last_generated_id(stmt) ⇒ Object
- #limit_not_supported_types ⇒ Object
-
#prepare(sql, _name = nil) ⇒ Object
Praveen.
-
#remove_column(table_name, column_name) ⇒ Object
This is supported by the DB2 for Linux, UNIX, Windows data servers and by the DB2 for i5 data servers.
- #reorg_table(table_name) ⇒ Object
- #select(stmt) ⇒ Object
- #select_rows(_sql, _name, stmt, results) ⇒ Object
- #set_binary_default(value) ⇒ Object
- #set_binary_value ⇒ Object
- #set_case(value) ⇒ Object
- #set_schema(schema) ⇒ Object
- #set_text_default ⇒ Object
- #setup_for_lob_table ⇒ Object
Constructor Details
#initialize(adapter, ar3) ⇒ IBM_DataServer
Returns a new instance of IBM_DataServer.
3600 3601 3602 3603 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3600 def initialize(adapter, ar3) @adapter = adapter @isAr3 = ar3 end |
Instance Method Details
#change_column_default(table_name, column_name, default) ⇒ Object
3732 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3732 def change_column_default(table_name, column_name, default); end |
#change_column_null(table_name, column_name, null, default) ⇒ Object
3734 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3734 def change_column_null(table_name, column_name, null, default); end |
#check_reserved_words(col_name) ⇒ Object
3613 3614 3615 3616 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3613 def check_reserved_words(col_name) @adapter.puts_log 'check_reserved_words' col_name.to_s end |
#create_index_after_table(table_name, cloumn_name) ⇒ Object
3607 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3607 def create_index_after_table(table_name, cloumn_name); end |
#execute(sql, _name = nil) ⇒ Object
Akhil Tcheck for if_exits added so that it will try to drop even if the table does not exit.
3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3701 def execute(sql, _name = nil) @adapter.puts_log "IBM_DataServer execute #{sql} #{Thread.current}" begin if @adapter.connection.nil? || @adapter.connection == false raise ActiveRecord::ConnectionNotEstablished, 'called on a closed database' elsif stmt = IBM_DB.exec(@adapter.connection, sql) stmt # Return the statement object else raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN), sql end rescue StandardError => e raise unless e && !e..empty? @adapter.puts_log "104 error = #{e.}" @adapter.puts_log "104 sql = #{sql}" raise StatementInvalid end end |
#get_datetime_mapping ⇒ Object
3726 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3726 def get_datetime_mapping; end |
#get_double_mapping ⇒ Object
3730 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3730 def get_double_mapping; end |
#get_time_mapping ⇒ Object
3728 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3728 def get_time_mapping; end |
#last_generated_id(stmt) ⇒ Object
3605 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3605 def last_generated_id(stmt); end |
#limit_not_supported_types ⇒ Object
3744 3745 3746 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3744 def limit_not_supported_types %i[integer double date time timestamp xml bigint] end |
#prepare(sql, _name = nil) ⇒ Object
Praveen
3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3686 def prepare(sql, _name = nil) @adapter.puts_log 'prepare' begin stmt = IBM_DB.prepare(@adapter.connection, sql) raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN) unless stmt stmt rescue StandardError => e raise "Failed to prepare sql #{sql} due to: #{e}" if e && !e..empty? raise 'An unexpected error occurred during SQLprepare' end end |
#remove_column(table_name, column_name) ⇒ Object
This is supported by the DB2 for Linux, UNIX, Windows data servers and by the DB2 for i5 data servers
3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3620 def remove_column(table_name, column_name) @adapter.puts_log 'remove_column' begin @adapter.execute "ALTER TABLE #{table_name} DROP #{column_name}" reorg_table(table_name) rescue StandardError => e # Provide details on the current XML columns support raise "#{e}" unless e..include?('SQLCODE=-1242') && e..include?('42997') raise StatementInvalid, "A column that is part of a table containing an XML column cannot be dropped. \ To remove the column, the table must be dropped and recreated without the #{column_name} column: #{e}" end end |
#reorg_table(table_name) ⇒ Object
3611 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3611 def reorg_table(table_name); end |
#select(stmt) ⇒ Object
3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3635 def select(stmt) @adapter.puts_log 'select' results = [] # Fetches all the results available. IBM_DB.fetch_assoc(stmt) returns # an hash for each single record. # The loop stops when there aren't any more valid records to fetch begin if @isAr3 while single_hash = IBM_DB.fetch_assoc(stmt) # Add the record to the +results+ array results << single_hash end else while single_hash = IBM_DB.fetch_array(stmt) # Add the record to the +results+ array results << single_hash end end rescue StandardError => e # Handle driver fetch errors error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT) raise StatementInvalid, "Failed to retrieve data: #{error_msg}" if error_msg && !error_msg.empty? error_msg = 'An unexpected error occurred during data retrieval' error_msg += ": #{e.}" unless e..empty? raise error_msg end results end |
#select_rows(_sql, _name, stmt, results) ⇒ Object
3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3664 def select_rows(_sql, _name, stmt, results) @adapter.puts_log 'select_rows' # Fetches all the results available. IBM_DB.fetch_array(stmt) returns # an array representing a row in a result set. # The loop stops when there aren't any more valid records to fetch begin while single_array = IBM_DB.fetch_array(stmt) # Add the array to results array results << single_array end rescue StandardError => e # Handle driver fetch errors error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT) raise StatementInvalid, "Failed to retrieve data: #{error_msg}" if error_msg && !error_msg.empty? error_msg = 'An unexpected error occurred during data retrieval' error_msg += ": #{e.}" unless e..empty? raise error_msg end results end |
#set_binary_default(value) ⇒ Object
3736 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3736 def set_binary_default(value); end |
#set_binary_value ⇒ Object
3738 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3738 def set_binary_value; end |
#set_case(value) ⇒ Object
3742 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3742 def set_case(value); end |
#set_schema(schema) ⇒ Object
3721 3722 3723 3724 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3721 def set_schema(schema) @adapter.puts_log 'set_schema' @adapter.execute("SET SCHEMA #{schema}") end |
#set_text_default ⇒ Object
3740 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3740 def set_text_default; end |
#setup_for_lob_table ⇒ Object
3609 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3609 def setup_for_lob_table; end |