ibm_db 3.0.4 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (351) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +8 -1
  3. data/LICENSE +1 -1
  4. data/ParameterizedQueries README +6 -6
  5. data/README +38 -55
  6. data/ext/Makefile +266 -0
  7. data/ext/extconf.rb +34 -3
  8. data/ext/gil_release_version +3 -0
  9. data/ext/ibm_db.c +106 -111
  10. data/ext/ibm_db.o +0 -0
  11. data/ext/ibm_db.so +0 -0
  12. data/ext/mkmf.log +103 -0
  13. data/ext/ruby_ibm_db_cli.o +0 -0
  14. data/ext/unicode_support_version +3 -0
  15. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +911 -527
  16. data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
  17. data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
  18. data/test/cases/adapter_test.rb +148 -58
  19. data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
  20. data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
  21. data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
  22. data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
  23. data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
  24. data/test/cases/adapters/mysql2/connection_test.rb +210 -0
  25. data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
  26. data/test/cases/adapters/mysql2/enum_test.rb +26 -0
  27. data/test/cases/adapters/mysql2/explain_test.rb +21 -0
  28. data/test/cases/adapters/mysql2/json_test.rb +195 -0
  29. data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
  30. data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
  31. data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
  32. data/test/cases/adapters/mysql2/schema_test.rb +126 -0
  33. data/test/cases/adapters/mysql2/sp_test.rb +36 -0
  34. data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
  35. data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
  36. data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
  37. data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
  38. data/test/cases/adapters/postgresql/array_test.rb +339 -0
  39. data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
  40. data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
  41. data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
  42. data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
  43. data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
  44. data/test/cases/adapters/postgresql/citext_test.rb +78 -0
  45. data/test/cases/adapters/postgresql/collation_test.rb +53 -0
  46. data/test/cases/adapters/postgresql/composite_test.rb +132 -0
  47. data/test/cases/adapters/postgresql/connection_test.rb +257 -0
  48. data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
  49. data/test/cases/adapters/postgresql/domain_test.rb +47 -0
  50. data/test/cases/adapters/postgresql/enum_test.rb +91 -0
  51. data/test/cases/adapters/postgresql/explain_test.rb +20 -0
  52. data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
  53. data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
  54. data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
  55. data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
  56. data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
  57. data/test/cases/adapters/postgresql/integer_test.rb +25 -0
  58. data/test/cases/adapters/postgresql/json_test.rb +237 -0
  59. data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
  60. data/test/cases/adapters/postgresql/money_test.rb +96 -0
  61. data/test/cases/adapters/postgresql/network_test.rb +94 -0
  62. data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
  63. data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
  64. data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
  65. data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
  66. data/test/cases/adapters/postgresql/range_test.rb +343 -0
  67. data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
  68. data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
  69. data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
  70. data/test/cases/adapters/postgresql/schema_test.rb +597 -0
  71. data/test/cases/adapters/postgresql/serial_test.rb +154 -0
  72. data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
  73. data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
  74. data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
  75. data/test/cases/adapters/postgresql/utils_test.rb +62 -0
  76. data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
  77. data/test/cases/adapters/postgresql/xml_test.rb +54 -0
  78. data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
  79. data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
  80. data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
  81. data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
  82. data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
  83. data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
  84. data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
  85. data/test/cases/aggregations_test.rb +11 -1
  86. data/test/cases/ar_schema_test.rb +35 -50
  87. data/test/cases/associations/association_scope_test.rb +1 -6
  88. data/test/cases/associations/belongs_to_associations_test.rb +122 -10
  89. data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
  90. data/test/cases/associations/callbacks_test.rb +5 -7
  91. data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
  92. data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
  93. data/test/cases/associations/eager_test.rb +176 -73
  94. data/test/cases/associations/extension_test.rb +7 -2
  95. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +104 -32
  96. data/test/cases/associations/has_many_associations_test.rb +382 -43
  97. data/test/cases/associations/has_many_through_associations_test.rb +108 -41
  98. data/test/cases/associations/has_one_associations_test.rb +105 -8
  99. data/test/cases/associations/has_one_through_associations_test.rb +6 -3
  100. data/test/cases/associations/inner_join_association_test.rb +3 -3
  101. data/test/cases/associations/inverse_associations_test.rb +51 -11
  102. data/test/cases/associations/join_model_test.rb +59 -36
  103. data/test/cases/associations/left_outer_join_association_test.rb +88 -0
  104. data/test/cases/associations/nested_through_associations_test.rb +2 -2
  105. data/test/cases/associations/required_test.rb +25 -5
  106. data/test/cases/associations_test.rb +39 -34
  107. data/test/cases/attribute_decorators_test.rb +9 -8
  108. data/test/cases/attribute_methods/read_test.rb +5 -5
  109. data/test/cases/attribute_methods_test.rb +97 -40
  110. data/test/cases/attribute_set_test.rb +74 -4
  111. data/test/cases/attribute_test.rb +84 -18
  112. data/test/cases/attributes_test.rb +151 -34
  113. data/test/cases/autosave_association_test.rb +149 -36
  114. data/test/cases/base_test.rb +311 -236
  115. data/test/cases/batches_test.rb +299 -22
  116. data/test/cases/binary_test.rb +2 -10
  117. data/test/cases/bind_parameter_test.rb +76 -66
  118. data/test/cases/cache_key_test.rb +26 -0
  119. data/test/cases/calculations_test.rb +167 -15
  120. data/test/cases/callbacks_test.rb +161 -68
  121. data/test/cases/coders/json_test.rb +15 -0
  122. data/test/cases/collection_cache_key_test.rb +115 -0
  123. data/test/cases/column_definition_test.rb +26 -57
  124. data/test/cases/comment_test.rb +145 -0
  125. data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
  126. data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
  127. data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
  128. data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
  129. data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
  130. data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
  131. data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
  132. data/test/cases/connection_management_test.rb +46 -56
  133. data/test/cases/connection_pool_test.rb +195 -20
  134. data/test/cases/connection_specification/resolver_test.rb +15 -0
  135. data/test/cases/counter_cache_test.rb +10 -5
  136. data/test/cases/custom_locking_test.rb +1 -1
  137. data/test/cases/database_statements_test.rb +18 -3
  138. data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
  139. data/test/cases/date_time_precision_test.rb +107 -0
  140. data/test/cases/defaults_test.rb +85 -89
  141. data/test/cases/dirty_test.rb +32 -44
  142. data/test/cases/disconnected_test.rb +4 -2
  143. data/test/cases/enum_test.rb +178 -24
  144. data/test/cases/errors_test.rb +16 -0
  145. data/test/cases/explain_test.rb +32 -21
  146. data/test/cases/finder_test.rb +279 -151
  147. data/test/cases/fixture_set/file_test.rb +18 -0
  148. data/test/cases/fixtures_test.rb +123 -32
  149. data/test/cases/forbidden_attributes_protection_test.rb +69 -3
  150. data/test/cases/helper.rb +10 -16
  151. data/test/cases/hot_compatibility_test.rb +89 -1
  152. data/test/cases/inheritance_test.rb +284 -53
  153. data/test/cases/integration_test.rb +23 -7
  154. data/test/cases/invalid_connection_test.rb +4 -2
  155. data/test/cases/invertible_migration_test.rb +124 -32
  156. data/test/cases/json_serialization_test.rb +11 -2
  157. data/test/cases/locking_test.rb +22 -6
  158. data/test/cases/log_subscriber_test.rb +106 -17
  159. data/test/cases/migration/change_schema_test.rb +118 -132
  160. data/test/cases/migration/change_table_test.rb +34 -2
  161. data/test/cases/migration/column_attributes_test.rb +7 -23
  162. data/test/cases/migration/column_positioning_test.rb +8 -8
  163. data/test/cases/migration/columns_test.rb +17 -11
  164. data/test/cases/migration/command_recorder_test.rb +47 -2
  165. data/test/cases/migration/compatibility_test.rb +118 -0
  166. data/test/cases/migration/create_join_table_test.rb +21 -12
  167. data/test/cases/migration/foreign_key_test.rb +68 -66
  168. data/test/cases/migration/index_test.rb +14 -12
  169. data/test/cases/migration/logger_test.rb +1 -1
  170. data/test/cases/migration/pending_migrations_test.rb +0 -1
  171. data/test/cases/migration/references_foreign_key_test.rb +114 -107
  172. data/test/cases/migration/references_index_test.rb +4 -4
  173. data/test/cases/migration/references_statements_test.rb +26 -6
  174. data/test/cases/migration/rename_table_test.rb +25 -25
  175. data/test/cases/migration_test.rb +279 -81
  176. data/test/cases/migrator_test.rb +91 -8
  177. data/test/cases/mixin_test.rb +0 -2
  178. data/test/cases/modules_test.rb +3 -4
  179. data/test/cases/multiparameter_attributes_test.rb +24 -2
  180. data/test/cases/multiple_db_test.rb +18 -11
  181. data/test/cases/nested_attributes_test.rb +74 -33
  182. data/test/cases/persistence_test.rb +102 -10
  183. data/test/cases/pooled_connections_test.rb +3 -3
  184. data/test/cases/primary_keys_test.rb +170 -31
  185. data/test/cases/query_cache_test.rb +216 -96
  186. data/test/cases/quoting_test.rb +65 -19
  187. data/test/cases/readonly_test.rb +2 -1
  188. data/test/cases/reflection_test.rb +77 -22
  189. data/test/cases/relation/delegation_test.rb +3 -8
  190. data/test/cases/relation/merging_test.rb +10 -14
  191. data/test/cases/relation/mutation_test.rb +42 -24
  192. data/test/cases/relation/or_test.rb +92 -0
  193. data/test/cases/relation/predicate_builder_test.rb +4 -2
  194. data/test/cases/relation/record_fetch_warning_test.rb +40 -0
  195. data/test/cases/relation/where_chain_test.rb +23 -99
  196. data/test/cases/relation/where_clause_test.rb +182 -0
  197. data/test/cases/relation/where_test.rb +45 -23
  198. data/test/cases/relation_test.rb +89 -58
  199. data/test/cases/relations_test.rb +249 -38
  200. data/test/cases/result_test.rb +10 -0
  201. data/test/cases/sanitize_test.rb +108 -15
  202. data/test/cases/schema_dumper_test.rb +119 -125
  203. data/test/cases/schema_loading_test.rb +52 -0
  204. data/test/cases/scoping/default_scoping_test.rb +113 -39
  205. data/test/cases/scoping/named_scoping_test.rb +46 -9
  206. data/test/cases/scoping/relation_scoping_test.rb +47 -4
  207. data/test/cases/secure_token_test.rb +32 -0
  208. data/test/cases/serialization_test.rb +1 -1
  209. data/test/cases/serialized_attribute_test.rb +93 -6
  210. data/test/cases/statement_cache_test.rb +38 -0
  211. data/test/cases/store_test.rb +2 -1
  212. data/test/cases/suppressor_test.rb +63 -0
  213. data/test/cases/tasks/database_tasks_test.rb +74 -8
  214. data/test/cases/tasks/mysql_rake_test.rb +143 -109
  215. data/test/cases/tasks/postgresql_rake_test.rb +71 -12
  216. data/test/cases/tasks/sqlite_rake_test.rb +30 -3
  217. data/test/cases/test_case.rb +28 -20
  218. data/test/cases/test_fixtures_test.rb +36 -0
  219. data/test/cases/time_precision_test.rb +103 -0
  220. data/test/cases/timestamp_test.rb +47 -14
  221. data/test/cases/touch_later_test.rb +121 -0
  222. data/test/cases/transaction_callbacks_test.rb +128 -62
  223. data/test/cases/transaction_isolation_test.rb +2 -2
  224. data/test/cases/transactions_test.rb +61 -43
  225. data/test/cases/type/adapter_specific_registry_test.rb +133 -0
  226. data/test/cases/type/date_time_test.rb +14 -0
  227. data/test/cases/type/integer_test.rb +2 -96
  228. data/test/cases/type/string_test.rb +0 -14
  229. data/test/cases/type_test.rb +39 -0
  230. data/test/cases/types_test.rb +1 -118
  231. data/test/cases/unconnected_test.rb +1 -1
  232. data/test/cases/validations/absence_validation_test.rb +73 -0
  233. data/test/cases/validations/association_validation_test.rb +13 -2
  234. data/test/cases/validations/i18n_validation_test.rb +6 -10
  235. data/test/cases/validations/length_validation_test.rb +62 -30
  236. data/test/cases/validations/presence_validation_test.rb +36 -1
  237. data/test/cases/validations/uniqueness_validation_test.rb +150 -36
  238. data/test/cases/validations_repair_helper.rb +2 -6
  239. data/test/cases/validations_test.rb +36 -7
  240. data/test/cases/view_test.rb +108 -5
  241. data/test/cases/yaml_serialization_test.rb +36 -1
  242. data/test/config.example.yml +97 -0
  243. data/test/fixtures/bad_posts.yml +9 -0
  244. data/test/fixtures/books.yml +20 -0
  245. data/test/fixtures/content.yml +3 -0
  246. data/test/fixtures/content_positions.yml +3 -0
  247. data/test/fixtures/dead_parrots.yml +5 -0
  248. data/test/fixtures/live_parrots.yml +4 -0
  249. data/test/fixtures/naked/yml/parrots.yml +2 -0
  250. data/test/fixtures/naked/yml/trees.yml +3 -0
  251. data/test/fixtures/nodes.yml +29 -0
  252. data/test/fixtures/other_comments.yml +6 -0
  253. data/test/fixtures/other_dogs.yml +2 -0
  254. data/test/fixtures/other_posts.yml +7 -0
  255. data/test/fixtures/price_estimates.yml +10 -1
  256. data/test/fixtures/trees.yml +3 -0
  257. data/test/migrations/10_urban/9_add_expressions.rb +1 -1
  258. data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
  259. data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
  260. data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
  261. data/test/migrations/missing/1_people_have_last_names.rb +2 -2
  262. data/test/migrations/missing/3_we_need_reminders.rb +2 -2
  263. data/test/migrations/missing/4_innocent_jointable.rb +2 -2
  264. data/test/migrations/rename/1_we_need_things.rb +2 -2
  265. data/test/migrations/rename/2_rename_things.rb +2 -2
  266. data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
  267. data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
  268. data/test/migrations/to_copy2/1_create_articles.rb +1 -1
  269. data/test/migrations/to_copy2/2_create_comments.rb +1 -1
  270. data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
  271. data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
  272. data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
  273. data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
  274. data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
  275. data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
  276. data/test/migrations/valid/2_we_need_reminders.rb +2 -2
  277. data/test/migrations/valid/3_innocent_jointable.rb +2 -2
  278. data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
  279. data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
  280. data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
  281. data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
  282. data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
  283. data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
  284. data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
  285. data/test/models/admin/randomly_named_c1.rb +6 -2
  286. data/test/models/aircraft.rb +1 -0
  287. data/test/models/author.rb +4 -7
  288. data/test/models/bird.rb +1 -1
  289. data/test/models/book.rb +5 -0
  290. data/test/models/bulb.rb +2 -1
  291. data/test/models/car.rb +3 -0
  292. data/test/models/cat.rb +10 -0
  293. data/test/models/chef.rb +5 -0
  294. data/test/models/club.rb +2 -0
  295. data/test/models/comment.rb +17 -5
  296. data/test/models/company.rb +7 -2
  297. data/test/models/company_in_module.rb +1 -1
  298. data/test/models/contact.rb +1 -1
  299. data/test/models/content.rb +40 -0
  300. data/test/models/customer.rb +8 -2
  301. data/test/models/developer.rb +22 -0
  302. data/test/models/face.rb +1 -1
  303. data/test/models/guitar.rb +4 -0
  304. data/test/models/hotel.rb +5 -0
  305. data/test/models/member.rb +1 -0
  306. data/test/models/member_detail.rb +4 -3
  307. data/test/models/mentor.rb +3 -0
  308. data/test/models/mocktail_designer.rb +2 -0
  309. data/test/models/node.rb +5 -0
  310. data/test/models/non_primary_key.rb +2 -0
  311. data/test/models/notification.rb +3 -0
  312. data/test/models/other_dog.rb +5 -0
  313. data/test/models/owner.rb +4 -1
  314. data/test/models/parrot.rb +6 -7
  315. data/test/models/person.rb +0 -1
  316. data/test/models/pet.rb +3 -0
  317. data/test/models/pet_treasure.rb +6 -0
  318. data/test/models/pirate.rb +3 -3
  319. data/test/models/post.rb +18 -9
  320. data/test/models/project.rb +11 -0
  321. data/test/models/randomly_named_c1.rb +1 -1
  322. data/test/models/recipe.rb +3 -0
  323. data/test/models/ship.rb +8 -2
  324. data/test/models/tag.rb +6 -0
  325. data/test/models/topic.rb +2 -8
  326. data/test/models/tree.rb +3 -0
  327. data/test/models/tuning_peg.rb +4 -0
  328. data/test/models/user.rb +14 -0
  329. data/test/models/uuid_item.rb +6 -0
  330. data/test/schema/mysql2_specific_schema.rb +33 -23
  331. data/test/schema/oracle_specific_schema.rb +1 -4
  332. data/test/schema/postgresql_specific_schema.rb +36 -124
  333. data/test/schema/schema.rb +183 -64
  334. data/test/schema/schema.rb.original +1057 -0
  335. data/test/schema/sqlite_specific_schema.rb +1 -5
  336. data/test/support/connection.rb +1 -0
  337. data/test/support/schema_dumping_helper.rb +1 -1
  338. data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
  339. data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
  340. metadata +145 -26
  341. data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
  342. data/test/cases/attribute_methods/serialization_test.rb +0 -29
  343. data/test/cases/migration/change_schema_test - Copy.rb +0 -448
  344. data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
  345. data/test/cases/migration/table_and_index_test.rb +0 -24
  346. data/test/cases/relation/where_test2.rb +0 -36
  347. data/test/cases/type/decimal_test.rb +0 -51
  348. data/test/cases/type/unsigned_integer_test.rb +0 -18
  349. data/test/cases/xml_serialization_test.rb +0 -457
  350. data/test/fixtures/naked/csv/accounts.csv +0 -1
  351. data/test/schema/mysql_specific_schema.rb +0 -70
