Class: ActiveRecord::ConnectionAdapters::IBM_DataServer

Inherits:
Object
  • Object
show all
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)

Direct Known Subclasses

IBM_DB2, IBM_IDS

Instance Method Summary collapse

Constructor Details

#initialize(adapter, ar3) ⇒ IBM_DataServer

Returns a new instance of IBM_DataServer.



2929
2930
2931
2932
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2929

def initialize(adapter, ar3)
  @adapter = adapter
@isAr3 = ar3
end

Instance Method Details

#change_column_default(table_name, column_name, default) ⇒ Object



3080
3081
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3080

def change_column_default(table_name, column_name, default)
end

#change_column_null(table_name, column_name, null, default) ⇒ Object



3083
3084
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3083

def change_column_null(table_name, column_name, null, default)
end

#check_reserved_words(col_name) ⇒ Object



2946
2947
2948
2949
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2946

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



2937
2938
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2937

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.



3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3044

def execute(sql, name = nil)
  @adapter.puts_log "execute #{sql}"
   
  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 => exec_err
    if exec_err && !exec_err.message.empty?
      @adapter.puts_log "104 error = #{exec_err.message}"
      @adapter.puts_log "104 sql = #{sql}"
      raise StatementInvalid
    else 
      raise
    end
  end
end

#get_datetime_mappingObject



3071
3072
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3071

def get_datetime_mapping
end

#get_double_mappingObject



3077
3078
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3077

def get_double_mapping
end

#get_time_mappingObject



3074
3075
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3074

def get_time_mapping
end

#last_generated_id(stmt) ⇒ Object



2934
2935
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2934

def last_generated_id(stmt)
end

#limit_not_supported_typesObject



3098
3099
3100
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3098

def limit_not_supported_types
  [:integer, :double, :date, :time, :timestamp, :xml, :bigint]
end

#prepare(sql, name = nil) ⇒ Object

Praveen



3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3025

def prepare(sql,name = nil)
  @adapter.puts_log "prepare"
  begin
    stmt = IBM_DB.prepare(@adapter.connection, sql)
    if( stmt )
      stmt
    else
      raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN )
    end
  rescue StandardError => prep_err
    if prep_err && !prep_err.message.empty?
      raise "Failed to prepare sql #{sql} due to: #{prep_err}"
    else 
      raise "An unexpected error occurred during SQLprepare"
    end
  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



2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2953

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 => exec_err
    # Provide details on the current XML columns support
    if exec_err.message.include?('SQLCODE=-1242') && exec_err.message.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: #{exec_err}"
    else
      raise "#{exec_err}"
    end
  end
end

#reorg_table(table_name) ⇒ Object



2943
2944
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2943

def reorg_table(table_name)
end

#select(stmt) ⇒ Object



2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2970

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 => fetch_error # Handle driver fetch errors
    error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT )
    if error_msg && !error_msg.empty?
      raise StatementInvalid,"Failed to retrieve data: #{error_msg}"
    else
      error_msg = "An unexpected error occurred during data retrieval"
      error_msg = error_msg + ": #{fetch_error.message}" if !fetch_error.message.empty?
      raise error_msg
    end
  end
  return results
end

#select_rows(sql, name, stmt, results) ⇒ Object



3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3001

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 => fetch_error # Handle driver fetch errors
    error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT )
    if error_msg && !error_msg.empty?
      raise StatementInvalid,"Failed to retrieve data: #{error_msg}"
    else
      error_msg = "An unexpected error occurred during data retrieval"
      error_msg = error_msg + ": #{fetch_error.message}" if !fetch_error.message.empty?
      raise error_msg
    end
  end
  return results
end

#set_binary_default(value) ⇒ Object



3086
3087
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3086

def set_binary_default(value)
end

#set_binary_valueObject



3089
3090
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3089

def set_binary_value
end

#set_case(value) ⇒ Object



3095
3096
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3095

def set_case(value)
end

#set_schema(schema) ⇒ Object



3066
3067
3068
3069
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3066

def set_schema(schema)
  @adapter.puts_log "set_schema"
  @adapter.execute("SET SCHEMA #{schema}")
end

#set_text_defaultObject



3092
3093
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3092

def set_text_default
end

#setup_for_lob_tableObject



2940
2941
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2940

def setup_for_lob_table ()
end