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.



2983
2984
2985
2986
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2983

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

Instance Method Details

#change_column_default(table_name, column_name, default) ⇒ Object



3134
3135
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3134

def change_column_default(table_name, column_name, default)
end

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



3137
3138
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3137

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

#check_reserved_words(col_name) ⇒ Object



3000
3001
3002
3003
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3000

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



2991
2992
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2991

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.



3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3098

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



3125
3126
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3125

def get_datetime_mapping
end

#get_double_mappingObject



3131
3132
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3131

def get_double_mapping
end

#get_time_mappingObject



3128
3129
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3128

def get_time_mapping
end

#last_generated_id(stmt) ⇒ Object



2988
2989
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2988

def last_generated_id(stmt)
end

#limit_not_supported_typesObject



3152
3153
3154
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3152

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

#prepare(sql, name = nil) ⇒ Object

Praveen



3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3079

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



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 3007

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



2997
2998
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2997

def reorg_table(table_name)
end

#select(stmt) ⇒ Object



3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3024

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



3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3055

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



3140
3141
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3140

def set_binary_default(value)
end

#set_binary_valueObject



3143
3144
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3143

def set_binary_value
end

#set_case(value) ⇒ Object



3149
3150
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3149

def set_case(value)
end

#set_schema(schema) ⇒ Object



3120
3121
3122
3123
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3120

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

#set_text_defaultObject



3146
3147
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3146

def set_text_default
end

#setup_for_lob_tableObject



2994
2995
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2994

def setup_for_lob_table ()
end