@@ -1,2 +1,5 @@
1
1
  #rb file to support alising of adapter name as ibmdb [without underscore] that will require ibm_db_adapter.rb
2
- require 'active_record/connection_adapters/ibm_db_adapter'
2
+ require 'active_record/connection_adapters/ibm_db_adapter'
3
+
4
+ require 'active_record/connection_adapters/ibm_schema_dumper'
5
+
@@ -7,7 +7,7 @@ module ActiveRecord
7
7
 
8
8
  module ConnectionAdapters
9
9
  class FakeAdapter < AbstractAdapter
10
- attr_accessor :tables, :primary_keys
10
+ attr_accessor :data_sources, :primary_keys
11
11
 
12
12
  @columns = Hash.new { |h,k| h[k] = [] }
13
13
  class << self
@@ -16,21 +16,20 @@ module ActiveRecord
16
16
 
17
17
  def initialize(connection, logger)
18
18
  super
19
- @tables = []
19
+ @data_sources = []
20
20
  @primary_keys = {}
21
21
  @columns = self.class.columns
22
22
  end
23
23
 
24
24
  def primary_key(table)
25
- @primary_keys[table]
25
+ @primary_keys[table] || "id"
26
26
  end
27
27
 
28
28
  def merge_column(table_name, name, sql_type = nil, options = {})
