ibm_db 3.0.5-x86-mingw32 → 5.0.5-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGES +4 -0
- data/LICENSE +1 -1
- data/ParameterizedQueries README +6 -6
- data/README +38 -55
- data/ext/Makefile +269 -0
- data/ext/extconf.rb +34 -3
- data/ext/gil_release_version +3 -0
- data/ext/ibm_db-i386-mingw32.def +2 -0
- data/ext/ibm_db.c +100 -108
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +110 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/ext/unicode_support_version +3 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +923 -527
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
- data/lib/mswin32/ibm_db.rb +7 -39
- data/lib/mswin32/rb2x/i386/ibm_db.so +0 -0
- data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
- data/test/cases/adapter_test.rb +133 -58
- data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
- data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
- data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
- data/test/cases/adapters/mysql2/connection_test.rb +210 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
- data/test/cases/adapters/mysql2/enum_test.rb +26 -0
- data/test/cases/adapters/mysql2/explain_test.rb +21 -0
- data/test/cases/adapters/mysql2/json_test.rb +195 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
- data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
- data/test/cases/adapters/mysql2/schema_test.rb +126 -0
- data/test/cases/adapters/mysql2/sp_test.rb +36 -0
- data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
- data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
- data/test/cases/adapters/postgresql/array_test.rb +339 -0
- data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
- data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
- data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
- data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
- data/test/cases/adapters/postgresql/citext_test.rb +78 -0
- data/test/cases/adapters/postgresql/collation_test.rb +53 -0
- data/test/cases/adapters/postgresql/composite_test.rb +132 -0
- data/test/cases/adapters/postgresql/connection_test.rb +257 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
- data/test/cases/adapters/postgresql/domain_test.rb +47 -0
- data/test/cases/adapters/postgresql/enum_test.rb +91 -0
- data/test/cases/adapters/postgresql/explain_test.rb +20 -0
- data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
- data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
- data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
- data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
- data/test/cases/adapters/postgresql/integer_test.rb +25 -0
- data/test/cases/adapters/postgresql/json_test.rb +237 -0
- data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
- data/test/cases/adapters/postgresql/money_test.rb +96 -0
- data/test/cases/adapters/postgresql/network_test.rb +94 -0
- data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
- data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
- data/test/cases/adapters/postgresql/range_test.rb +343 -0
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
- data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
- data/test/cases/adapters/postgresql/schema_test.rb +597 -0
- data/test/cases/adapters/postgresql/serial_test.rb +154 -0
- data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
- data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
- data/test/cases/adapters/postgresql/utils_test.rb +62 -0
- data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
- data/test/cases/adapters/postgresql/xml_test.rb +54 -0
- data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
- data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
- data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
- data/test/cases/aggregations_test.rb +11 -1
- data/test/cases/ar_schema_test.rb +35 -50
- data/test/cases/associations/association_scope_test.rb +1 -6
- data/test/cases/associations/belongs_to_associations_test.rb +122 -10
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
- data/test/cases/associations/callbacks_test.rb +5 -7
- data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
- data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
- data/test/cases/associations/eager_test.rb +158 -73
- data/test/cases/associations/extension_test.rb +7 -2
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +64 -32
- data/test/cases/associations/has_many_associations_test.rb +362 -43
- data/test/cases/associations/has_many_through_associations_test.rb +108 -41
- data/test/cases/associations/has_one_associations_test.rb +105 -8
- data/test/cases/associations/has_one_through_associations_test.rb +6 -3
- data/test/cases/associations/inner_join_association_test.rb +3 -3
- data/test/cases/associations/inverse_associations_test.rb +38 -11
- data/test/cases/associations/join_model_test.rb +59 -36
- data/test/cases/associations/left_outer_join_association_test.rb +88 -0
- data/test/cases/associations/nested_through_associations_test.rb +2 -2
- data/test/cases/associations/required_test.rb +25 -5
- data/test/cases/associations_test.rb +39 -34
- data/test/cases/attribute_decorators_test.rb +9 -8
- data/test/cases/attribute_methods/read_test.rb +5 -5
- data/test/cases/attribute_methods_test.rb +97 -40
- data/test/cases/attribute_set_test.rb +64 -4
- data/test/cases/attribute_test.rb +84 -18
- data/test/cases/attributes_test.rb +151 -34
- data/test/cases/autosave_association_test.rb +149 -36
- data/test/cases/base_test.rb +290 -241
- data/test/cases/batches_test.rb +299 -22
- data/test/cases/binary_test.rb +2 -10
- data/test/cases/bind_parameter_test.rb +76 -66
- data/test/cases/cache_key_test.rb +26 -0
- data/test/cases/calculations_test.rb +167 -15
- data/test/cases/callbacks_test.rb +161 -68
- data/test/cases/coders/json_test.rb +15 -0
- data/test/cases/collection_cache_key_test.rb +115 -0
- data/test/cases/column_definition_test.rb +26 -57
- data/test/cases/comment_test.rb +145 -0
- data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
- data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
- data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
- data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
- data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
- data/test/cases/connection_management_test.rb +46 -56
- data/test/cases/connection_pool_test.rb +195 -20
- data/test/cases/connection_specification/resolver_test.rb +15 -0
- data/test/cases/counter_cache_test.rb +10 -5
- data/test/cases/custom_locking_test.rb +1 -1
- data/test/cases/database_statements_test.rb +18 -3
- data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
- data/test/cases/date_time_precision_test.rb +107 -0
- data/test/cases/defaults_test.rb +85 -89
- data/test/cases/dirty_test.rb +30 -52
- data/test/cases/disconnected_test.rb +4 -2
- data/test/cases/enum_test.rb +178 -24
- data/test/cases/errors_test.rb +16 -0
- data/test/cases/explain_test.rb +32 -21
- data/test/cases/finder_test.rb +273 -148
- data/test/cases/fixture_set/file_test.rb +18 -0
- data/test/cases/fixtures_test.rb +112 -32
- data/test/cases/forbidden_attributes_protection_test.rb +69 -3
- data/test/cases/helper.rb +10 -16
- data/test/cases/hot_compatibility_test.rb +89 -1
- data/test/cases/inheritance_test.rb +284 -53
- data/test/cases/integration_test.rb +23 -7
- data/test/cases/invalid_connection_test.rb +4 -2
- data/test/cases/invertible_migration_test.rb +124 -32
- data/test/cases/json_serialization_test.rb +11 -2
- data/test/cases/locking_test.rb +22 -6
- data/test/cases/log_subscriber_test.rb +106 -17
- data/test/cases/migration/change_schema_test.rb +60 -114
- data/test/cases/migration/change_table_test.rb +34 -2
- data/test/cases/migration/column_attributes_test.rb +7 -23
- data/test/cases/migration/column_positioning_test.rb +8 -8
- data/test/cases/migration/columns_test.rb +17 -11
- data/test/cases/migration/command_recorder_test.rb +47 -2
- data/test/cases/migration/compatibility_test.rb +118 -0
- data/test/cases/migration/create_join_table_test.rb +21 -12
- data/test/cases/migration/foreign_key_test.rb +52 -18
- data/test/cases/migration/index_test.rb +14 -12
- data/test/cases/migration/logger_test.rb +1 -1
- data/test/cases/migration/pending_migrations_test.rb +0 -1
- data/test/cases/migration/references_foreign_key_test.rb +59 -7
- data/test/cases/migration/references_index_test.rb +4 -4
- data/test/cases/migration/references_statements_test.rb +26 -6
- data/test/cases/migration/rename_table_test.rb +25 -25
- data/test/cases/migration_test.rb +279 -81
- data/test/cases/migrator_test.rb +91 -8
- data/test/cases/mixin_test.rb +0 -2
- data/test/cases/modules_test.rb +3 -4
- data/test/cases/multiparameter_attributes_test.rb +24 -2
- data/test/cases/multiple_db_test.rb +11 -4
- data/test/cases/nested_attributes_test.rb +61 -33
- data/test/cases/persistence_test.rb +102 -10
- data/test/cases/pooled_connections_test.rb +3 -3
- data/test/cases/primary_keys_test.rb +170 -31
- data/test/cases/query_cache_test.rb +216 -96
- data/test/cases/quoting_test.rb +65 -19
- data/test/cases/readonly_test.rb +2 -1
- data/test/cases/reflection_test.rb +68 -22
- data/test/cases/relation/delegation_test.rb +3 -8
- data/test/cases/relation/merging_test.rb +10 -14
- data/test/cases/relation/mutation_test.rb +42 -24
- data/test/cases/relation/or_test.rb +92 -0
- data/test/cases/relation/predicate_builder_test.rb +4 -2
- data/test/cases/relation/record_fetch_warning_test.rb +40 -0
- data/test/cases/relation/where_chain_test.rb +23 -99
- data/test/cases/relation/where_clause_test.rb +182 -0
- data/test/cases/relation/where_test.rb +45 -23
- data/test/cases/relation_test.rb +67 -58
- data/test/cases/relations_test.rb +249 -38
- data/test/cases/result_test.rb +10 -0
- data/test/cases/sanitize_test.rb +108 -15
- data/test/cases/schema_dumper_test.rb +119 -125
- data/test/cases/schema_loading_test.rb +52 -0
- data/test/cases/scoping/default_scoping_test.rb +113 -39
- data/test/cases/scoping/named_scoping_test.rb +46 -9
- data/test/cases/scoping/relation_scoping_test.rb +47 -4
- data/test/cases/secure_token_test.rb +32 -0
- data/test/cases/serialization_test.rb +1 -1
- data/test/cases/serialized_attribute_test.rb +93 -6
- data/test/cases/statement_cache_test.rb +38 -0
- data/test/cases/store_test.rb +2 -1
- data/test/cases/suppressor_test.rb +63 -0
- data/test/cases/tasks/database_tasks_test.rb +73 -9
- data/test/cases/tasks/mysql_rake_test.rb +139 -118
- data/test/cases/tasks/postgresql_rake_test.rb +60 -6
- data/test/cases/tasks/sqlite_rake_test.rb +30 -3
- data/test/cases/test_case.rb +28 -20
- data/test/cases/test_fixtures_test.rb +36 -0
- data/test/cases/time_precision_test.rb +103 -0
- data/test/cases/timestamp_test.rb +44 -10
- data/test/cases/touch_later_test.rb +121 -0
- data/test/cases/transaction_callbacks_test.rb +128 -62
- data/test/cases/transaction_isolation_test.rb +2 -2
- data/test/cases/transactions_test.rb +61 -43
- data/test/cases/type/adapter_specific_registry_test.rb +133 -0
- data/test/cases/type/date_time_test.rb +14 -0
- data/test/cases/type/integer_test.rb +2 -96
- data/test/cases/type/string_test.rb +0 -14
- data/test/cases/type_test.rb +39 -0
- data/test/cases/types_test.rb +1 -118
- data/test/cases/unconnected_test.rb +1 -1
- data/test/cases/validations/absence_validation_test.rb +73 -0
- data/test/cases/validations/association_validation_test.rb +13 -2
- data/test/cases/validations/i18n_validation_test.rb +6 -10
- data/test/cases/validations/length_validation_test.rb +62 -30
- data/test/cases/validations/presence_validation_test.rb +36 -1
- data/test/cases/validations/uniqueness_validation_test.rb +128 -37
- data/test/cases/validations_repair_helper.rb +2 -6
- data/test/cases/validations_test.rb +36 -7
- data/test/cases/view_test.rb +102 -5
- data/test/cases/yaml_serialization_test.rb +21 -26
- data/test/config.example.yml +97 -0
- data/test/fixtures/bad_posts.yml +9 -0
- data/test/fixtures/books.yml +20 -0
- data/test/fixtures/content.yml +3 -0
- data/test/fixtures/content_positions.yml +3 -0
- data/test/fixtures/dead_parrots.yml +5 -0
- data/test/fixtures/live_parrots.yml +4 -0
- data/test/fixtures/naked/yml/parrots.yml +2 -0
- data/test/fixtures/naked/yml/trees.yml +3 -0
- data/test/fixtures/nodes.yml +29 -0
- data/test/fixtures/other_comments.yml +6 -0
- data/test/fixtures/other_dogs.yml +2 -0
- data/test/fixtures/other_posts.yml +7 -0
- data/test/fixtures/price_estimates.yml +10 -1
- data/test/fixtures/trees.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +1 -1
- data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
- data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
- data/test/migrations/missing/1_people_have_last_names.rb +2 -2
- data/test/migrations/missing/3_we_need_reminders.rb +2 -2
- data/test/migrations/missing/4_innocent_jointable.rb +2 -2
- data/test/migrations/rename/1_we_need_things.rb +2 -2
- data/test/migrations/rename/2_rename_things.rb +2 -2
- data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy2/1_create_articles.rb +1 -1
- data/test/migrations/to_copy2/2_create_comments.rb +1 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
- data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
- data/test/models/admin/randomly_named_c1.rb +6 -2
- data/test/models/aircraft.rb +1 -0
- data/test/models/author.rb +4 -7
- data/test/models/bird.rb +1 -1
- data/test/models/book.rb +5 -0
- data/test/models/bulb.rb +2 -1
- data/test/models/car.rb +3 -0
- data/test/models/cat.rb +10 -0
- data/test/models/chef.rb +1 -0
- data/test/models/club.rb +2 -0
- data/test/models/comment.rb +17 -5
- data/test/models/company.rb +4 -2
- data/test/models/company_in_module.rb +1 -1
- data/test/models/contact.rb +1 -1
- data/test/models/content.rb +40 -0
- data/test/models/customer.rb +8 -2
- data/test/models/developer.rb +19 -0
- data/test/models/face.rb +1 -1
- data/test/models/guitar.rb +4 -0
- data/test/models/hotel.rb +2 -0
- data/test/models/member.rb +1 -0
- data/test/models/member_detail.rb +4 -3
- data/test/models/mentor.rb +3 -0
- data/test/models/mocktail_designer.rb +2 -0
- data/test/models/node.rb +5 -0
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +3 -0
- data/test/models/other_dog.rb +5 -0
- data/test/models/owner.rb +4 -1
- data/test/models/parrot.rb +6 -7
- data/test/models/person.rb +0 -1
- data/test/models/pet.rb +3 -0
- data/test/models/pet_treasure.rb +6 -0
- data/test/models/pirate.rb +3 -3
- data/test/models/post.rb +18 -9
- data/test/models/project.rb +9 -0
- data/test/models/randomly_named_c1.rb +1 -1
- data/test/models/recipe.rb +3 -0
- data/test/models/ship.rb +8 -2
- data/test/models/tag.rb +6 -0
- data/test/models/topic.rb +2 -8
- data/test/models/tree.rb +3 -0
- data/test/models/tuning_peg.rb +4 -0
- data/test/models/user.rb +14 -0
- data/test/models/uuid_item.rb +6 -0
- data/test/schema/mysql2_specific_schema.rb +33 -23
- data/test/schema/oracle_specific_schema.rb +1 -4
- data/test/schema/postgresql_specific_schema.rb +36 -124
- data/test/schema/schema.rb +170 -65
- data/test/schema/schema.rb.original +1057 -0
- data/test/schema/sqlite_specific_schema.rb +1 -5
- data/test/support/connection.rb +1 -0
- data/test/support/schema_dumping_helper.rb +1 -1
- data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
- data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
- metadata +146 -30
- data/lib/mswin32/rb19x/ibm_db.so +0 -0
- data/lib/mswin32/rb21x/i386/ibm_db.so +0 -0
- data/lib/mswin32/rb22x/i386/ibm_db.so +0 -0
- data/lib/mswin32/rb23x/i386/ibm_db.so +0 -0
- data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
- data/test/cases/attribute_methods/serialization_test.rb +0 -29
- data/test/cases/migration/change_schema_test - Copy.rb +0 -448
- data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
- data/test/cases/migration/table_and_index_test.rb +0 -24
- data/test/cases/relation/where_test2.rb +0 -36
- data/test/cases/type/decimal_test.rb +0 -56
- data/test/cases/type/unsigned_integer_test.rb +0 -18
- data/test/cases/xml_serialization_test.rb +0 -457
- data/test/fixtures/naked/csv/accounts.csv +0 -1
- data/test/schema/mysql_specific_schema.rb +0 -70
data/ext/ibm_db.o
ADDED
Binary file
|
data/ext/ibm_db.so
ADDED
Binary file
|
data/ext/mkmf.log
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
gil_release_version is:
|
2
|
+
/* begin */
|
3
|
+
1: #ifndef GIL_RELEASE_VERSION
|
4
|
+
2: #define GIL_RELEASE_VERSION
|
5
|
+
3: #endif
|
6
|
+
/* end */
|
7
|
+
|
8
|
+
unicode_support_version is:
|
9
|
+
/* begin */
|
10
|
+
1: #ifndef UNICODE_SUPPORT_VERSION
|
11
|
+
2: #define UNICODE_SUPPORT_VERSION
|
12
|
+
3: #endif
|
13
|
+
/* end */
|
14
|
+
|
15
|
+
have_library: checking for SQLConnect() in -ldb2cli... -------------------- yes
|
16
|
+
|
17
|
+
"i686-w64-mingw32-gcc -o conftest.exe -IC:/Ruby26/include/ruby-2.6.0/i386-mingw32 -IC:/Ruby26/include/ruby-2.6.0/ruby/backward -IC:/Ruby26/include/ruby-2.6.0 -I. -IC:\clidriver\32-bit\clidriver/include -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-fast-math conftest.c -L. -LC:/Ruby26/lib -LC:\clidriver\32-bit\clidriver/lib -L. -pipe -s -lmsvcrt-ruby260 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
|
18
|
+
checked program was:
|
19
|
+
/* begin */
|
20
|
+
1: #include "ruby.h"
|
21
|
+
2:
|
22
|
+
3: #include <winsock2.h>
|
23
|
+
4: #include <windows.h>
|
24
|
+
5: int main(int argc, char **argv)
|
25
|
+
6: {
|
26
|
+
7: return 0;
|
27
|
+
8: }
|
28
|
+
/* end */
|
29
|
+
|
30
|
+
"i686-w64-mingw32-gcc -o conftest.exe -IC:/Ruby26/include/ruby-2.6.0/i386-mingw32 -IC:/Ruby26/include/ruby-2.6.0/ruby/backward -IC:/Ruby26/include/ruby-2.6.0 -I. -IC:\clidriver\32-bit\clidriver/include -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-fast-math conftest.c -L. -LC:/Ruby26/lib -LC:\clidriver\32-bit\clidriver/lib -L. -pipe -s -lmsvcrt-ruby260 -ldb2cli -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
|
31
|
+
conftest.c: In function 't':
|
32
|
+
conftest.c:17:57: error: 'SQLConnect' undeclared (first use in this function); did you mean 'WSAConnect'?
|
33
|
+
17 | int t(void) { void ((*volatile p)()); p = (void ((*)()))SQLConnect; return !p; }
|
34
|
+
| ^~~~~~~~~~
|
35
|
+
| WSAConnect
|
36
|
+
conftest.c:17:57: note: each undeclared identifier is reported only once for each function it appears in
|
37
|
+
checked program was:
|
38
|
+
/* begin */
|
39
|
+
1: #include "ruby.h"
|
40
|
+
2:
|
41
|
+
3: #include <winsock2.h>
|
42
|
+
4: #include <windows.h>
|
43
|
+
5:
|
44
|
+
6: /*top*/
|
45
|
+
7: extern int t(void);
|
46
|
+
8: int main(int argc, char **argv)
|
47
|
+
9: {
|
48
|
+
10: if (argc > 1000000) {
|
49
|
+
11: int (* volatile tp)(void)=(int (*)(void))&t;
|
50
|
+
12: printf("%d", (*tp)());
|
51
|
+
13: }
|
52
|
+
14:
|
53
|
+
15: return 0;
|
54
|
+
16: }
|
55
|
+
17: int t(void) { void ((*volatile p)()); p = (void ((*)()))SQLConnect; return !p; }
|
56
|
+
/* end */
|
57
|
+
|
58
|
+
"i686-w64-mingw32-gcc -o conftest.exe -IC:/Ruby26/include/ruby-2.6.0/i386-mingw32 -IC:/Ruby26/include/ruby-2.6.0/ruby/backward -IC:/Ruby26/include/ruby-2.6.0 -I. -IC:\clidriver\32-bit\clidriver/include -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-fast-math conftest.c -L. -LC:/Ruby26/lib -LC:\clidriver\32-bit\clidriver/lib -L. -pipe -s -lmsvcrt-ruby260 -ldb2cli -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
|
59
|
+
checked program was:
|
60
|
+
/* begin */
|
61
|
+
1: #include "ruby.h"
|
62
|
+
2:
|
63
|
+
3: #include <winsock2.h>
|
64
|
+
4: #include <windows.h>
|
65
|
+
5:
|
66
|
+
6: /*top*/
|
67
|
+
7: extern int t(void);
|
68
|
+
8: int main(int argc, char **argv)
|
69
|
+
9: {
|
70
|
+
10: if (argc > 1000000) {
|
71
|
+
11: int (* volatile tp)(void)=(int (*)(void))&t;
|
72
|
+
12: printf("%d", (*tp)());
|
73
|
+
13: }
|
74
|
+
14:
|
75
|
+
15: return 0;
|
76
|
+
16: }
|
77
|
+
17: extern void SQLConnect();
|
78
|
+
18: int t(void) { SQLConnect(); return 0; }
|
79
|
+
/* end */
|
80
|
+
|
81
|
+
--------------------
|
82
|
+
|
83
|
+
have_header: checking for gil_release_version... -------------------- yes
|
84
|
+
|
85
|
+
"i686-w64-mingw32-gcc -E -IC:/Ruby26/include/ruby-2.6.0/i386-mingw32 -IC:/Ruby26/include/ruby-2.6.0/ruby/backward -IC:/Ruby26/include/ruby-2.6.0 -I. -IC:\clidriver\32-bit\clidriver/include -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-fast-math conftest.c -o conftest.i"
|
86
|
+
checked program was:
|
87
|
+
/* begin */
|
88
|
+
1: #include "ruby.h"
|
89
|
+
2:
|
90
|
+
3: #include <winsock2.h>
|
91
|
+
4: #include <windows.h>
|
92
|
+
5: #include <gil_release_version>
|
93
|
+
/* end */
|
94
|
+
|
95
|
+
--------------------
|
96
|
+
|
97
|
+
have_header: checking for unicode_support_version... -------------------- yes
|
98
|
+
|
99
|
+
"i686-w64-mingw32-gcc -E -IC:/Ruby26/include/ruby-2.6.0/i386-mingw32 -IC:/Ruby26/include/ruby-2.6.0/ruby/backward -IC:/Ruby26/include/ruby-2.6.0 -I. -IC:\clidriver\32-bit\clidriver/include -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-fast-math conftest.c -o conftest.i"
|
100
|
+
checked program was:
|
101
|
+
/* begin */
|
102
|
+
1: #include "ruby.h"
|
103
|
+
2:
|
104
|
+
3: #include <winsock2.h>
|
105
|
+
4: #include <windows.h>
|
106
|
+
5: #include <unicode_support_version>
|
107
|
+
/* end */
|
108
|
+
|
109
|
+
--------------------
|
110
|
+
|
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# +----------------------------------------------------------------------+
|
2
2
|
# | Licensed Materials - Property of IBM |
|
3
3
|
# | |
|
4
|
-
# | (C) Copyright IBM Corporation 2006-
|
4
|
+
# | (C) Copyright IBM Corporation 2006- 2018 |
|
5
5
|
# +----------------------------------------------------------------------+
|
6
6
|
# | Authors: Antonio Cangiano <cangiano@ca.ibm.com> |
|
7
7
|
# | : Mario Ds Briggs <mario.briggs@in.ibm.com> |
|
@@ -9,115 +9,163 @@
|
|
9
9
|
# | : Arvind Gupta <arvindgu@in.ibm.com> |
|
10
10
|
# +----------------------------------------------------------------------+
|
11
11
|
|
12
|
+
|
12
13
|
require 'active_record/connection_adapters/abstract_adapter'
|
13
|
-
require 'arel/visitors/
|
14
|
+
require 'arel/visitors/visitor'
|
14
15
|
require 'active_support/core_ext/string/strip'
|
16
|
+
require 'active_record/type'
|
17
|
+
require 'active_record/connection_adapters/sql_type_metadata'
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
module CallChain
|
22
|
+
def self.caller_method(depth=1)
|
23
|
+
parse_caller(caller(depth+1).first).last
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Copied from ActionMailer
|
29
|
+
def self.parse_caller(at)
|
30
|
+
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
|
31
|
+
file = Regexp.last_match[1]
|
32
|
+
line = Regexp.last_match[2].to_i
|
33
|
+
method = Regexp.last_match[3]
|
34
|
+
[file, line, method]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
15
39
|
|
16
40
|
module ActiveRecord
|
17
|
-
class Relation
|
18
|
-
def insert(values)
|
19
|
-
primary_key_value = nil
|
20
41
|
|
21
|
-
if primary_key && Hash === values
|
22
|
-
primary_key_value = values[values.keys.find { |k|
|
23
|
-
k.name == primary_key
|
24
|
-
}]
|
25
42
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
43
|
+
class SchemaMigration < ActiveRecord::Base
|
44
|
+
class << self
|
45
|
+
def create_table
|
46
|
+
#puts "Calling method : " << CallChain.caller_method << "\n"
|
47
|
+
#puts "Calling method for create_table(): " << String(caller(start=1, length=nil) )
|
48
|
+
unless table_exists?
|
49
|
+
version_options = connection.internal_string_options_for_primary_key
|
50
|
+
|
51
|
+
connection.create_table(table_name,id:false) do |t|
|
52
|
+
t.string :version, version_options
|
53
|
+
end
|
30
54
|
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
class Relation
|
31
62
|
|
32
|
-
|
33
|
-
|
63
|
+
def insert(values)
|
64
|
+
primary_key_value = nil
|
34
65
|
|
35
|
-
|
66
|
+
if primary_key && Hash === values
|
67
|
+
primary_key_value = values[values.keys.find { |k|
|
68
|
+
k.name == primary_key
|
69
|
+
}]
|
36
70
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
71
|
+
if !primary_key_value && connection.prefetch_primary_key?(klass.table_name)
|
72
|
+
primary_key_value = connection.next_sequence_value(klass.sequence_name)
|
73
|
+
values[klass.arel_table[klass.primary_key]] = primary_key_value
|
74
|
+
end
|
75
|
+
end
|
41
76
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
77
|
+
im = arel.create_insert
|
78
|
+
im.into @table
|
45
79
|
|
46
|
-
|
47
|
-
im.values = Arel.sql(connection.empty_insert_statement_value(klass.primary_key))
|
48
|
-
else
|
49
|
-
im.insert substitutes
|
50
|
-
end
|
80
|
+
conn = @klass.connection
|
51
81
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
82
|
+
substitutes = values.sort_by { |arel_attr,_| arel_attr.name }
|
83
|
+
binds = substitutes.map do |arel_attr, value|
|
84
|
+
[@klass.columns_hash[arel_attr.name], value]
|
85
|
+
end
|
86
|
+
|
87
|
+
#substitutes.each_with_index do |tuple, i|
|
88
|
+
# tuple[1] = conn.substitute_at(binds[i][0], i)
|
89
|
+
#end
|
90
|
+
|
91
|
+
substitutes, binds = substitute_values values
|
61
92
|
|
62
|
-
|
93
|
+
|
94
|
+
if values.empty? # empty insert
|
95
|
+
im.values = Arel.sql(connection.empty_insert_statement_value(klass.primary_key))
|
96
|
+
else
|
97
|
+
im.insert substitutes
|
98
|
+
end
|
99
|
+
conn.insert(
|
100
|
+
im,
|
101
|
+
'SQL',
|
102
|
+
primary_key,
|
103
|
+
primary_key_value,
|
104
|
+
nil,
|
105
|
+
binds)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
class Base
|
63
112
|
# Method required to handle LOBs and XML fields.
|
64
113
|
# An after save callback checks if a marker has been inserted through
|
65
114
|
# the insert or update, and then proceeds to update that record with
|
66
115
|
# the actual large object through a prepared statement (param binding).
|
67
116
|
after_save :handle_lobs
|
68
117
|
def handle_lobs()
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
+
if self.class.connection.kind_of?(ConnectionAdapters::IBM_DBAdapter)
|
119
|
+
# Checks that the insert or update had at least a BLOB, CLOB or XML field
|
120
|
+
self.class.connection.sql.each do |clob_sql|
|
121
|
+
if clob_sql =~ /BLOB\('(.*)'\)/i ||
|
122
|
+
clob_sql =~ /@@@IBMTEXT@@@/i ||
|
123
|
+
clob_sql =~ /@@@IBMXML@@@/i ||
|
124
|
+
clob_sql =~ /@@@IBMBINARY@@@/i
|
125
|
+
update_query = "UPDATE #{self.class.table_name} SET ("
|
126
|
+
counter = 0
|
127
|
+
values = []
|
128
|
+
params = []
|
129
|
+
# Selects only binary, text and xml columns
|
130
|
+
self.class.columns.select{|col| col.sql_type.to_s =~ /blob|binary|clob|text|xml/i }.each do |col|
|
131
|
+
|
132
|
+
if counter == 0
|
133
|
+
update_query << "#{col.name}"
|
134
|
+
else
|
135
|
+
update_query << ",#{col.name}"
|
136
|
+
end
|
137
|
+
|
138
|
+
# Add a '?' for the parameter or a NULL if the value is nil or empty
|
139
|
+
# (except for a CLOB field where '' can be a value)
|
140
|
+
if self[col.name].nil? ||
|
141
|
+
self[col.name] == {} ||
|
142
|
+
self[col.name] == [] ||
|
143
|
+
(self[col.name] == '' && !(col.sql_type.to_s =~ /text|clob/i))
|
144
|
+
params << 'NULL'
|
145
|
+
else
|
146
|
+
if (col.cast_type.is_a?(::ActiveRecord::Type::Serialized))
|
147
|
+
values << YAML.dump(self[col.name])
|
148
|
+
else
|
149
|
+
values << self[col.name]
|
150
|
+
end
|
151
|
+
params << '?'
|
152
|
+
end
|
153
|
+
counter += 1
|
154
|
+
end
|
155
|
+
# no subsequent update is required if no relevant columns are found
|
156
|
+
next if counter == 0
|
157
|
+
|
158
|
+
update_query << ") = "
|
159
|
+
# IBM_DB accepts 'SET (column) = NULL' but not (NULL),
|
160
|
+
# therefore the sql needs to be changed for a single NULL field.
|
161
|
+
if params.size==1 && params[0] == 'NULL'
|
162
|
+
update_query << "NULL"
|
163
|
+
else
|
164
|
+
update_query << "(" + params.join(',') + ")"
|
165
|
+
end
|
118
166
|
|
119
|
-
|
120
|
-
|
167
|
+
update_query << " WHERE #{self.class.primary_key} = ?"
|
168
|
+
values << self[self.class.primary_key.downcase]
|
121
169
|
|
122
170
|
begin
|
123
171
|
unless stmt = IBM_DB.prepare(self.class.connection.connection, update_query)
|
@@ -148,6 +196,7 @@ module ActiveRecord
|
|
148
196
|
end # handle_lobs
|
149
197
|
private :handle_lobs
|
150
198
|
|
199
|
+
|
151
200
|
# Establishes a connection to a specified database using the credentials provided
|
152
201
|
# with the +config+ argument. All the ActiveRecord objects will use this connection
|
153
202
|
def self.ibm_db_connection(config)
|
@@ -160,16 +209,16 @@ module ActiveRecord
|
|
160
209
|
end
|
161
210
|
|
162
211
|
#if( config.has_key?(:parameterized) && config[:parameterized] == true )
|
163
|
-
|
164
|
-
|
212
|
+
# require 'active_record/connection_adapters/ibm_db_pstmt'
|
213
|
+
# end
|
165
214
|
|
166
215
|
# Check if class TableDefinition responds to indexes method to determine if we are on AR 3 or AR 4.
|
167
216
|
# This is a interim hack ti ensure backward compatibility. To remove as we move out of AR 3 support or have a better way to determine which version of AR being run against.
|
168
|
-
|
217
|
+
checkClass = ActiveRecord::ConnectionAdapters::TableDefinition.new(self,nil)
|
169
218
|
if(checkClass.respond_to?(:indexes))
|
170
219
|
isAr3 = false
|
171
220
|
else
|
172
|
-
isAr3
|
221
|
+
isAr3= true
|
173
222
|
end
|
174
223
|
# Converts all +config+ keys to symbols
|
175
224
|
config = config.symbolize_keys
|
@@ -252,7 +301,6 @@ module ActiveRecord
|
|
252
301
|
conn_string << "SECURITY=#{config[:security]};" if config.has_key?(:security)
|
253
302
|
conn_string << "AUTHENTICATION=#{config[:authentication]};" if config.has_key?(:authentication)
|
254
303
|
conn_string << "CONNECTTIMEOUT=#{config[:timeout]};" if config.has_key?(:timeout)
|
255
|
-
|
256
304
|
connection = IBM_DB.connect( conn_string, '', '', conn_options, set_quoted_literal_replacement )
|
257
305
|
else
|
258
306
|
# No host implies a local catalog-based connection: +database+ represents catalog alias
|
@@ -278,40 +326,144 @@ module ActiveRecord
|
|
278
326
|
end
|
279
327
|
end # class Base
|
280
328
|
|
329
|
+
|
330
|
+
|
281
331
|
module ConnectionAdapters
|
332
|
+
class Column
|
333
|
+
def self.binary_to_string(value)
|
334
|
+
# Returns a string removing the eventual BLOB scalar function
|
335
|
+
value.to_s.gsub(/"SYSIBM"."BLOB"\('(.*)'\)/i,'\1')
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
module Quoting
|
340
|
+
def lookup_cast_type_from_column(column) # :nodoc:
|
341
|
+
lookup_cast_type(column.sql_type_metadata)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
module Savepoints
|
346
|
+
def create_savepoint(name = current_savepoint_name)
|
347
|
+
execute("SAVEPOINT #{name} ON ROLLBACK RETAIN CURSORS")
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
|
352
|
+
module ColumnDumper
|
353
|
+
def prepare_column_options(column)
|
354
|
+
spec = {}
|
355
|
+
|
356
|
+
if limit = schema_limit(column)
|
357
|
+
spec[:limit] = limit
|
358
|
+
end
|
359
|
+
|
360
|
+
if precision = schema_precision(column)
|
361
|
+
spec[:precision] = precision
|
362
|
+
end
|
363
|
+
|
364
|
+
if scale = schema_scale(column)
|
365
|
+
spec[:scale] = scale
|
366
|
+
end
|
367
|
+
|
368
|
+
default = schema_default(column) if column.has_default?
|
369
|
+
spec[:default] = default unless default.nil?
|
370
|
+
|
371
|
+
spec[:null] = 'false' unless column.null
|
372
|
+
|
373
|
+
if collation = schema_collation(column)
|
374
|
+
spec[:collation] = collation
|
375
|
+
end
|
376
|
+
|
377
|
+
spec[:comment] = column.comment.inspect if column.comment.present?
|
378
|
+
|
379
|
+
spec
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
def schema_limit(column)
|
384
|
+
limit = column.limit unless column.bigint?
|
385
|
+
#limit.inspect if limit && limit != native_database_types[column.type][:limit]
|
386
|
+
|
387
|
+
limit.inspect if limit && limit != native_database_types[column.type.to_sym][:limit]
|
388
|
+
|
389
|
+
end
|
390
|
+
|
391
|
+
=begin
|
392
|
+
def column_spec_for_primary_key(column)
|
393
|
+
if column.bigint?
|
394
|
+
spec = { id: :bigint.inspect }
|
395
|
+
spec[:default] = schema_default(column) || 'nil' unless column.auto_increment?
|
396
|
+
else
|
397
|
+
#spec = super
|
398
|
+
end
|
399
|
+
#spec[:unsigned] = 'true' if column.unsigned?
|
400
|
+
#spec
|
401
|
+
""
|
402
|
+
end
|
403
|
+
=end
|
404
|
+
|
405
|
+
end
|
406
|
+
|
282
407
|
module SchemaStatements
|
283
|
-
|
408
|
+
|
409
|
+
def internal_string_options_for_primary_key # :nodoc:
|
410
|
+
{ primary_key: true}
|
411
|
+
{ version_options: "PRIMARY KEY NOT NULL"}
|
412
|
+
end
|
413
|
+
|
414
|
+
def drop_table(table_name,options={})
|
415
|
+
execute("DROP TABLE #{quote_table_name(table_name)}", options)
|
416
|
+
#execute("DROP TABLE#{' IF EXISTS' if options[:if_exists]} #{quote_table_name(table_name)}"
|
417
|
+
end
|
418
|
+
|
419
|
+
=begin
|
420
|
+
def create_table_definition(name, temporary, options,as = nil)
|
284
421
|
TableDefinition.new self, name, temporary, options
|
285
422
|
end
|
423
|
+
=end
|
424
|
+
def create_table_definition(*args, **options)
|
425
|
+
TableDefinition.new(self, *args, **options)
|
426
|
+
end
|
286
427
|
|
287
|
-
|
288
|
-
|
428
|
+
def remove_foreign_key(from_table, options_or_to_table = {})
|
429
|
+
return unless supports_foreign_keys?
|
289
430
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
431
|
+
if options_or_to_table.is_a?(Hash)
|
432
|
+
options = options_or_to_table
|
433
|
+
else
|
434
|
+
options = { column: foreign_key_column_for(options_or_to_table) }
|
435
|
+
end
|
436
|
+
|
437
|
+
fk_name_to_delete = options.fetch(:name) do
|
438
|
+
fk_to_delete = foreign_keys(@servertype.set_case(from_table)).detect {|fk| "#{@servertype.set_case(fk.column)}" == "#{servertype.set_case(options[:column])}"}
|
439
|
+
|
440
|
+
if fk_to_delete
|
441
|
+
fk_to_delete.name
|
442
|
+
else
|
443
|
+
raise ArgumentError, "Table '#{from_table}' has no foreign key on column '#{options[:column]}'"
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
at = create_alter_table from_table
|
448
|
+
at.drop_foreign_key fk_name_to_delete
|
308
449
|
|
309
|
-
|
310
|
-
|
311
|
-
|
450
|
+
execute schema_creation.accept(at)
|
451
|
+
end
|
452
|
+
end #end of Module SchemaStatements
|
312
453
|
|
313
|
-
|
314
|
-
|
454
|
+
|
455
|
+
#class IBM_DBColumn < Column
|
456
|
+
class IBM_DBColumn < ConnectionAdapters::Column # :nodoc:
|
457
|
+
# delegate :precision, :scale, :limit, :type, :sql_type, to: :sql_type_metadata, allow_nil: true
|
458
|
+
|
459
|
+
def initialize(*)
|
460
|
+
super
|
461
|
+
end
|
462
|
+
|
463
|
+
#def initialize(column_name, column_default_value, sqltype_metadata, column_nullable, table_name, default_function, collation, comment)
|
464
|
+
#super(column_name, column_default_value, sqltype_metadata, column_nullable, table_name)
|
465
|
+
#end
|
466
|
+
|
315
467
|
# Casts value (which is a String) to an appropriate instance
|
316
468
|
=begin
|
317
469
|
def type_cast(value)
|
@@ -321,239 +473,234 @@ module ActiveRecord
|
|
321
473
|
super
|
322
474
|
end
|
323
475
|
=end
|
324
|
-
# Used to convert from BLOBs to Strings
|
325
|
-
def self.binary_to_string(value)
|
326
|
-
# Returns a string removing the eventual BLOB scalar function
|
327
|
-
value.to_s.gsub(/"SYSIBM"."BLOB"\('(.*)'\)/i,'\1')
|
328
|
-
end
|
329
476
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
:binary
|
337
|
-
when /smallint/i
|
338
|
-
:boolean
|
339
|
-
when /int|serial/i
|
340
|
-
:integer
|
341
|
-
when /decimal|numeric|decfloat/i
|
342
|
-
:decimal
|
343
|
-
when /float|double|real/i
|
344
|
-
:float
|
345
|
-
when /timestamp|datetime/i
|
346
|
-
:timestamp
|
347
|
-
when /time/i
|
348
|
-
:time
|
349
|
-
when /date/i
|
350
|
-
:date
|
351
|
-
when /vargraphic/i
|
352
|
-
:vargraphic
|
353
|
-
when /graphic/i
|
354
|
-
:graphic
|
355
|
-
when /clob|text/i
|
356
|
-
:text
|
357
|
-
when /xml/i
|
358
|
-
:xml
|
359
|
-
when /blob|binary/i
|
360
|
-
:binary
|
361
|
-
when /char/i
|
362
|
-
:string
|
363
|
-
when /boolean/i
|
364
|
-
:boolean
|
365
|
-
when /rowid/i # rowid is a supported datatype on z/OS and i/5
|
366
|
-
:rowid
|
367
|
-
end
|
368
|
-
end # method simplified_type
|
477
|
+
# Used to convert from BLOBs to Strings
|
478
|
+
def self.binary_to_string(value)
|
479
|
+
# Returns a string removing the eventual BLOB scalar function
|
480
|
+
value.to_s.gsub(/"SYSIBM"."BLOB"\('(.*)'\)/i,'\1')
|
481
|
+
end
|
482
|
+
|
369
483
|
end #class IBM_DBColumn
|
370
484
|
|
371
|
-
class Table
|
372
|
-
|
373
|
-
#Method to parse the passed arguments and create the ColumnDefinition object of the specified type
|
374
|
-
def ibm_parse_column_attributes_args(type, *args)
|
375
|
-
options = {}
|
376
|
-
if args.last.is_a?(Hash)
|
377
|
-
options = args.delete_at(args.length-1)
|
378
|
-
end
|
379
|
-
args.each do | name |
|
380
|
-
column name,type.to_sym,options
|
381
|
-
end # end args.each
|
382
|
-
end
|
383
|
-
private :ibm_parse_column_attributes_args
|
384
485
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
486
|
+
module ColumnMethods
|
487
|
+
|
488
|
+
def primary_key(name, type = :primary_key, **options)
|
489
|
+
column(name, type, options.merge(primary_key: true))
|
490
|
+
end
|
491
|
+
|
492
|
+
##class Table
|
493
|
+
class Table < ActiveRecord::ConnectionAdapters::Table
|
494
|
+
include ColumnMethods
|
495
|
+
|
496
|
+
#Method to parse the passed arguments and create the ColumnDefinition object of the specified type
|
497
|
+
def ibm_parse_column_attributes_args(type, *args)
|
498
|
+
options = {}
|
499
|
+
if args.last.is_a?(Hash)
|
500
|
+
options = args.delete_at(args.length-1)
|
501
|
+
end
|
502
|
+
args.each do | name |
|
503
|
+
column name,type.to_sym,options
|
504
|
+
end # end args.each
|
505
|
+
end
|
506
|
+
private :ibm_parse_column_attributes_args
|
507
|
+
|
508
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type xml
|
509
|
+
#This method is different as compared to def char (sql is being issued explicitly
|
510
|
+
#as compared to def char where method column(which will generate the sql is being called)
|
511
|
+
#in order to handle the DEFAULT and NULL option for the native XML datatype
|
512
|
+
def xml(*args )
|
513
|
+
options = {}
|
514
|
+
if args.last.is_a?(Hash)
|
515
|
+
options = args.delete_at(args.length-1)
|
516
|
+
end
|
517
|
+
sql_segment = "ALTER TABLE #{@base.quote_table_name(@table_name)} ADD COLUMN "
|
518
|
+
args.each do | name |
|
519
|
+
sql = sql_segment + " #{@base.quote_column_name(name)} xml"
|
520
|
+
@base.execute(sql,"add_xml_column")
|
521
|
+
end
|
522
|
+
return self
|
523
|
+
end
|
401
524
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
525
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type double
|
526
|
+
def double(*args)
|
527
|
+
ibm_parse_column_attributes_args('double',*args)
|
528
|
+
return self
|
529
|
+
end
|
407
530
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
531
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type decfloat
|
532
|
+
def decfloat(*args)
|
533
|
+
ibm_parse_column_attributes_args('decfloat',*args)
|
534
|
+
return self
|
535
|
+
end
|
413
536
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
537
|
+
def graphic(*args)
|
538
|
+
ibm_parse_column_attributes_args('graphic',*args)
|
539
|
+
return self
|
540
|
+
end
|
418
541
|
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
542
|
+
def vargraphic(*args)
|
543
|
+
ibm_parse_column_attributes_args('vargraphic',*args)
|
544
|
+
return self
|
545
|
+
end
|
423
546
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
547
|
+
def bigint(*args)
|
548
|
+
ibm_parse_column_attributes_args('bigint',*args)
|
549
|
+
return self
|
550
|
+
end
|
428
551
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
552
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type char [character]
|
553
|
+
def char(*args)
|
554
|
+
ibm_parse_column_attributes_args('char',*args)
|
555
|
+
return self
|
556
|
+
end
|
557
|
+
alias_method :character, :char
|
558
|
+
end
|
436
559
|
|
437
|
-
|
560
|
+
#class TableDefinition
|
561
|
+
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
|
562
|
+
include ColumnMethods
|
438
563
|
|
439
|
-
|
440
|
-
|
441
|
-
@ar3 = false
|
442
|
-
else
|
443
|
-
@ar3 = true
|
444
|
-
end
|
445
|
-
@columns = []
|
446
|
-
@columns_hash = {}
|
447
|
-
@indexes = {}
|
448
|
-
@base = base
|
449
|
-
@temporary = temporary
|
450
|
-
@options = options
|
451
|
-
@name = name
|
452
|
-
@foreign_keys = {}
|
453
|
-
end
|
564
|
+
=begin
|
565
|
+
def initialize(base, name=nil, temporary=nil, options=nil)
|
454
566
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
def ibm_parse_column_attributes_args(type, *args)
|
461
|
-
options = {}
|
462
|
-
if args.last.is_a?(Hash)
|
463
|
-
options = args.delete_at(args.length-1)
|
464
|
-
end
|
465
|
-
args.each do | name |
|
466
|
-
column(name,type,options)
|
467
|
-
end
|
468
|
-
end
|
469
|
-
private :ibm_parse_column_attributes_args
|
567
|
+
if(self.respond_to?(:indexes))
|
568
|
+
@ar3 = false
|
569
|
+
else
|
570
|
+
@ar3 = true
|
571
|
+
end
|
470
572
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
573
|
+
@columns = []
|
574
|
+
@columns_hash = {}
|
575
|
+
@indexes = {}
|
576
|
+
@base = base
|
577
|
+
@temporary = temporary
|
578
|
+
@options = options
|
579
|
+
@name = name
|
580
|
+
@foreign_keys = {}
|
581
|
+
end
|
582
|
+
=end
|
583
|
+
|
584
|
+
def initialize(conn, name, temporary = false, options = nil, as = nil, comment: nil)
|
585
|
+
@connection = conn
|
586
|
+
@columns_hash = {}
|
587
|
+
@indexes = []
|
588
|
+
@foreign_keys = []
|
589
|
+
@primary_keys = nil
|
590
|
+
@temporary = temporary
|
591
|
+
@options = options
|
592
|
+
@as = as
|
593
|
+
@name = name
|
594
|
+
@comment = comment
|
595
|
+
##
|
596
|
+
#@base = base
|
597
|
+
end
|
598
|
+
|
599
|
+
def primary_keys(name = nil) # :nodoc:
|
600
|
+
@primary_keys = PrimaryKeyDefinition.new(name) if name
|
601
|
+
@primary_keys
|
602
|
+
end
|
476
603
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
604
|
+
def native
|
605
|
+
@base.native_database_types
|
606
|
+
end
|
607
|
+
|
608
|
+
#Method to parse the passed arguments and create the ColumnDefinition object of the specified type
|
609
|
+
def ibm_parse_column_attributes_args(type, *args)
|
610
|
+
options = {}
|
611
|
+
if args.last.is_a?(Hash)
|
612
|
+
options = args.delete_at(args.length-1)
|
613
|
+
end
|
614
|
+
args.each do | name |
|
615
|
+
column(name,type,options)
|
616
|
+
end
|
617
|
+
end
|
618
|
+
private :ibm_parse_column_attributes_args
|
482
619
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
620
|
+
#Method to support the new syntax of rails 2.0 migrations for columns of type xml
|
621
|
+
def xml(*args )
|
622
|
+
ibm_parse_column_attributes_args('xml', *args)
|
623
|
+
return self
|
624
|
+
end
|
488
625
|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
626
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type double
|
627
|
+
def double(*args)
|
628
|
+
ibm_parse_column_attributes_args('double',*args)
|
629
|
+
return self
|
630
|
+
end
|
493
631
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
632
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type decfloat
|
633
|
+
def decfloat(*args)
|
634
|
+
ibm_parse_column_attributes_args('decfloat',*args)
|
635
|
+
return self
|
636
|
+
end
|
498
637
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
638
|
+
def graphic(*args)
|
639
|
+
ibm_parse_column_attributes_args('graphic',*args)
|
640
|
+
return self
|
641
|
+
end
|
503
642
|
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
end
|
509
|
-
alias_method :character, :char
|
643
|
+
def vargraphic(*args)
|
644
|
+
ibm_parse_column_attributes_args('vargraphic',*args)
|
645
|
+
return self
|
646
|
+
end
|
510
647
|
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
if(@ar3)
|
516
|
-
column = ColumnDefinition.new(@base, name, type)
|
517
|
-
else
|
518
|
-
column = ColumnDefinition.new(name, type)
|
519
|
-
end
|
520
|
-
# DB2 does not accept DEFAULT NULL option for XML
|
521
|
-
# for table create, but does accept nullable option
|
522
|
-
unless type.to_s == 'xml'
|
523
|
-
column.null = options[:null]
|
524
|
-
column.default = options[:default]
|
525
|
-
else
|
526
|
-
column.null = options[:null]
|
527
|
-
# Override column object's (instance of ColumnDefinition structure)
|
528
|
-
# to_s which is expected to return the create_table SQL fragment
|
529
|
-
# and bypass DEFAULT NULL option while still appending NOT NULL
|
530
|
-
def column.to_s
|
531
|
-
sql = "#{base.quote_column_name(name)} #{type}"
|
532
|
-
unless self.null == nil
|
533
|
-
sql << " NOT NULL" if (self.null == false)
|
534
|
-
end
|
535
|
-
return sql
|
536
|
-
end
|
537
|
-
end
|
648
|
+
def bigint(*args)
|
649
|
+
ibm_parse_column_attributes_args('bigint',*args)
|
650
|
+
return self
|
651
|
+
end
|
538
652
|
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
653
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type char [character]
|
654
|
+
def char(*args)
|
655
|
+
ibm_parse_column_attributes_args('char',*args)
|
656
|
+
return self
|
657
|
+
end
|
658
|
+
alias_method :character, :char
|
659
|
+
|
660
|
+
# Overrides the abstract adapter in order to handle
|
661
|
+
# the DEFAULT option for the native XML datatype
|
662
|
+
def column(name, type, options ={})
|
663
|
+
# construct a column definition where @base is adaptor instance
|
664
|
+
column = ColumnDefinition.new(name, type)
|
665
|
+
|
666
|
+
# DB2 does not accept DEFAULT NULL option for XML
|
667
|
+
# for table create, but does accept nullable option
|
668
|
+
unless type.to_s == 'xml'
|
669
|
+
column.null = options[:null]
|
670
|
+
column.default = options[:default]
|
671
|
+
else
|
672
|
+
column.null = options[:null]
|
673
|
+
# Override column object's (instance of ColumnDefinition structure)
|
674
|
+
# to_s which is expected to return the create_table SQL fragment
|
675
|
+
# and bypass DEFAULT NULL option while still appending NOT NULL
|
676
|
+
def column.to_s
|
677
|
+
sql = "#{base.quote_column_name(name)} #{type}"
|
678
|
+
unless self.null == nil
|
679
|
+
sql << " NOT NULL" if (self.null == false)
|
680
|
+
end
|
681
|
+
return sql
|
682
|
+
end
|
683
|
+
end
|
547
684
|
|
548
|
-
|
549
|
-
|
550
|
-
|
685
|
+
column.scale = options[:scale] if options[:scale]
|
686
|
+
column.precision = options[:precision] if options[:precision]
|
687
|
+
# append column's limit option and yield native limits
|
688
|
+
if options[:limit]
|
689
|
+
column.limit = options[:limit]
|
690
|
+
elsif @base.native_database_types[type.to_sym]
|
691
|
+
column.limit = @base.native_database_types[type.to_sym][:limit] if @base.native_database_types[type.to_sym].has_key? :limit
|
692
|
+
end
|
551
693
|
|
552
|
-
|
694
|
+
unless @columns.nil? or @columns.include? column
|
695
|
+
@columns << column
|
696
|
+
end
|
553
697
|
|
554
|
-
|
555
|
-
|
556
|
-
|
698
|
+
@columns_hash[name] = column
|
699
|
+
|
700
|
+
return self
|
701
|
+
end
|
702
|
+
end
|
703
|
+
end
|
557
704
|
|
558
705
|
# The IBM_DB Adapter requires the native Ruby driver (ibm_db)
|
559
706
|
# for IBM data servers (ibm_db.so).
|
@@ -597,11 +744,12 @@ module ActiveRecord
|
|
597
744
|
end
|
598
745
|
|
599
746
|
class BindSubstitution < Arel::Visitors::IBM_DB # :nodoc:
|
600
|
-
include Arel::Visitors
|
747
|
+
include Arel::Visitors
|
601
748
|
end
|
602
749
|
|
603
750
|
def initialize(connection, ar3, logger, config, conn_options)
|
604
|
-
# Caching database connection configuration (+connect+ or +reconnect+ support)
|
751
|
+
# Caching database connection configuration (+connect+ or +reconnect+ support)\
|
752
|
+
@config = config
|
605
753
|
@connection = connection
|
606
754
|
@isAr3 = ar3
|
607
755
|
@conn_options = conn_options
|
@@ -631,7 +779,7 @@ module ActiveRecord
|
|
631
779
|
|
632
780
|
# Calls the parent class +ConnectionAdapters+' initializer
|
633
781
|
# which sets @connection, @logger, @runtime and @last_verification
|
634
|
-
super(@connection, logger)
|
782
|
+
super(@connection, logger, @config)
|
635
783
|
|
636
784
|
if @connection
|
637
785
|
server_info = IBM_DB.server_info( @connection )
|
@@ -763,7 +911,7 @@ module ActiveRecord
|
|
763
911
|
rescue
|
764
912
|
@arelVersion = 0
|
765
913
|
end
|
766
|
-
|
914
|
+
if(@arelVersion < 6 )
|
767
915
|
def to_sql(arel, binds = [])
|
768
916
|
if arel.respond_to?(:ast)
|
769
917
|
visitor.accept(arel.ast) do
|
@@ -785,8 +933,11 @@ module ActiveRecord
|
|
785
933
|
|
786
934
|
def supports_foreign_keys?
|
787
935
|
true
|
936
|
+
end
|
937
|
+
|
938
|
+
def supports_datetime_with_precision?
|
939
|
+
true
|
788
940
|
end
|
789
|
-
|
790
941
|
|
791
942
|
# This Adapter supports DDL transactions.
|
792
943
|
# This means CREATE TABLE and other DDL statements can be carried out as a transaction.
|
@@ -871,21 +1022,20 @@ module ActiveRecord
|
|
871
1022
|
|
872
1023
|
def create_table(name, options = {})
|
873
1024
|
@servertype.setup_for_lob_table
|
874
|
-
super
|
875
|
-
|
876
1025
|
#Table definition is complete only when a unique index is created on the primarykey column for DB2 V8 on zOS
|
877
1026
|
|
878
1027
|
#create index on id column if options[:id] is nil or id ==true
|
879
1028
|
#else check if options[:primary_key]is not nil then create an unique index on that column
|
880
1029
|
if !options[:id].nil? || !options[:primary_key].nil?
|
881
1030
|
if (!options[:id].nil? && options[:id] == true)
|
882
|
-
|
1031
|
+
@servertype.create_index_after_table(name,"id")
|
883
1032
|
elsif !options[:primary_key].nil?
|
884
|
-
|
1033
|
+
@servertype.create_index_after_table(name,options[:primary_key].to_s)
|
885
1034
|
end
|
886
1035
|
else
|
887
|
-
|
888
|
-
end
|
1036
|
+
@servertype.create_index_after_table(name,"id")
|
1037
|
+
end
|
1038
|
+
super(name, options)
|
889
1039
|
end
|
890
1040
|
|
891
1041
|
# Returns an array of hashes with the column names as keys and
|
@@ -976,8 +1126,8 @@ module ActiveRecord
|
|
976
1126
|
end
|
977
1127
|
|
978
1128
|
def select(sql, name = nil, binds = [])
|
979
|
-
# Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"
|
980
|
-
sql.gsub
|
1129
|
+
# Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"
|
1130
|
+
sql.gsub( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
|
981
1131
|
|
982
1132
|
results = []
|
983
1133
|
|
@@ -1005,7 +1155,7 @@ module ActiveRecord
|
|
1005
1155
|
#+sql+ is the select query and +name+ is an optional description for logging
|
1006
1156
|
def select_rows(sql, name = nil,binds = [])
|
1007
1157
|
# Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
|
1008
|
-
sql.gsub
|
1158
|
+
sql.gsub( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
|
1009
1159
|
|
1010
1160
|
results = []
|
1011
1161
|
# Invokes the method +execute+ in order to log and execute the SQL
|
@@ -1072,10 +1222,10 @@ module ActiveRecord
|
|
1072
1222
|
break
|
1073
1223
|
end
|
1074
1224
|
end
|
1225
|
+
|
1075
1226
|
if item.at(1).nil? ||
|
1076
1227
|
item.at(1) == {} ||
|
1077
1228
|
(item.at(1) == '' && !(col.sql_type.to_s =~ /text|clob/i))
|
1078
|
-
|
1079
1229
|
params << 'NULL'
|
1080
1230
|
|
1081
1231
|
elsif (!col.nil? && (col.sql_type.to_s =~ /blob|binary|clob|text|xml/i) )
|
@@ -1137,12 +1287,12 @@ module ActiveRecord
|
|
1137
1287
|
end
|
1138
1288
|
end
|
1139
1289
|
|
1140
|
-
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds
|
1141
|
-
if(@arelVersion < 6
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1290
|
+
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds=[])
|
1291
|
+
if(@arelVersion < 6)
|
1292
|
+
sql, binds = [to_sql(arel), binds]
|
1293
|
+
else
|
1294
|
+
sql, binds = [to_sql(arel),binds] #sql_for_insert(to_sql(arel, binds), binds) #[to_sql(arel),binds]
|
1295
|
+
end
|
1146
1296
|
|
1147
1297
|
#unless IBM_DBAdapter.respond_to?(:exec_insert)
|
1148
1298
|
if binds.nil? || binds.empty?
|
@@ -1150,7 +1300,8 @@ module ActiveRecord
|
|
1150
1300
|
end
|
1151
1301
|
|
1152
1302
|
clear_query_cache if defined? clear_query_cache
|
1153
|
-
|
1303
|
+
|
1304
|
+
if stmt = exec_insert(sql, name, binds)
|
1154
1305
|
begin
|
1155
1306
|
@sql << sql
|
1156
1307
|
return id_value || @servertype.last_generated_id(stmt)
|
@@ -1244,14 +1395,18 @@ module ActiveRecord
|
|
1244
1395
|
|
1245
1396
|
# Executes and logs +sql+ commands and
|
1246
1397
|
# returns a +IBM_DB.Statement+ object.
|
1247
|
-
def execute(sql, name
|
1398
|
+
def execute(sql, name=nil)
|
1248
1399
|
# Logs and execute the sql instructions.
|
1249
1400
|
# The +log+ method is defined in the parent class +AbstractAdapter+
|
1250
|
-
|
1401
|
+
#sql='INSERT INTO ar_internal_metadata (key, value, created_at, updated_at) VALUES ('10', '10', '10', '10')
|
1402
|
+
log(sql , name) do
|
1251
1403
|
@servertype.execute(sql, name)
|
1252
1404
|
end
|
1253
1405
|
end
|
1254
1406
|
|
1407
|
+
def exec_insert(sql,name,binds,pk,sequence_name)
|
1408
|
+
end
|
1409
|
+
|
1255
1410
|
# Executes an "UPDATE" SQL statement
|
1256
1411
|
def update_direct(sql, name = nil)
|
1257
1412
|
if @handle_lobs_triggered #Ensure the array of sql is cleared if they have been handled in the callback
|
@@ -1303,10 +1458,10 @@ module ActiveRecord
|
|
1303
1458
|
|
1304
1459
|
def update(arel, name = nil, binds = [])
|
1305
1460
|
if(@arelVersion < 6 )
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1461
|
+
sql = to_sql(arel)
|
1462
|
+
else
|
1463
|
+
sql = to_sql(arel,binds)
|
1464
|
+
end
|
1310
1465
|
|
1311
1466
|
# Make sure the WHERE clause handles NULL's correctly
|
1312
1467
|
sqlarray = sql.split(/\s*WHERE\s*/)
|
@@ -1364,6 +1519,7 @@ module ActiveRecord
|
|
1364
1519
|
end
|
1365
1520
|
|
1366
1521
|
def get_limit_offset_clauses(limit,offset)
|
1522
|
+
|
1367
1523
|
if limit && limit == 0
|
1368
1524
|
clauses = @servertype.get_limit_offset_clauses(limit,0)
|
1369
1525
|
else
|
@@ -1424,6 +1580,7 @@ module ActiveRecord
|
|
1424
1580
|
|
1425
1581
|
# Quote date/time values for use in SQL input.
|
1426
1582
|
# Includes microseconds, if the value is a Time responding to usec.
|
1583
|
+
=begin
|
1427
1584
|
def quoted_date(value) #:nodoc:
|
1428
1585
|
if value.respond_to?(:usec)
|
1429
1586
|
"#{super}.#{sprintf("%06d", value.usec)}"
|
@@ -1431,7 +1588,7 @@ module ActiveRecord
|
|
1431
1588
|
super
|
1432
1589
|
end
|
1433
1590
|
end
|
1434
|
-
|
1591
|
+
=end
|
1435
1592
|
def quote_value_for_pstmt(value, column=nil)
|
1436
1593
|
|
1437
1594
|
return value.quoted_id if value.respond_to?(:quoted_id)
|
@@ -1460,75 +1617,82 @@ module ActiveRecord
|
|
1460
1617
|
end
|
1461
1618
|
end
|
1462
1619
|
end
|
1463
|
-
|
1464
1620
|
# Properly quotes the various data types.
|
1465
1621
|
# +value+ contains the data, +column+ is optional and contains info on the field
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1622
|
+
# def quote(value, column=nil)
|
1623
|
+
# return value.quoted_id if value.respond_to?(:quoted_id)
|
1624
|
+
# case value
|
1625
|
+
# # If it's a numeric value and the column sql_type is not a string, it shouldn't be quoted
|
1626
|
+
# # (IBM_DB doesn't accept quotes on numeric types)
|
1627
|
+
# when Numeric
|
1628
|
+
# # If the column sql_type is text or string, return the quote value
|
1629
|
+
# if (column && ( column.sql_type.to_s =~ /text|char/i ))
|
1630
|
+
# unless caller[0] =~ /insert_fixture/i
|
1631
|
+
# "'#{value}'"
|
1632
|
+
# else
|
1633
|
+
# "#{value}"
|
1634
|
+
# end
|
1635
|
+
# else
|
1636
|
+
# # value is Numeric, column.sql_type is not a string,
|
1637
|
+
# # therefore it converts the number to string without quoting it
|
1638
|
+
# value.to_s
|
1639
|
+
# end
|
1640
|
+
# when String, ActiveSupport::Multibyte::Chars
|
1641
|
+
# if column && column.sql_type.to_s =~ /binary|blob/i && !(column.sql_type.to_s =~ /for bit data/i)
|
1642
|
+
# # If quoting is required for the insert/update of a BLOB
|
1643
|
+
# unless caller[0] =~ /add_column_options/i
|
1644
|
+
# # Invokes a convertion from string to binary
|
1645
|
+
# @servertype.set_binary_value
|
1646
|
+
# else
|
1647
|
+
# # Quoting required for the default value of a column
|
1648
|
+
# @servertype.set_binary_default(value)
|
1649
|
+
# end
|
1650
|
+
# elsif column && column.sql_type.to_s =~ /text|clob/i
|
1651
|
+
# unless caller[0] =~ /add_column_options/i
|
1652
|
+
# @servertype.set_text_default(quote_string(value))
|
1653
|
+
# else
|
1654
|
+
# @servertype.set_text_default(quote_string(value))
|
1655
|
+
# end
|
1656
|
+
# elsif column && column.sql_type.to_s =~ /xml/i
|
1657
|
+
# unless caller[0] =~ /add_column_options/i
|
1658
|
+
# "#{value}"
|
1659
|
+
# else
|
1660
|
+
# "#{value}"
|
1661
|
+
# end
|
1662
|
+
# else
|
1663
|
+
# unless caller[0] =~ /insert_fixture/i
|
1664
|
+
# super(value)
|
1665
|
+
# else
|
1666
|
+
# "#{value}"
|
1667
|
+
# end
|
1668
|
+
# end
|
1669
|
+
# #when TrueClass then quoted_true # return '1' for true
|
1670
|
+
# when TrueClass
|
1671
|
+
# quoted_true
|
1672
|
+
# #when FalseClass then quoted_false # return '0' for false
|
1673
|
+
# when FalseClass
|
1674
|
+
# quoted_false
|
1675
|
+
# when nil
|
1676
|
+
# "NULL"
|
1677
|
+
# when Date
|
1678
|
+
# "'#{quoted_date(value)}'"
|
1679
|
+
# when Time
|
1680
|
+
# "'#{quoted_date(value)}'"
|
1681
|
+
# when Symbol
|
1682
|
+
# "'#{quote_string(value)}'"
|
1683
|
+
# else
|
1684
|
+
# unless caller[0] =~ /insert_fixture/i
|
1685
|
+
# "'#{quote_string(YAML.dump(value))}'"
|
1686
|
+
# else
|
1687
|
+
# "#{quote_string(YAML.dump(value))}"
|
1688
|
+
# end
|
1689
|
+
# end
|
1690
|
+
# end
|
1691
|
+
# # Quotes a given string, escaping single quote (') characters.
|
1692
|
+
# def quote_string(string)
|
1693
|
+
# #string.gsub(/'/, "''")
|
1694
|
+
# string.gsub('\\', '\&\&').gsub("'", "''")
|
1695
|
+
# end
|
1532
1696
|
|
1533
1697
|
# *true* is represented by a smallint 1, *false*
|
1534
1698
|
# by 0, as no native boolean type exists in DB2.
|
@@ -1548,7 +1712,7 @@ module ActiveRecord
|
|
1548
1712
|
#==============================================
|
1549
1713
|
# SCHEMA STATEMENTS
|
1550
1714
|
#==============================================
|
1551
|
-
|
1715
|
+
|
1552
1716
|
# Returns a Hash of mappings from the abstract data types to the native
|
1553
1717
|
# database types
|
1554
1718
|
def native_database_types
|
@@ -1558,9 +1722,9 @@ module ActiveRecord
|
|
1558
1722
|
:text => { :name => "clob" },
|
1559
1723
|
:integer => { :name => "integer" },
|
1560
1724
|
:float => { :name => "float" },
|
1561
|
-
:datetime => { :name =>
|
1562
|
-
:timestamp => { :name =>
|
1563
|
-
:time => { :name =>
|
1725
|
+
:datetime => { :name => "timestamp" },
|
1726
|
+
:timestamp => { :name => "timestamp" },
|
1727
|
+
:time => { :name => "time" },
|
1564
1728
|
:date => { :name => "date" },
|
1565
1729
|
:binary => { :name => "blob" },
|
1566
1730
|
|
@@ -1575,8 +1739,8 @@ module ActiveRecord
|
|
1575
1739
|
:char => { :name => "char" },
|
1576
1740
|
:double => { :name => @servertype.get_double_mapping },
|
1577
1741
|
:decfloat => { :name => "decfloat"},
|
1578
|
-
:graphic => { :name => "graphic"
|
1579
|
-
:vargraphic => { :name => "vargraphic"
|
1742
|
+
:graphic => { :name => "graphic"},
|
1743
|
+
:vargraphic => { :name => "vargraphic"},
|
1580
1744
|
:bigint => { :name => "bigint"}
|
1581
1745
|
}
|
1582
1746
|
end
|
@@ -1638,16 +1802,90 @@ module ActiveRecord
|
|
1638
1802
|
end
|
1639
1803
|
end
|
1640
1804
|
|
1805
|
+
|
1806
|
+
|
1807
|
+
|
1808
|
+
def valid_type?(type)
|
1809
|
+
#!native_database_types[type].nil?
|
1810
|
+
native_database_types[type].nil?
|
1811
|
+
end
|
1812
|
+
|
1641
1813
|
# IBM data servers do not support limits on certain data types (unlike MySQL)
|
1642
1814
|
# Limit is supported for the {float, decimal, numeric, varchar, clob, blob, graphic, vargraphic} data types.
|
1643
|
-
def type_to_sql(type, limit
|
1815
|
+
def type_to_sql(type, limit=nil, precision=nil, scale=nil )
|
1816
|
+
if type.to_sym == :decimal
|
1817
|
+
if limit.class == Hash
|
1818
|
+
if limit.has_key?("precision".to_sym)
|
1819
|
+
precision = limit[:precision]
|
1820
|
+
end
|
1821
|
+
end
|
1822
|
+
if limit.class == Hash
|
1823
|
+
if limit.has_key?("scale".to_sym)
|
1824
|
+
scale = limit[:scale]
|
1825
|
+
end
|
1826
|
+
end
|
1827
|
+
sql_segment = native_database_types[type.to_sym][:name].to_s
|
1828
|
+
if !precision.nil? && !scale.nil?
|
1829
|
+
sql_segment << "(#{precision},#{scale})"
|
1830
|
+
return sql_segment
|
1831
|
+
elsif scale.nil? && !precision.nil?
|
1832
|
+
sql_segment << "(#{precision})"
|
1833
|
+
else
|
1834
|
+
return sql_segment
|
1835
|
+
end
|
1836
|
+
end
|
1837
|
+
|
1644
1838
|
if type.to_sym == :decfloat
|
1645
1839
|
sql_segment = native_database_types[type.to_sym][:name].to_s
|
1646
1840
|
sql_segment << "(#{precision})" if !precision.nil?
|
1647
1841
|
return sql_segment
|
1648
1842
|
end
|
1649
|
-
|
1650
|
-
|
1843
|
+
|
1844
|
+
if type.to_sym == :vargraphic
|
1845
|
+
sql_segment = native_database_types[type.to_sym][:name].to_s
|
1846
|
+
if limit.class == Hash
|
1847
|
+
if limit.has_key?("limit".to_sym)
|
1848
|
+
limit1 = limit[:limit]
|
1849
|
+
sql_segment << "(#{limit1})"
|
1850
|
+
else
|
1851
|
+
return "vargraphic(1)"
|
1852
|
+
end
|
1853
|
+
else
|
1854
|
+
if limit != nil
|
1855
|
+
sql_segment << "(#{limit})"
|
1856
|
+
else
|
1857
|
+
return "vargraphic(1)"
|
1858
|
+
end
|
1859
|
+
end
|
1860
|
+
return sql_segment
|
1861
|
+
end
|
1862
|
+
|
1863
|
+
if type.to_sym == :graphic
|
1864
|
+
sql_segment = native_database_types[type.to_sym][:name].to_s
|
1865
|
+
if limit.class == Hash
|
1866
|
+
if limit.has_key?("limit".to_sym)
|
1867
|
+
limit1 = limit[:limit]
|
1868
|
+
sql_segment << "(#{limit1})"
|
1869
|
+
else
|
1870
|
+
return "graphic(1)"
|
1871
|
+
end
|
1872
|
+
else
|
1873
|
+
if limit != nil
|
1874
|
+
sql_segment << "(#{limit})"
|
1875
|
+
else
|
1876
|
+
return "graphic(1)"
|
1877
|
+
end
|
1878
|
+
end
|
1879
|
+
return sql_segment
|
1880
|
+
end
|
1881
|
+
|
1882
|
+
|
1883
|
+
|
1884
|
+
if limit.class == Hash
|
1885
|
+
return super if limit.has_key?("limit".to_sym).nil?
|
1886
|
+
else
|
1887
|
+
return super if limit.nil?
|
1888
|
+
end
|
1651
1889
|
|
1652
1890
|
# strip off limits on data types not supporting them
|
1653
1891
|
if @servertype.limit_not_supported_types.include? type.to_sym
|
@@ -1655,16 +1893,23 @@ module ActiveRecord
|
|
1655
1893
|
elsif type.to_sym == :boolean
|
1656
1894
|
return "smallint"
|
1657
1895
|
else
|
1658
|
-
return super
|
1896
|
+
return super(type)
|
1659
1897
|
end
|
1660
|
-
end
|
1661
1898
|
|
1899
|
+
end
|
1900
|
+
|
1901
|
+
|
1902
|
+
|
1903
|
+
|
1904
|
+
|
1905
|
+
|
1662
1906
|
# Returns the maximum length a table alias identifier can be.
|
1663
1907
|
# IBM data servers (cross-platform) table limit is 128 characters
|
1664
1908
|
def table_alias_length
|
1665
1909
|
128
|
1666
1910
|
end
|
1667
|
-
|
1911
|
+
|
1912
|
+
|
1668
1913
|
# Retrieves table's metadata for a specified shema name
|
1669
1914
|
def tables(name = nil)
|
1670
1915
|
# Initializes the tables array
|
@@ -1705,6 +1950,50 @@ module ActiveRecord
|
|
1705
1950
|
return tables
|
1706
1951
|
end
|
1707
1952
|
|
1953
|
+
###################################
|
1954
|
+
|
1955
|
+
|
1956
|
+
# Retrieves views's metadata for a specified shema name
|
1957
|
+
def views
|
1958
|
+
# Initializes the tables array
|
1959
|
+
tables = []
|
1960
|
+
# Retrieve view's metadata through IBM_DB driver
|
1961
|
+
stmt = IBM_DB.tables(@connection, nil,
|
1962
|
+
@servertype.set_case(@schema))
|
1963
|
+
if(stmt)
|
1964
|
+
begin
|
1965
|
+
# Fetches all the records available
|
1966
|
+
while tab = IBM_DB.fetch_assoc(stmt)
|
1967
|
+
# Adds the lowercase view's name to the array
|
1968
|
+
if(tab["table_type"]== 'V') #check, so that only views are dumped,IBM_DB.tables also returns tables,alias etc in the schema
|
1969
|
+
tables << tab["table_name"].downcase
|
1970
|
+
end
|
1971
|
+
end
|
1972
|
+
rescue StandardError => fetch_error # Handle driver fetch errors
|
1973
|
+
error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT )
|
1974
|
+
if error_msg && !error_msg.empty?
|
1975
|
+
raise "Failed to retrieve views metadata during fetch: #{error_msg}"
|
1976
|
+
else
|
1977
|
+
error_msg = "An unexpected error occurred during retrieval of views metadata"
|
1978
|
+
error_msg = error_msg + ": #{fetch_error.message}" if !fetch_error.message.empty?
|
1979
|
+
raise error_msg
|
1980
|
+
end
|
1981
|
+
ensure
|
1982
|
+
IBM_DB.free_stmt(stmt) if stmt # Free resources associated with the statement
|
1983
|
+
end
|
1984
|
+
else # Handle driver execution errors
|
1985
|
+
error_msg = IBM_DB.getErrormsg(@connection, IBM_DB::DB_CONN )
|
1986
|
+
if error_msg && !error_msg.empty?
|
1987
|
+
raise "Failed to retrieve tables metadata due to error: #{error_msg}"
|
1988
|
+
else
|
1989
|
+
raise StandardError.new('An unexpected error occurred during retrieval of views metadata')
|
1990
|
+
end
|
1991
|
+
end
|
1992
|
+
# Returns the tables array
|
1993
|
+
return tables
|
1994
|
+
end
|
1995
|
+
|
1996
|
+
|
1708
1997
|
# Returns the primary key of the mentioned table
|
1709
1998
|
def primary_key(table_name)
|
1710
1999
|
pk_name = nil
|
@@ -1741,7 +2030,7 @@ module ActiveRecord
|
|
1741
2030
|
|
1742
2031
|
# Returns an array of non-primary key indexes for a specified table name
|
1743
2032
|
def indexes(table_name, name = nil)
|
1744
|
-
|
2033
|
+
# to_s required because +table_name+ may be a symbol.
|
1745
2034
|
table_name = table_name.to_s
|
1746
2035
|
# Checks if a blank table name has been given.
|
1747
2036
|
# If so it returns an empty array of columns.
|
@@ -1804,7 +2093,7 @@ module ActiveRecord
|
|
1804
2093
|
if(stmt)
|
1805
2094
|
begin
|
1806
2095
|
while ( index_stats = IBM_DB.fetch_array(stmt) )
|
1807
|
-
|
2096
|
+
is_composite = false
|
1808
2097
|
if index_stats[5] # INDEX_NAME
|
1809
2098
|
index_name = index_stats[5].downcase
|
1810
2099
|
index_unique = (index_stats[3] == 0)
|
@@ -1814,7 +2103,8 @@ module ActiveRecord
|
|
1814
2103
|
i = 0;
|
1815
2104
|
indexes.each do |index|
|
1816
2105
|
if index.name == index_name && index_schema[i] == index_qualifier
|
1817
|
-
index.columns = index.columns + index_columns
|
2106
|
+
#index.columns = index.columns + index_columns
|
2107
|
+
index.columns.concat index_columns
|
1818
2108
|
is_composite = true
|
1819
2109
|
end
|
1820
2110
|
i = i+1
|
@@ -1860,10 +2150,92 @@ module ActiveRecord
|
|
1860
2150
|
return indexes
|
1861
2151
|
end
|
1862
2152
|
|
2153
|
+
|
2154
|
+
# Mapping IBM data servers SQL datatypes to Ruby data types
|
2155
|
+
def simplified_type2(field_type)
|
2156
|
+
case field_type
|
2157
|
+
# if +field_type+ contains 'for bit data' handle it as a binary
|
2158
|
+
when /for bit data/i
|
2159
|
+
"binary"
|
2160
|
+
when /smallint/i
|
2161
|
+
"boolean"
|
2162
|
+
when /int|serial/i
|
2163
|
+
"integer"
|
2164
|
+
when /decimal|numeric|decfloat/i
|
2165
|
+
"decimal"
|
2166
|
+
when /float|double|real/i
|
2167
|
+
"float"
|
2168
|
+
when /timestamp|datetime/i
|
2169
|
+
"timestamp"
|
2170
|
+
when /time/i
|
2171
|
+
"time"
|
2172
|
+
when /date/i
|
2173
|
+
"date"
|
2174
|
+
when /vargraphic/i
|
2175
|
+
"vargraphic"
|
2176
|
+
when /graphic/i
|
2177
|
+
"graphic"
|
2178
|
+
when /clob|text/i
|
2179
|
+
"text"
|
2180
|
+
when /xml/i
|
2181
|
+
"xml"
|
2182
|
+
when /blob|binary/i
|
2183
|
+
"binary"
|
2184
|
+
when /char/i
|
2185
|
+
"string"
|
2186
|
+
when /boolean/i
|
2187
|
+
"boolean"
|
2188
|
+
when /rowid/i # rowid is a supported datatype on z/OS and i/5
|
2189
|
+
"rowid"
|
2190
|
+
end
|
2191
|
+
end # method simplified_type
|
2192
|
+
|
2193
|
+
|
2194
|
+
# Mapping IBM data servers SQL datatypes to Ruby data types
|
2195
|
+
def simplified_type(field_type)
|
2196
|
+
case field_type
|
2197
|
+
# if +field_type+ contains 'for bit data' handle it as a binary
|
2198
|
+
when /for bit data/i
|
2199
|
+
:binary
|
2200
|
+
when /smallint/i
|
2201
|
+
:boolean
|
2202
|
+
when /int|serial/i
|
2203
|
+
:integer
|
2204
|
+
when /decimal|numeric|decfloat/i
|
2205
|
+
:decimal
|
2206
|
+
when /float|double|real/i
|
2207
|
+
:float
|
2208
|
+
when /timestamp|datetime/i
|
2209
|
+
:timestamp
|
2210
|
+
when /time/i
|
2211
|
+
:time
|
2212
|
+
when /date/i
|
2213
|
+
:date
|
2214
|
+
when /vargraphic/i
|
2215
|
+
:vargraphic
|
2216
|
+
when /graphic/i
|
2217
|
+
:graphic
|
2218
|
+
when /clob|text/i
|
2219
|
+
:text
|
2220
|
+
when /xml/i
|
2221
|
+
:xml
|
2222
|
+
when /blob|binary/i
|
2223
|
+
:binary
|
2224
|
+
when /char/i
|
2225
|
+
:string
|
2226
|
+
when /boolean/i
|
2227
|
+
:boolean
|
2228
|
+
when /rowid/i # rowid is a supported datatype on z/OS and i/5
|
2229
|
+
:rowid
|
2230
|
+
end
|
2231
|
+
end # method simplified_type
|
2232
|
+
|
2233
|
+
|
1863
2234
|
# Returns an array of Column objects for the table specified by +table_name+
|
1864
|
-
def columns(table_name
|
1865
|
-
|
2235
|
+
def columns(table_name)
|
2236
|
+
# to_s required because it may be a symbol.
|
1866
2237
|
table_name = @servertype.set_case(table_name.to_s)
|
2238
|
+
|
1867
2239
|
# Checks if a blank table name has been given.
|
1868
2240
|
# If so it returns an empty array
|
1869
2241
|
return [] if table_name.strip.empty?
|
@@ -1890,6 +2262,9 @@ module ActiveRecord
|
|
1890
2262
|
# Assigns the column type
|
1891
2263
|
column_type = col["type_name"].downcase
|
1892
2264
|
# Assigns the field length (size) for the column
|
2265
|
+
|
2266
|
+
original_column_type = "#{column_type}"
|
2267
|
+
|
1893
2268
|
column_length = col["column_size"]
|
1894
2269
|
column_scale = col["decimal_digits"]
|
1895
2270
|
# The initializer of the class Column, requires the +column_length+ to be declared
|
@@ -1914,12 +2289,30 @@ module ActiveRecord
|
|
1914
2289
|
if !(column_name =~ /db2_generated_rowid_for_lobs/i)
|
1915
2290
|
# Pushes into the array the *IBM_DBColumn* object, created by passing to the initializer
|
1916
2291
|
# +column_name+, +default_value+, +column_type+ and +column_nullable+.
|
1917
|
-
if(@arelVersion >= 6 )
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
2292
|
+
#if(@arelVersion >= 6 )
|
2293
|
+
|
2294
|
+
#cast_type = lookup_cast_type(column_type)
|
2295
|
+
|
2296
|
+
ruby_type = simplified_type2(column_type)
|
2297
|
+
precision = extract_precision(ruby_type)
|
2298
|
+
|
2299
|
+
#type = type_map.lookup(column_type)
|
2300
|
+
sql_type = type_to_sql(column_type, column_length, precision, column_scale)
|
2301
|
+
|
2302
|
+
sqltype_metadata = SqlTypeMetadata.new(
|
2303
|
+
#sql_type: sql_type,
|
2304
|
+
sql_type: original_column_type,
|
2305
|
+
type: ruby_type,
|
2306
|
+
limit: column_length,
|
2307
|
+
precision: precision,
|
2308
|
+
scale: column_scale,
|
2309
|
+
)
|
2310
|
+
|
2311
|
+
columns << Column.new(column_name, column_default_value, sqltype_metadata, column_nullable, table_name)
|
2312
|
+
|
2313
|
+
#else
|
2314
|
+
# columns << IBM_DBColumn.new(column_name, column_default_value, column_type, column_nullable)
|
2315
|
+
#end
|
1923
2316
|
end
|
1924
2317
|
end
|
1925
2318
|
rescue StandardError => fetch_error # Handle driver fetch errors
|
@@ -1946,7 +2339,7 @@ module ActiveRecord
|
|
1946
2339
|
return columns
|
1947
2340
|
end
|
1948
2341
|
|
1949
|
-
def foreign_keys(table_name)
|
2342
|
+
def foreign_keys(table_name)
|
1950
2343
|
#fetch the foreign keys of the table using function foreign_keys
|
1951
2344
|
#PKTABLE_NAME:: fk_row[2] Name of the table containing the primary key.
|
1952
2345
|
#PKCOLUMN_NAME:: fk_row[3] Name of the column containing the primary key.
|
@@ -1995,8 +2388,9 @@ module ActiveRecord
|
|
1995
2388
|
end
|
1996
2389
|
#Returns the foreignKeys array
|
1997
2390
|
return foreignKeys
|
1998
|
-
|
1999
|
-
|
2391
|
+
end
|
2392
|
+
|
2393
|
+
def extract_foreign_key_action(specifier) # :nodoc:
|
2000
2394
|
case specifier
|
2001
2395
|
when 0; :cascade
|
2002
2396
|
when 1; :restrict
|
@@ -2007,9 +2401,9 @@ module ActiveRecord
|
|
2007
2401
|
|
2008
2402
|
def supports_disable_referential_integrity? #:nodoc:
|
2009
2403
|
true
|
2010
|
-
|
2404
|
+
end
|
2011
2405
|
|
2012
|
-
|
2406
|
+
def disable_referential_integrity #:nodoc:
|
2013
2407
|
if supports_disable_referential_integrity?
|
2014
2408
|
alter_foreign_keys(tables, true)
|
2015
2409
|
end
|
@@ -2020,7 +2414,7 @@ module ActiveRecord
|
|
2020
2414
|
alter_foreign_keys(tables, false)
|
2021
2415
|
end
|
2022
2416
|
|
2023
|
-
|
2417
|
+
end
|
2024
2418
|
|
2025
2419
|
def alter_foreign_keys(tables, not_enforced)
|
2026
2420
|
enforced = not_enforced ? 'NOT ENFORCED' : 'ENFORCED'
|
@@ -2029,7 +2423,7 @@ module ActiveRecord
|
|
2029
2423
|
execute("ALTER TABLE #{@servertype.set_case(fk.from_table)} ALTER FOREIGN KEY #{@servertype.set_case(fk.name)} #{enforced}")
|
2030
2424
|
end
|
2031
2425
|
end
|
2032
|
-
|
2426
|
+
end
|
2033
2427
|
|
2034
2428
|
# Renames a table.
|
2035
2429
|
# ==== Example
|
@@ -2070,7 +2464,7 @@ module ActiveRecord
|
|
2070
2464
|
#Add distinct clause to the sql if there is no order by specified
|
2071
2465
|
def distinct(columns, order_by)
|
2072
2466
|
if order_by.nil?
|
2073
|
-
"DISTINCT #{columns}"
|
2467
|
+
"DISTINCT #{columns}"
|
2074
2468
|
else
|
2075
2469
|
"#{columns}"
|
2076
2470
|
end
|
@@ -2117,7 +2511,7 @@ module ActiveRecord
|
|
2117
2511
|
# remove_index :accounts, :username
|
2118
2512
|
# Overriden to use the IBM data servers SQL syntax.
|
2119
2513
|
def remove_index(table_name, options = {})
|
2120
|
-
|
2514
|
+
execute("DROP INDEX #{index_name(table_name, options)}")
|
2121
2515
|
end
|
2122
2516
|
|
2123
2517
|
protected
|
@@ -2131,14 +2525,15 @@ module ActiveRecord
|
|
2131
2525
|
register_class_with_limit m, %r(datetime)i, Type::DateTime
|
2132
2526
|
register_class_with_limit m, %r(float)i, Type::Float
|
2133
2527
|
register_class_with_limit m, %r(int)i, Type::Integer
|
2134
|
-
|
2528
|
+
|
2529
|
+
|
2135
2530
|
m.alias_type %r(blob)i, 'binary'
|
2136
2531
|
m.alias_type %r(clob)i, 'text'
|
2137
2532
|
m.alias_type %r(timestamp)i, 'datetime'
|
2138
2533
|
m.alias_type %r(numeric)i, 'decimal'
|
2139
2534
|
m.alias_type %r(number)i, 'decimal'
|
2140
2535
|
m.alias_type %r(double)i, 'float'
|
2141
|
-
|
2536
|
+
|
2142
2537
|
m.register_type(%r(decimal)i) do |sql_type|
|
2143
2538
|
scale = extract_scale(sql_type)
|
2144
2539
|
precision = extract_precision(sql_type)
|
@@ -2166,7 +2561,7 @@ module ActiveRecord
|
|
2166
2561
|
class IBM_DataServer
|
2167
2562
|
def initialize(adapter, ar3)
|
2168
2563
|
@adapter = adapter
|
2169
|
-
|
2564
|
+
@isAr3 = ar3
|
2170
2565
|
end
|
2171
2566
|
|
2172
2567
|
def last_generated_id(stmt)
|
@@ -2273,7 +2668,9 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2273
2668
|
end
|
2274
2669
|
end
|
2275
2670
|
|
2671
|
+
# Akhil Tcheck for if_exits added so that it will try to drop even if the table does not exit.
|
2276
2672
|
def execute(sql, name = nil)
|
2673
|
+
if name == nil || name.class == String
|
2277
2674
|
begin
|
2278
2675
|
if stmt = IBM_DB.exec(@adapter.connection, sql)
|
2279
2676
|
stmt # Return the statement object
|
@@ -2287,6 +2684,25 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2287
2684
|
raise
|
2288
2685
|
end
|
2289
2686
|
end
|
2687
|
+
else
|
2688
|
+
if name[:if_exists]
|
2689
|
+
IBM_DB.exec(@adapter.connection, sql)
|
2690
|
+
else
|
2691
|
+
begin
|
2692
|
+
if stmt = IBM_DB.exec(@adapter.connection, sql)
|
2693
|
+
stmt # Return the statement object
|
2694
|
+
else
|
2695
|
+
raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN )
|
2696
|
+
end
|
2697
|
+
rescue StandardError => exec_err
|
2698
|
+
if exec_err && !exec_err.message.empty?
|
2699
|
+
raise "Failed to execute statement due to: #{exec_err}"
|
2700
|
+
else
|
2701
|
+
raise
|
2702
|
+
end
|
2703
|
+
end
|
2704
|
+
end
|
2705
|
+
end
|
2290
2706
|
end
|
2291
2707
|
|
2292
2708
|
def set_schema(schema)
|
@@ -2345,7 +2761,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2345
2761
|
end
|
2346
2762
|
|
2347
2763
|
def primary_key_definition(start_id)
|
2348
|
-
return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH #{start_id}) PRIMARY KEY"
|
2764
|
+
return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH #{start_id}) PRIMARY KEY NOT NULL"
|
2349
2765
|
end
|
2350
2766
|
|
2351
2767
|
# Returns the last automatically generated ID.
|
@@ -2395,6 +2811,9 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2395
2811
|
end
|
2396
2812
|
|
2397
2813
|
def change_column(table_name, column_name, type, options)
|
2814
|
+
if !options[:default].nil?
|
2815
|
+
change_column_default(table_name, column_name, options[:default])
|
2816
|
+
else
|
2398
2817
|
data_type = @adapter.type_to_sql(type, options[:limit], options[:precision], options[:scale])
|
2399
2818
|
begin
|
2400
2819
|
execute "ALTER TABLE #{table_name} ALTER #{column_name} SET DATA TYPE #{data_type}"
|
@@ -2412,6 +2831,7 @@ The column datatype change to [#{data_type}] is not supported by this data serve
|
|
2412
2831
|
change_column_default(table_name, column_name, options[:default])
|
2413
2832
|
reorg_table(table_name)
|
2414
2833
|
end
|
2834
|
+
end
|
2415
2835
|
|
2416
2836
|
# DB2 specific ALTER TABLE statement to add a default clause
|
2417
2837
|
def change_column_default(table_name, column_name, default)
|
@@ -2468,12 +2888,14 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
2468
2888
|
return retHash
|
2469
2889
|
end
|
2470
2890
|
|
2891
|
+
|
2471
2892
|
if (offset.nil?)
|
2472
2893
|
retHash["endSegment"] = " FETCH FIRST #{limit} ROWS ONLY"
|
2473
2894
|
return retHash
|
2474
2895
|
end
|
2475
2896
|
|
2476
|
-
if(limit.nil?)
|
2897
|
+
#if(limit.nil?)
|
2898
|
+
if(limit.nil?)
|
2477
2899
|
#retHash["startSegment"] = "SELECT O.* FROM (SELECT I.*, ROW_NUMBER() OVER () sys_row_num FROM ( SELECT "
|
2478
2900
|
retHash["startSegment"] = "SELECT O.* FROM (SELECT I.*, ROW_NUMBER() OVER () sys_row_num FROM ( "
|
2479
2901
|
retHash["endSegment"] = " ) AS I) AS O WHERE sys_row_num > #{offset}"
|
@@ -2484,7 +2906,13 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
2484
2906
|
last_record = offset.to_i + limit.to_i
|
2485
2907
|
#retHash["startSegment"] = "SELECT O.* FROM (SELECT I.*, ROW_NUMBER() OVER () sys_row_num FROM ( SELECT "
|
2486
2908
|
retHash["startSegment"] = "SELECT O.* FROM (SELECT I.*, ROW_NUMBER() OVER () sys_row_num FROM ( "
|
2487
|
-
|
2909
|
+
|
2910
|
+
if last_record < offset+1
|
2911
|
+
retHash["endSegment"] = " ) AS I) AS O WHERE sys_row_num BETWEEN #{last_record} AND #{offset+1}"
|
2912
|
+
else
|
2913
|
+
retHash["endSegment"] = " ) AS I) AS O WHERE sys_row_num BETWEEN #{offset+1} AND #{last_record}"
|
2914
|
+
end
|
2915
|
+
|
2488
2916
|
return retHash
|
2489
2917
|
end
|
2490
2918
|
|
@@ -3004,7 +3432,7 @@ end
|
|
3004
3432
|
rescue
|
3005
3433
|
arelVersion = 0
|
3006
3434
|
end
|
3007
|
-
if(arelVersion >= 6)
|
3435
|
+
if(arelVersion >= 6 && arelVersion <= 9)
|
3008
3436
|
class ToSql < Arel::Visitors::Reduce #opening and closing the class to ensure backward compatibility
|
3009
3437
|
# In case when using Rails-2.3.x there is no arel used due to which the constructor has to be defined explicitly
|
3010
3438
|
# to ensure the same code works on any version of Rails
|
@@ -3057,54 +3485,7 @@ end
|
|
3057
3485
|
class IBM_DB < Arel::Visitors::ToSql
|
3058
3486
|
private
|
3059
3487
|
|
3060
|
-
|
3061
|
-
#Check Arel version
|
3062
|
-
begin
|
3063
|
-
@arelVersion = Arel::VERSION.to_i
|
3064
|
-
rescue
|
3065
|
-
@arelVersion = 0
|
3066
|
-
end
|
3067
|
-
if(@arelVersion < 6)
|
3068
|
-
|
3069
|
-
def visit_Arel_Nodes_Limit o, a=nil
|
3070
|
-
visit o.expr
|
3071
|
-
end
|
3072
|
-
|
3073
|
-
def visit_Arel_Nodes_Offset o, a=nil
|
3074
|
-
visit o.expr
|
3075
|
-
end
|
3076
|
-
def visit_Arel_Nodes_SelectStatement o, a=nil
|
3077
|
-
#Interim fix for backward compatibility [Arel 4.0.0 and below]
|
3078
|
-
if self.method(:visit_Arel_Nodes_SelectCore).arity == 1
|
3079
|
-
sql = [
|
3080
|
-
(visit(o.with) if o.with),
|
3081
|
-
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
|
3082
|
-
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
|
3083
|
-
].compact.join ' '
|
3084
|
-
else
|
3085
|
-
sql = [
|
3086
|
-
(visit(o.with) if o.with),
|
3087
|
-
o.cores.map { |x| visit_Arel_Nodes_SelectCore x,a }.join,
|
3088
|
-
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
|
3089
|
-
].compact.join ' '
|
3090
|
-
end
|
3091
|
-
|
3092
|
-
if o.limit
|
3093
|
-
limit = visit(o.limit)
|
3094
|
-
else
|
3095
|
-
limit = nil
|
3096
|
-
end
|
3097
|
-
|
3098
|
-
if o.offset
|
3099
|
-
offset = visit(o.offset)
|
3100
|
-
else
|
3101
|
-
offset = nil
|
3102
|
-
end
|
3103
|
-
@connection.add_limit_offset!(sql, {:limit => limit, :offset => offset})
|
3104
|
-
sql << " #{(visit(o.lock) if o.lock)}"
|
3105
|
-
return sql
|
3106
|
-
end
|
3107
|
-
else
|
3488
|
+
|
3108
3489
|
def visit_Arel_Nodes_Limit o,collector
|
3109
3490
|
visit o.expr, collector
|
3110
3491
|
end
|
@@ -3112,28 +3493,45 @@ else
|
|
3112
3493
|
def visit_Arel_Nodes_Offset o,collector
|
3113
3494
|
visit o.expr,collector
|
3114
3495
|
end
|
3115
|
-
|
3496
|
+
def visit_Arel_Nodes_ValuesList(o, collector)
|
3497
|
+
collector << "VALUES "
|
3498
|
+
o.rows.each_with_index do |row, i|
|
3499
|
+
collector << ", " unless i == 0
|
3500
|
+
collector << "("
|
3501
|
+
row.each_with_index do |value, k|
|
3502
|
+
collector << ", " unless k == 0
|
3503
|
+
case value
|
3504
|
+
when Nodes::SqlLiteral, Nodes::BindParam
|
3505
|
+
collector = visit(value, collector)
|
3506
|
+
#collector << quote(value).to_s
|
3507
|
+
else
|
3508
|
+
collector << value.to_s
|
3509
|
+
end
|
3510
|
+
end
|
3511
|
+
collector << ")"
|
3512
|
+
end
|
3513
|
+
collector
|
3514
|
+
end
|
3116
3515
|
def visit_Arel_Nodes_SelectStatement o, collector
|
3117
|
-
|
3118
3516
|
if o.with
|
3119
3517
|
collector = visit o.with, collector
|
3120
|
-
collector <<
|
3518
|
+
collector << " "
|
3121
3519
|
end
|
3122
3520
|
|
3123
3521
|
collector = o.cores.inject(collector) { |c,x|
|
3124
3522
|
visit_Arel_Nodes_SelectCore(x, c)
|
3125
3523
|
}
|
3126
3524
|
|
3127
|
-
unless o.orders.empty?
|
3128
|
-
collector <<
|
3129
|
-
collector << ORDER_BY
|
3525
|
+
unless o.orders.empty?
|
3526
|
+
collector << " ORDER BY "
|
3130
3527
|
len = o.orders.length - 1
|
3131
3528
|
o.orders.each_with_index { |x, i|
|
3132
3529
|
collector = visit(x, collector)
|
3133
|
-
collector <<
|
3530
|
+
collector << "," unless len == i
|
3134
3531
|
}
|
3135
3532
|
end
|
3136
3533
|
|
3534
|
+
|
3137
3535
|
if o.limit
|
3138
3536
|
limcoll = Arel::Collectors::SQLString.new
|
3139
3537
|
visit(o.limit,limcoll)
|
@@ -3141,7 +3539,7 @@ else
|
|
3141
3539
|
else
|
3142
3540
|
limit = nil
|
3143
3541
|
end
|
3144
|
-
|
3542
|
+
|
3145
3543
|
if o.offset
|
3146
3544
|
offcoll = Arel::Collectors::SQLString.new
|
3147
3545
|
visit(o.offset,offcoll)
|
@@ -3149,28 +3547,26 @@ else
|
|
3149
3547
|
else
|
3150
3548
|
offset = nil
|
3151
3549
|
end
|
3152
|
-
|
3550
|
+
|
3153
3551
|
limOffClause = @connection.get_limit_offset_clauses(limit,offset)
|
3154
|
-
|
3552
|
+
|
3155
3553
|
if( !limOffClause["startSegment"].empty? )
|
3156
|
-
#collector.changeFirstSegment(limOffClause["startSegment"])
|
3554
|
+
#collector.changeFirstSegment(limOffClause["startSegment"])
|
3157
3555
|
collector.value.prepend(limOffClause["startSegment"])
|
3158
3556
|
end
|
3159
3557
|
|
3160
3558
|
if( !limOffClause["endSegment"].empty? )
|
3161
3559
|
#collector.changeEndSegment(limOffClause["endSegment"])
|
3162
|
-
collector <<
|
3560
|
+
collector << " "
|
3163
3561
|
collector << limOffClause["endSegment"]
|
3164
3562
|
end
|
3165
3563
|
|
3166
3564
|
#Initialize a new Collector and set its value to the sql string built so far with any limit and ofset modifications
|
3167
3565
|
#collector.reset(sql)
|
3168
|
-
|
3566
|
+
|
3169
3567
|
collector = maybe_visit o.lock, collector
|
3170
|
-
|
3171
|
-
return collector
|
3568
|
+
return collector
|
3172
3569
|
end
|
3173
|
-
end
|
3174
3570
|
|
3175
3571
|
end
|
3176
3572
|
end
|