Class: ActiveRecord::ConnectionAdapters::IBM_IDS
- Inherits:
-
IBM_DataServer
- Object
- IBM_DataServer
- ActiveRecord::ConnectionAdapters::IBM_IDS
- Defined in:
- lib/active_record/connection_adapters/ibm_db_adapter.rb
Overview
class IBM_DB2_I5
Instance Method Summary collapse
- #change_column(table_name, column_name, type, options) ⇒ Object
-
#change_column_default(table_name, column_name, default) ⇒ Object
IDS specific ALTER TABLE statement to add a default clause IDS requires the data type to be explicitly specified when adding the DEFAULT clause.
-
#get_datetime_mapping ⇒ Object
This method returns the IDS SQL type corresponding to the Rails datetime/timestamp type.
-
#get_time_mapping ⇒ Object
This method returns the IDS SQL type corresponding to the Rails time type.
-
#last_generated_id(stmt) ⇒ Object
Method that returns the last automatically generated ID on the given @connection.
- #primary_key ⇒ Object
-
#query_offset_limit(sql, offset, limit) ⇒ Object
Handling offset/limit as per Informix requirements.
- #rename_column(table_name, column_name, new_column_name) ⇒ Object
-
#reorg_table(table_name) ⇒ Object
Reorganizes the table for column changes.
-
#set_binary_default(value) ⇒ Object
This method throws an error when trying to create a default value on a BLOB/CLOB column for IDS.
-
#set_binary_value ⇒ Object
For Informix Dynamic Server, we treat binary value same as we treat a text value.
-
#set_case(value) ⇒ Object
For Informix Dynamic Server, the arguments to the meta-data functions need to be in lower-case.
-
#set_schema(schema) ⇒ Object
IDS does not support the SET SCHEMA syntax.
-
#set_text_default(value) ⇒ Object
This method throws an error when trying to create a default value on a BLOB/CLOB column for IDS.
Methods inherited from IBM_DataServer
#check_reserved_words, #create_index_after_table, #execute, #initialize, #remove_column, #select_all, #setup_for_lob_table
Constructor Details
This class inherits a constructor from ActiveRecord::ConnectionAdapters::IBM_DataServer
Instance Method Details
#change_column(table_name, column_name, type, options) ⇒ Object
1370 1371 1372 1373 1374 1375 1376 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1370 def change_column(table_name, column_name, type, ) execute "ALTER TABLE #{table_name} MODIFY #{column_name} #{@adapter.type_to_sql(type, [:limit], [:precision], [:scale])}" if ![:default].nil? change_column_default(table_name, column_name, [:default]) end reorg_table(table_name) end |
#change_column_default(table_name, column_name, default) ⇒ Object
IDS specific ALTER TABLE statement to add a default clause IDS requires the data type to be explicitly specified when adding the DEFAULT clause
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1381 def change_column_default(table_name, column_name, default) sql_type = nil @adapter.columns(table_name).select do |col| if (col.name == column_name) sql_type = @adapter.type_to_sql(col.type, col.limit, col.precision, col.scale) end end # SQL statement which alters column's default value change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type} DEFAULT #{@adapter.quote(default)}" stmt = execute(change_column_sql) # Ensures to free the resources associated with the statement ensure IBM_DB::free_result stmt if stmt end |
#get_datetime_mapping ⇒ Object
This method returns the IDS SQL type corresponding to the Rails datetime/timestamp type
1403 1404 1405 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1403 def get_datetime_mapping return "datetime year to fraction(5)" end |
#get_time_mapping ⇒ Object
This method returns the IDS SQL type corresponding to the Rails time type
1409 1410 1411 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1409 def get_time_mapping return "datetime hour to second" end |
#last_generated_id(stmt) ⇒ Object
Method that returns the last automatically generated ID on the given @connection. This method is required by the insert
method. IDS returns the last generated serial value in the SQLCA unlike DB2 where the generated value has to be retrieved using the IDENTITY_VAL_LOCAL function. We used the “stmt” parameter to identify the statement resource from which to get the last generated value
1436 1437 1438 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1436 def last_generated_id(stmt) IBM_DB::get_last_serial_value(stmt) end |
#primary_key ⇒ Object
1366 1367 1368 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1366 def primary_key return "SERIAL(100) PRIMARY KEY" end |
#query_offset_limit(sql, offset, limit) ⇒ Object
Handling offset/limit as per Informix requirements
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1414 def query_offset_limit(sql, offset, limit) if limit != 0 if !offset.nil? # Modifying the SQL to utilize the skip and limit amounts sql.gsub!(/SELECT/i,"SELECT SKIP #{offset} LIMIT #{limit}") else # Modifying the SQL to retrieve only the first #{limit} rows sql = sql.gsub!("SELECT","SELECT FIRST #{limit}") end else # Modifying the SQL to ensure that no rows will be returned sql.gsub!(/SELECT/i,"SELECT * FROM (SELECT") sql << ") WHERE 0 = 1" end end |
#rename_column(table_name, column_name, new_column_name) ⇒ Object
1362 1363 1364 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1362 def rename_column(table_name, column_name, new_column_name) execute "RENAME COLUMN #{table_name}.#{column_name} TO #{new_column_name}" end |
#reorg_table(table_name) ⇒ Object
Reorganizes the table for column changes
1397 1398 1399 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1397 def reorg_table(table_name) execute("UPDATE STATISTICS FOR TABLE #{table_name}") end |
#set_binary_default(value) ⇒ Object
This method throws an error when trying to create a default value on a BLOB/CLOB column for IDS. The documentation states: “if the column is a BLOB or CLOB datatype, NULL is the only valid default value.”
1443 1444 1445 1446 1447 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1443 def set_binary_default(value) unless (value == 'NULL') raise "Informix Dynamic Server only allows NULL as a valid default value for a BLOB data type" end end |
#set_binary_value ⇒ Object
For Informix Dynamic Server, we treat binary value same as we treat a text value. We support literals by converting the insert into a dummy insert and an update (See handle_lobs method above)
1452 1453 1454 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1452 def set_binary_value "'@@@IBMBINARY@@@'" end |
#set_case(value) ⇒ Object
For Informix Dynamic Server, the arguments to the meta-data functions need to be in lower-case
1467 1468 1469 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1467 def set_case(value) value.downcase end |
#set_schema(schema) ⇒ Object
IDS does not support the SET SCHEMA syntax
1359 1360 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1359 def set_schema(schema) end |
#set_text_default(value) ⇒ Object
This method throws an error when trying to create a default value on a BLOB/CLOB column for IDS. The documentation states: “if the column is a BLOB or CLOB datatype, NULL is the only valid default value.”
1459 1460 1461 1462 1463 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1459 def set_text_default(value) unless (value == 'NULL') raise "Informix Dynamic Server only allows NULL as a valid default value for a CLOB data type" end end |