29
29
  @columns[table_name] << ActiveRecord::ConnectionAdapters::Column.new(
30
30
  name.to_s,
31
31
  options[:default],
32
- lookup_cast_type(sql_type.to_s),
33
- sql_type.to_s,
32
+ fetch_type_metadata(sql_type),
34
33
  options[:null])
35
34
  end
36
35
 
@@ -38,6 +37,10 @@ module ActiveRecord
38
37
  @columns[table_name]
39
38
  end
40
39
 
40
+ def data_source_exists?(*)
41
+ true
42
+ end
43
+
41
44
  def active?
42
45
  true
43
46
  end
@@ -1,19 +1,19 @@
1
- # encoding: utf-8
2
-
3
1
  require "cases/helper"
4
2
  require "models/book"
5
3
  require "models/post"
6
4
  require "models/author"
5
+ require "models/event"
7
6
 
8
7
  module ActiveRecord
9
8
  class AdapterTest < ActiveRecord::TestCase
10
- def setup
9
+ def setup
11
10
  @connection = ActiveRecord::Base.connection
12
11
  end
13
12
 
14
13
  ##
15
14
  # PostgreSQL does not support null bytes in strings
16
- unless current_adapter?(:PostgreSQLAdapter)
15
+ unless current_adapter?(:PostgreSQLAdapter, :IBM_DBAdapter) ||
16
+ (current_adapter?(:SQLite3Adapter) && !ActiveRecord::Base.connection.prepared_statements)
17
17
  def test_update_prepared_statement
18
18
  b = Book.create(name: "my \x00 book")
19
19
  b.reload
@@ -24,18 +24,49 @@ module ActiveRecord
24
24
  end
25
25
  end
26
26
 
27
+ unless current_adapter?(:IBM_DBAdapter)
28
+ def test_create_record_with_pk_as_zero
29
+ Book.create(id: 0)
30
+ assert_equal 0, Book.find(0).id
31
+ assert_nothing_raised { Book.destroy(0) }
32
+ end
33
+ end
34
+
27
35
  def test_tables
28
- tables = @connection.tables
36
+ tables = nil
37
+ ActiveSupport::Deprecation.silence { tables = @connection.tables }
29
38
  assert tables.include?("accounts")
30
39
  assert tables.include?("authors")
31
40
  assert tables.include?("tasks")
32
41
  assert tables.include?("topics")
33
42
  end
34
43
 
44
+
35
45
  def test_table_exists?
36
- assert @connection.table_exists?("accounts")
37
- assert !@connection.table_exists?("nonexistingtable")
38
- assert !@connection.table_exists?(nil)
46
+ ActiveSupport::Deprecation.silence do
47
+ assert @connection.table_exists?("accounts")
48
+ assert !@connection.table_exists?("nonexistingtable")
49
+ assert !@connection.table_exists?(nil)
50
+ end
51
+ end
52
+
53
+ def test_table_exists_checking_both_tables_and_views_is_deprecated
54
+ assert_deprecated { @connection.table_exists?("accounts") }
55
+ end
56
+
57
+ def test_data_sources
58
+ data_sources = @connection.data_sources
59
+ assert data_sources.include?("accounts")
60
+ assert data_sources.include?("authors")
61
+ assert data_sources.include?("tasks")
62
+ assert data_sources.include?("topics")
63
+ end
64
+
65
+ def test_data_source_exists?
66
+ assert @connection.data_source_exists?("accounts")
67
+ assert @connection.data_source_exists?(:accounts)
68
+ assert_not @connection.data_source_exists?("nonexistingtable")
69
+ assert_not @connection.data_source_exists?(nil)
39
70
  end
40
71
 
41
72
  def test_indexes
@@ -59,13 +90,26 @@ module ActiveRecord
59
90
  @connection.remove_index(:accounts, :name => idx_name) rescue nil
60
91
  end
61
92
 
93
+ unless current_adapter?(:IBM_DBAdapter)
94
+ def test_remove_index_when_name_and_wrong_column_name_specified
95
+ index_name = "accounts_idx"
96
+
97
+ @connection.add_index :accounts, :firm_id, :name => index_name
98
+ assert_raises ArgumentError do
99
+ @connection.remove_index :accounts, :name => index_name, :column => :wrong_column_name
100
+ end
101
+ ensure
102
+ @connection.remove_index(:accounts, :name => index_name)
103
+ end
104
+ end
105
+
62
106
  def test_current_database
63
107
  if @connection.respond_to?(:current_database)
64
108
  assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
65
109
  end
66
110
  end
67
111
 
68
- if current_adapter?(:MysqlAdapter)
112
+ if current_adapter?(:Mysql2Adapter)
69
113
  def test_charset
70
114
  assert_not_nil @connection.charset
71
115
  assert_not_equal 'character_set_database', @connection.charset
@@ -135,17 +179,21 @@ module ActiveRecord
135
179
  assert_nothing_raised { sub.save! }
136
180
  end
137
181
  end
138
-
139
- def test_uniqueness_violations_are_translated_to_specific_exception
140
- @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
141
- assert_raises(ActiveRecord::RecordNotUnique) do
142
- @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
143
- end
144
- end
145
-
146
- unless current_adapter?(:SQLite3Adapter)
182
+
183
+ unless current_adapter?(:IBM_DBAdapter)
184
+ def test_uniqueness_violations_are_translated_to_specific_exception
185
+ @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
186
+ error = assert_raises(ActiveRecord::RecordNotUnique) do
187
+ @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
188
+ end
189
+
190
+ assert_not_nil error.cause
191
+ end
192
+ end
193
+
194
+ unless current_adapter?(:SQLite3Adapter, :IBM_DBAdapter)
147
195
  def test_foreign_key_violations_are_translated_to_specific_exception
148
- assert_raises(ActiveRecord::InvalidForeignKey) do
196
+ error = assert_raises(ActiveRecord::InvalidForeignKey) do
149
197
  # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
150
198
  if @connection.prefetch_primary_key?
151
199
  id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
@@ -154,6 +202,8 @@ module ActiveRecord
154
202
  @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
155
203
  end
156
204
  end
205
+
206
+ assert_not_nil error.cause
157
207
  end
158
208
 
159
209
  def test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false
@@ -161,11 +211,21 @@ module ActiveRecord
161
211
  self.table_name = 'fk_test_has_fk'
162
212
  end
163
213
 
164
- assert_raises(ActiveRecord::InvalidForeignKey) do
214
+ error = assert_raises(ActiveRecord::InvalidForeignKey) do
165
215
  has_fk = klass_has_fk.new
166
216
  has_fk.fk_id = 1231231231
167
217
  has_fk.save(validate: false)
168
218
  end
219
+
220
+ assert_not_nil error.cause
221
+ end
222
+
223
+ def test_value_limit_violations_are_translated_to_specific_exception
224
+ error = assert_raises(ActiveRecord::ValueTooLong) do
225
+ Event.create(title: 'abcdefgh')
226
+ end
227
+
228
+ assert_not_nil error.cause
169
229
  end
170
230
  end
171
231
 
@@ -191,44 +251,69 @@ module ActiveRecord
191
251
  assert result.is_a?(ActiveRecord::Result)
192
252
  end
193
253
 
194
- def test_select_methods_passing_a_association_relation
195
- author = Author.create!(name: 'john')
196
- Post.create!(author: author, title: 'foo', body: 'bar')
197
- query = author.posts.where(title: 'foo').select(:title)
198
- assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bind_values))
199
- assert_equal({"title" => "foo"}, @connection.select_one(query))
200
- assert @connection.select_all(query).is_a?(ActiveRecord::Result)
201
- assert_equal "foo", @connection.select_value(query)
202
- assert_equal ["foo"], @connection.select_values(query)
254
+ if ActiveRecord::Base.connection.prepared_statements
255
+ def test_select_all_with_legacy_binds
256
+ post = Post.create!(title: "foo", body: "bar")
257
+ expected = @connection.select_all("SELECT * FROM posts WHERE id = #{post.id}")
258
+ result = @connection.select_all("SELECT * FROM posts WHERE id = #{Arel::Nodes::BindParam.new.to_sql}", nil, [[nil, post.id]])
259
+ assert_equal expected.to_hash, result.to_hash
260
+ end
203
261
  end
204
262
 
205
- def test_select_methods_passing_a_relation
206
- Post.create!(title: 'foo', body: 'bar')
207
- query = Post.where(title: 'foo').select(:title)
208
- assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bind_values))
209
- assert_equal({"title" => "foo"}, @connection.select_one(query))
210
- assert @connection.select_all(query).is_a?(ActiveRecord::Result)
211
- assert_equal "foo", @connection.select_value(query)
212
- assert_equal ["foo"], @connection.select_values(query)
213
- end
263
+ unless current_adapter?(:IBM_DBAdapter)
264
+ def test_select_methods_passing_a_association_relation
265
+ author = Author.create!(name: 'john')
266
+ Post.create!(author: author, title: 'foo', body: 'bar')
267
+ query = author.posts.where(title: 'foo').select(:title)
268
+ assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes))
269
+ assert_equal({"title" => "foo"}, @connection.select_one(query))
270
+ assert @connection.select_all(query).is_a?(ActiveRecord::Result)
271
+ assert_equal "foo", @connection.select_value(query)
272
+ assert_equal ["foo"], @connection.select_values(query)
273
+ end
274
+ end
275
+
276
+ unless current_adapter?(:IBM_DBAdapter)
277
+ def test_select_methods_passing_a_relation
278
+ Post.create!(title: 'foo', body: 'bar')
279
+ query = Post.where(title: 'foo').select(:title)
280
+ assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes))
281
+ assert_equal({"title" => "foo"}, @connection.select_one(query))
282
+ assert @connection.select_all(query).is_a?(ActiveRecord::Result)
283
+ assert_equal "foo", @connection.select_value(query)
284
+ assert_equal ["foo"], @connection.select_values(query)
285
+ end
286
+ end
214
287
 
215
288
  test "type_to_sql returns a String for unmapped types" do
216
289
  assert_equal "special_db_type", @connection.type_to_sql(:special_db_type)
217
290
  end
218
291
 
219
- unless current_adapter?(:PostgreSQLAdapter)
292
+ unless current_adapter?(:PostgreSQLAdapter, :IBM_DBAdapter)
220
293
  def test_log_invalid_encoding
221
- assert_raise ActiveRecord::StatementInvalid do
222
- @connection.send :log, "SELECT '?' FROM DUAL" do
223
- raise '?'.force_encoding(Encoding::ASCII_8BIT)
294
+ error = assert_raise ActiveRecord::StatementInvalid do
295
+ @connection.send :log, "SELECT 'ы' FROM DUAL" do
296
+ raise 'ы'.force_encoding(Encoding::ASCII_8BIT)
224
297
  end
225
298
  end
299
+
300
+ assert_not_nil error.cause
301
+ end
302
+ end
303
+
304
+ if current_adapter?(:Mysql2Adapter, :SQLite3Adapter)
305
+ def test_tables_returning_both_tables_and_views_is_deprecated
306
+ assert_deprecated { @connection.tables }
226
307
  end
227
308
  end
309
+
310
+ def test_passing_arguments_to_tables_is_deprecated
311
+ assert_deprecated { @connection.tables(:books) }
312
+ end
228
313
  end
229
314
 
230
315
  class AdapterTestWithoutTransaction < ActiveRecord::TestCase
231
- self.use_transactional_fixtures = false
316
+ self.use_transactional_tests = false
232
317
 
233
318
  class Klass < ActiveRecord::Base
234
319
  end
@@ -242,20 +327,25 @@ module ActiveRecord
242
327
  Klass.remove_connection
243
328
  end
244
329
 
245
- unless in_memory_db?
246
- test "transaction state is reset after a reconnect" do
247
- @connection.begin_transaction
248
- assert @connection.transaction_open?
249
- @connection.reconnect!
250
- assert !@connection.transaction_open?
251
- end
252
-
253
- test "transaction state is reset after a disconnect" do
254
- @connection.begin_transaction
255
- assert @connection.transaction_open?
256
- @connection.disconnect!
257
- assert !@connection.transaction_open?
258
- end
259
- end
330
+ unless current_adapter?(:IBM_DBAdapter)
331
+ unless in_memory_db?
332
+ test "transaction state is reset after a reconnect" do
333
+ @connection.begin_transaction
334
+ assert @connection.transaction_open?
335
+ @connection.reconnect!
336
+ assert !@connection.transaction_open?
337
+ end
338
+
339
+ test "transaction state is reset after a disconnect" do
340
+ @connection.begin_transaction
341
+ assert @connection.transaction_open?
342
+ @connection.disconnect!
343
+ assert !@connection.transaction_open?
344
+ end
345
+ end
346
+ end
347
+
260
348
  end
349
+
350
+
261
351
  end
@@ -0,0 +1,193 @@
1
+ require "cases/helper"
2
+ require 'support/connection_helper'
3
+
4
+ class Mysql2ActiveSchemaTest < ActiveRecord::Mysql2TestCase
5
+ include ConnectionHelper
6
+
7
+ def setup
8
+ ActiveRecord::Base.connection.singleton_class.class_eval do
9
+ alias_method :execute_without_stub, :execute
10
+ def execute(sql, name = nil) return sql end
11
+ end
12
+ end
13
+
14
+ teardown do
15
+ reset_connection
16
+ end
17
+
18
+ def test_add_index
19
+ # add_index calls data_source_exists? and index_name_exists? which can't work since execute is stubbed
20
+ def (ActiveRecord::Base.connection).data_source_exists?(*); true; end
21
+ def (ActiveRecord::Base.connection).index_name_exists?(*); false; end
22
+
23
+ expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`) "
24
+ assert_equal expected, add_index(:people, :last_name, :length => nil)
25
+
26
+ expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`(10)) "
27
+ assert_equal expected, add_index(:people, :last_name, :length => 10)
28
+
29
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(15)) "
30
+ assert_equal expected, add_index(:people, [:last_name, :first_name], length: 15)
31
+ assert_equal expected, add_index(:people, ["last_name", "first_name"], length: 15)
32
+
33
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`) "
34
+ assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15 })
35
+ assert_equal expected, add_index(:people, ["last_name", "first_name"], length: { last_name: 15 })
36
+
37
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10)) "
38
+ assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15, first_name: 10 })
39
+ assert_equal expected, add_index(:people, ["last_name", :first_name], length: { last_name: 15, "first_name" => 10 })
40
+
41
+ %w(SPATIAL FULLTEXT UNIQUE).each do |type|
42
+ expected = "CREATE #{type} INDEX `index_people_on_last_name` ON `people` (`last_name`) "
43
+ assert_equal expected, add_index(:people, :last_name, :type => type)
44
+ end
45
+
46
+ %w(btree hash).each do |using|
47
+ expected = "CREATE INDEX `index_people_on_last_name` USING #{using} ON `people` (`last_name`) "
48
+ assert_equal expected, add_index(:people, :last_name, :using => using)
49
+ end
50
+
51
+ expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) "
52
+ assert_equal expected, add_index(:people, :last_name, :length => 10, :using => :btree)
53
+
54
+ expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) ALGORITHM = COPY"
55
+ assert_equal expected, add_index(:people, :last_name, :length => 10, using: :btree, algorithm: :copy)
56
+
57
+ assert_raise ArgumentError do
58
+ add_index(:people, :last_name, algorithm: :coyp)
59
+ end
60
+
61
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` USING btree ON `people` (`last_name`(15), `first_name`(15)) "
62
+ assert_equal expected, add_index(:people, [:last_name, :first_name], :length => 15, :using => :btree)
63
+ end
64
+
65
+ def test_index_in_create
66
+ def (ActiveRecord::Base.connection).data_source_exists?(*); false; end
67
+
68
+ %w(SPATIAL FULLTEXT UNIQUE).each do |type|
69
+ expected = "CREATE TABLE `people` (#{type} INDEX `index_people_on_last_name` (`last_name`)) ENGINE=InnoDB"
70
+ actual = ActiveRecord::Base.connection.create_table(:people, id: false) do |t|
71
+ t.index :last_name, type: type
72
+ end
73
+ assert_equal expected, actual
74
+ end
75
+
76
+ expected = "CREATE TABLE `people` ( INDEX `index_people_on_last_name` USING btree (`last_name`(10))) ENGINE=InnoDB"
77
+ actual = ActiveRecord::Base.connection.create_table(:people, id: false) do |t|
78
+ t.index :last_name, length: 10, using: :btree
79
+ end
80
+ assert_equal expected, actual
81
+ end
82
+
83
+ def test_index_in_bulk_change
84
+ def (ActiveRecord::Base.connection).data_source_exists?(*); true; end
85
+ def (ActiveRecord::Base.connection).index_name_exists?(*); false; end
86
+
87
+ %w(SPATIAL FULLTEXT UNIQUE).each do |type|
88
+ expected = "ALTER TABLE `people` ADD #{type} INDEX `index_people_on_last_name` (`last_name`)"
89
+ actual = ActiveRecord::Base.connection.change_table(:people, bulk: true) do |t|
90
+ t.index :last_name, type: type
91
+ end
92
+ assert_equal expected, actual
93
+ end
94
+
95
+ expected = "ALTER TABLE `peaple` ADD INDEX `index_peaple_on_last_name` USING btree (`last_name`(10)), ALGORITHM = COPY"
96
+ actual = ActiveRecord::Base.connection.change_table(:peaple, bulk: true) do |t|
97
+ t.index :last_name, length: 10, using: :btree, algorithm: :copy
98
+ end
99
+ assert_equal expected, actual
100
+ end
101
+
102
+ def test_drop_table
103
+ assert_equal "DROP TABLE `people`", drop_table(:people)
104
+ end
105
+
106
+ def test_create_mysql_database_with_encoding
107
+ assert_equal "CREATE DATABASE `matt` DEFAULT CHARACTER SET `utf8`", create_database(:matt)
108
+ assert_equal "CREATE DATABASE `aimonetti` DEFAULT CHARACTER SET `latin1`", create_database(:aimonetti, {:charset => 'latin1'})
109
+ assert_equal "CREATE DATABASE `matt_aimonetti` DEFAULT CHARACTER SET `big5` COLLATE `big5_chinese_ci`", create_database(:matt_aimonetti, {:charset => :big5, :collation => :big5_chinese_ci})
110
+ end
111
+
112
+ def test_recreate_mysql_database_with_encoding
113
+ create_database(:luca, {:charset => 'latin1'})
114
+ assert_equal "CREATE DATABASE `luca` DEFAULT CHARACTER SET `latin1`", recreate_database(:luca, {:charset => 'latin1'})
115
+ end
116
+
117
+ def test_add_column
118
+ assert_equal "ALTER TABLE `people` ADD `last_name` varchar(255)", add_column(:people, :last_name, :string)
119
+ end
120
+
121
+ def test_add_column_with_limit
122
+ assert_equal "ALTER TABLE `people` ADD `key` varchar(32)", add_column(:people, :key, :string, :limit => 32)
123
+ end
124
+
125
+ def test_drop_table_with_specific_database
126
+ assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people')
127
+ end
128
+
129
+ def test_add_timestamps
130
+ with_real_execute do
131
+ begin
132
+ ActiveRecord::Base.connection.create_table :delete_me
133
+ ActiveRecord::Base.connection.add_timestamps :delete_me, null: true
134
+ assert column_present?('delete_me', 'updated_at', 'datetime')
135
+ assert column_present?('delete_me', 'created_at', 'datetime')
136
+ ensure
137
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
138
+ end
139
+ end
140
+ end
141
+
142
+ def test_remove_timestamps
143
+ with_real_execute do
144
+ begin
145
+ ActiveRecord::Base.connection.create_table :delete_me do |t|
146
+ t.timestamps null: true
147
+ end
148
+ ActiveRecord::Base.connection.remove_timestamps :delete_me, { null: true }
149
+ assert !column_present?('delete_me', 'updated_at', 'datetime')
150
+ assert !column_present?('delete_me', 'created_at', 'datetime')
151
+ ensure
152
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
153
+ end
154
+ end
155
+ end
156
+
157
+ def test_indexes_in_create
158
+ ActiveRecord::Base.connection.stubs(:data_source_exists?).with(:temp).returns(false)
159
+ ActiveRecord::Base.connection.stubs(:index_name_exists?).with(:index_temp_on_zip).returns(false)
160
+
161
+ expected = "CREATE TEMPORARY TABLE `temp` ( INDEX `index_temp_on_zip` (`zip`)) ENGINE=InnoDB AS SELECT id, name, zip FROM a_really_complicated_query"
162
+ actual = ActiveRecord::Base.connection.create_table(:temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query") do |t|
163
+ t.index :zip
164
+ end
165
+
166
+ assert_equal expected, actual
167
+ end
168
+
169
+ private
170
+ def with_real_execute
171
+ ActiveRecord::Base.connection.singleton_class.class_eval do
172
+ alias_method :execute_with_stub, :execute
173
+ remove_method :execute
174
+ alias_method :execute, :execute_without_stub
175
+ end
176
+
177
+ yield
178
+ ensure
179
+ ActiveRecord::Base.connection.singleton_class.class_eval do
180
+ remove_method :execute
181
+ alias_method :execute, :execute_with_stub
182
+ end
183
+ end
184
+
185
+ def method_missing(method_symbol, *arguments)
186
+ ActiveRecord::Base.connection.send(method_symbol, *arguments)
187
+ end
188
+
189
+ def column_present?(table_name, column_name, type)
190
+ results = ActiveRecord::Base.connection.select_all("SHOW FIELDS FROM #{table_name} LIKE '#{column_name}'")
191
+ results.first && results.first['Type'] == type
192
+ end
193
+ end