sequel 5.29.0 → 5.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (323) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +8 -1922
  3. data/doc/release_notes/5.30.0.txt +20 -0
  4. data/lib/sequel/adapters/shared/sqlite.rb +7 -1
  5. data/lib/sequel/database/transactions.rb +5 -9
  6. data/lib/sequel/version.rb +1 -1
  7. metadata +4 -368
  8. data/Rakefile +0 -151
  9. data/doc/release_notes/4.0.0.txt +0 -262
  10. data/doc/release_notes/4.1.0.txt +0 -85
  11. data/doc/release_notes/4.10.0.txt +0 -226
  12. data/doc/release_notes/4.11.0.txt +0 -147
  13. data/doc/release_notes/4.12.0.txt +0 -105
  14. data/doc/release_notes/4.13.0.txt +0 -169
  15. data/doc/release_notes/4.14.0.txt +0 -68
  16. data/doc/release_notes/4.15.0.txt +0 -56
  17. data/doc/release_notes/4.16.0.txt +0 -36
  18. data/doc/release_notes/4.17.0.txt +0 -38
  19. data/doc/release_notes/4.18.0.txt +0 -36
  20. data/doc/release_notes/4.19.0.txt +0 -45
  21. data/doc/release_notes/4.2.0.txt +0 -129
  22. data/doc/release_notes/4.20.0.txt +0 -79
  23. data/doc/release_notes/4.21.0.txt +0 -94
  24. data/doc/release_notes/4.22.0.txt +0 -72
  25. data/doc/release_notes/4.23.0.txt +0 -65
  26. data/doc/release_notes/4.24.0.txt +0 -99
  27. data/doc/release_notes/4.25.0.txt +0 -181
  28. data/doc/release_notes/4.26.0.txt +0 -44
  29. data/doc/release_notes/4.27.0.txt +0 -78
  30. data/doc/release_notes/4.28.0.txt +0 -57
  31. data/doc/release_notes/4.29.0.txt +0 -41
  32. data/doc/release_notes/4.3.0.txt +0 -40
  33. data/doc/release_notes/4.30.0.txt +0 -37
  34. data/doc/release_notes/4.31.0.txt +0 -57
  35. data/doc/release_notes/4.32.0.txt +0 -132
  36. data/doc/release_notes/4.33.0.txt +0 -88
  37. data/doc/release_notes/4.34.0.txt +0 -86
  38. data/doc/release_notes/4.35.0.txt +0 -130
  39. data/doc/release_notes/4.36.0.txt +0 -116
  40. data/doc/release_notes/4.37.0.txt +0 -50
  41. data/doc/release_notes/4.38.0.txt +0 -67
  42. data/doc/release_notes/4.39.0.txt +0 -127
  43. data/doc/release_notes/4.4.0.txt +0 -92
  44. data/doc/release_notes/4.40.0.txt +0 -179
  45. data/doc/release_notes/4.41.0.txt +0 -77
  46. data/doc/release_notes/4.42.0.txt +0 -221
  47. data/doc/release_notes/4.43.0.txt +0 -87
  48. data/doc/release_notes/4.44.0.txt +0 -125
  49. data/doc/release_notes/4.45.0.txt +0 -370
  50. data/doc/release_notes/4.46.0.txt +0 -404
  51. data/doc/release_notes/4.47.0.txt +0 -56
  52. data/doc/release_notes/4.48.0.txt +0 -293
  53. data/doc/release_notes/4.49.0.txt +0 -222
  54. data/doc/release_notes/4.5.0.txt +0 -34
  55. data/doc/release_notes/4.6.0.txt +0 -30
  56. data/doc/release_notes/4.7.0.txt +0 -103
  57. data/doc/release_notes/4.8.0.txt +0 -175
  58. data/doc/release_notes/4.9.0.txt +0 -190
  59. data/spec/adapter_spec.rb +0 -4
  60. data/spec/adapters/db2_spec.rb +0 -170
  61. data/spec/adapters/mssql_spec.rb +0 -828
  62. data/spec/adapters/mysql_spec.rb +0 -1060
  63. data/spec/adapters/oracle_spec.rb +0 -371
  64. data/spec/adapters/postgres_spec.rb +0 -4476
  65. data/spec/adapters/spec_helper.rb +0 -44
  66. data/spec/adapters/sqlanywhere_spec.rb +0 -97
  67. data/spec/adapters/sqlite_spec.rb +0 -652
  68. data/spec/bin_spec.rb +0 -278
  69. data/spec/core/connection_pool_spec.rb +0 -1250
  70. data/spec/core/database_spec.rb +0 -2915
  71. data/spec/core/dataset_spec.rb +0 -5544
  72. data/spec/core/deprecated_spec.rb +0 -70
  73. data/spec/core/expression_filters_spec.rb +0 -1498
  74. data/spec/core/mock_adapter_spec.rb +0 -722
  75. data/spec/core/object_graph_spec.rb +0 -336
  76. data/spec/core/placeholder_literalizer_spec.rb +0 -166
  77. data/spec/core/schema_generator_spec.rb +0 -214
  78. data/spec/core/schema_spec.rb +0 -1844
  79. data/spec/core/spec_helper.rb +0 -24
  80. data/spec/core/version_spec.rb +0 -14
  81. data/spec/core_extensions_spec.rb +0 -763
  82. data/spec/core_model_spec.rb +0 -2
  83. data/spec/core_spec.rb +0 -1
  84. data/spec/deprecation_helper.rb +0 -30
  85. data/spec/extensions/accessed_columns_spec.rb +0 -51
  86. data/spec/extensions/active_model_spec.rb +0 -99
  87. data/spec/extensions/after_initialize_spec.rb +0 -28
  88. data/spec/extensions/any_not_empty_spec.rb +0 -23
  89. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  90. data/spec/extensions/association_dependencies_spec.rb +0 -125
  91. data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
  92. data/spec/extensions/association_pks_spec.rb +0 -423
  93. data/spec/extensions/association_proxies_spec.rb +0 -100
  94. data/spec/extensions/auto_literal_strings_spec.rb +0 -205
  95. data/spec/extensions/auto_validations_spec.rb +0 -229
  96. data/spec/extensions/blacklist_security_spec.rb +0 -95
  97. data/spec/extensions/blank_spec.rb +0 -69
  98. data/spec/extensions/boolean_readers_spec.rb +0 -93
  99. data/spec/extensions/boolean_subsets_spec.rb +0 -47
  100. data/spec/extensions/caching_spec.rb +0 -273
  101. data/spec/extensions/caller_logging_spec.rb +0 -52
  102. data/spec/extensions/class_table_inheritance_spec.rb +0 -750
  103. data/spec/extensions/column_conflicts_spec.rb +0 -75
  104. data/spec/extensions/column_select_spec.rb +0 -129
  105. data/spec/extensions/columns_introspection_spec.rb +0 -90
  106. data/spec/extensions/columns_updated_spec.rb +0 -35
  107. data/spec/extensions/composition_spec.rb +0 -248
  108. data/spec/extensions/connection_expiration_spec.rb +0 -151
  109. data/spec/extensions/connection_validator_spec.rb +0 -144
  110. data/spec/extensions/constant_sql_override_spec.rb +0 -24
  111. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
  112. data/spec/extensions/constraint_validations_spec.rb +0 -439
  113. data/spec/extensions/core_refinements_spec.rb +0 -528
  114. data/spec/extensions/csv_serializer_spec.rb +0 -183
  115. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  116. data/spec/extensions/dataset_associations_spec.rb +0 -365
  117. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  118. data/spec/extensions/date_arithmetic_spec.rb +0 -181
  119. data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
  120. data/spec/extensions/def_dataset_method_spec.rb +0 -100
  121. data/spec/extensions/defaults_setter_spec.rb +0 -150
  122. data/spec/extensions/delay_add_association_spec.rb +0 -73
  123. data/spec/extensions/dirty_spec.rb +0 -222
  124. data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
  125. data/spec/extensions/eager_each_spec.rb +0 -62
  126. data/spec/extensions/eager_graph_eager_spec.rb +0 -100
  127. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  128. data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
  129. data/spec/extensions/error_splitter_spec.rb +0 -18
  130. data/spec/extensions/error_sql_spec.rb +0 -20
  131. data/spec/extensions/escaped_like_spec.rb +0 -40
  132. data/spec/extensions/eval_inspect_spec.rb +0 -81
  133. data/spec/extensions/exclude_or_null_spec.rb +0 -15
  134. data/spec/extensions/finder_spec.rb +0 -260
  135. data/spec/extensions/force_encoding_spec.rb +0 -126
  136. data/spec/extensions/freeze_datasets_spec.rb +0 -31
  137. data/spec/extensions/graph_each_spec.rb +0 -113
  138. data/spec/extensions/hook_class_methods_spec.rb +0 -402
  139. data/spec/extensions/identifier_mangling_spec.rb +0 -201
  140. data/spec/extensions/implicit_subquery_spec.rb +0 -58
  141. data/spec/extensions/index_caching_spec.rb +0 -66
  142. data/spec/extensions/inflector_spec.rb +0 -183
  143. data/spec/extensions/input_transformer_spec.rb +0 -69
  144. data/spec/extensions/insert_conflict_spec.rb +0 -103
  145. data/spec/extensions/insert_returning_select_spec.rb +0 -72
  146. data/spec/extensions/instance_filters_spec.rb +0 -79
  147. data/spec/extensions/instance_hooks_spec.rb +0 -246
  148. data/spec/extensions/integer64_spec.rb +0 -22
  149. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  150. data/spec/extensions/json_serializer_spec.rb +0 -346
  151. data/spec/extensions/lazy_attributes_spec.rb +0 -183
  152. data/spec/extensions/list_spec.rb +0 -291
  153. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  154. data/spec/extensions/many_through_many_spec.rb +0 -2177
  155. data/spec/extensions/migration_spec.rb +0 -864
  156. data/spec/extensions/modification_detection_spec.rb +0 -93
  157. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
  158. data/spec/extensions/named_timezones_spec.rb +0 -218
  159. data/spec/extensions/nested_attributes_spec.rb +0 -815
  160. data/spec/extensions/null_dataset_spec.rb +0 -85
  161. data/spec/extensions/optimistic_locking_spec.rb +0 -127
  162. data/spec/extensions/pagination_spec.rb +0 -116
  163. data/spec/extensions/pg_array_associations_spec.rb +0 -802
  164. data/spec/extensions/pg_array_ops_spec.rb +0 -144
  165. data/spec/extensions/pg_array_spec.rb +0 -398
  166. data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
  167. data/spec/extensions/pg_enum_spec.rb +0 -118
  168. data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
  169. data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
  170. data/spec/extensions/pg_hstore_spec.rb +0 -219
  171. data/spec/extensions/pg_inet_ops_spec.rb +0 -102
  172. data/spec/extensions/pg_inet_spec.rb +0 -72
  173. data/spec/extensions/pg_interval_spec.rb +0 -103
  174. data/spec/extensions/pg_json_ops_spec.rb +0 -356
  175. data/spec/extensions/pg_json_spec.rb +0 -451
  176. data/spec/extensions/pg_loose_count_spec.rb +0 -23
  177. data/spec/extensions/pg_range_ops_spec.rb +0 -60
  178. data/spec/extensions/pg_range_spec.rb +0 -600
  179. data/spec/extensions/pg_row_ops_spec.rb +0 -61
  180. data/spec/extensions/pg_row_plugin_spec.rb +0 -60
  181. data/spec/extensions/pg_row_spec.rb +0 -363
  182. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
  183. data/spec/extensions/pg_timestamptz_spec.rb +0 -17
  184. data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
  185. data/spec/extensions/prepared_statements_spec.rb +0 -177
  186. data/spec/extensions/pretty_table_spec.rb +0 -123
  187. data/spec/extensions/query_spec.rb +0 -94
  188. data/spec/extensions/rcte_tree_spec.rb +0 -387
  189. data/spec/extensions/round_timestamps_spec.rb +0 -39
  190. data/spec/extensions/s_spec.rb +0 -60
  191. data/spec/extensions/schema_caching_spec.rb +0 -64
  192. data/spec/extensions/schema_dumper_spec.rb +0 -870
  193. data/spec/extensions/select_remove_spec.rb +0 -38
  194. data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
  195. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  196. data/spec/extensions/serialization_spec.rb +0 -365
  197. data/spec/extensions/server_block_spec.rb +0 -135
  198. data/spec/extensions/server_logging_spec.rb +0 -45
  199. data/spec/extensions/sharding_spec.rb +0 -197
  200. data/spec/extensions/shared_caching_spec.rb +0 -151
  201. data/spec/extensions/single_table_inheritance_spec.rb +0 -347
  202. data/spec/extensions/singular_table_names_spec.rb +0 -22
  203. data/spec/extensions/skip_create_refresh_spec.rb +0 -18
  204. data/spec/extensions/spec_helper.rb +0 -70
  205. data/spec/extensions/split_array_nil_spec.rb +0 -24
  206. data/spec/extensions/split_values_spec.rb +0 -57
  207. data/spec/extensions/sql_comments_spec.rb +0 -33
  208. data/spec/extensions/sql_expr_spec.rb +0 -59
  209. data/spec/extensions/static_cache_cache_spec.rb +0 -35
  210. data/spec/extensions/static_cache_spec.rb +0 -471
  211. data/spec/extensions/string_agg_spec.rb +0 -90
  212. data/spec/extensions/string_date_time_spec.rb +0 -95
  213. data/spec/extensions/string_stripper_spec.rb +0 -68
  214. data/spec/extensions/subclasses_spec.rb +0 -79
  215. data/spec/extensions/subset_conditions_spec.rb +0 -38
  216. data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
  217. data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
  218. data/spec/extensions/synchronize_sql_spec.rb +0 -124
  219. data/spec/extensions/table_select_spec.rb +0 -83
  220. data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
  221. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  222. data/spec/extensions/throw_failures_spec.rb +0 -74
  223. data/spec/extensions/timestamps_spec.rb +0 -209
  224. data/spec/extensions/to_dot_spec.rb +0 -153
  225. data/spec/extensions/touch_spec.rb +0 -226
  226. data/spec/extensions/tree_spec.rb +0 -334
  227. data/spec/extensions/typecast_on_load_spec.rb +0 -86
  228. data/spec/extensions/unlimited_update_spec.rb +0 -21
  229. data/spec/extensions/update_or_create_spec.rb +0 -83
  230. data/spec/extensions/update_primary_key_spec.rb +0 -105
  231. data/spec/extensions/update_refresh_spec.rb +0 -59
  232. data/spec/extensions/uuid_spec.rb +0 -101
  233. data/spec/extensions/validate_associated_spec.rb +0 -52
  234. data/spec/extensions/validation_class_methods_spec.rb +0 -1040
  235. data/spec/extensions/validation_contexts_spec.rb +0 -31
  236. data/spec/extensions/validation_helpers_spec.rb +0 -525
  237. data/spec/extensions/whitelist_security_spec.rb +0 -157
  238. data/spec/extensions/xml_serializer_spec.rb +0 -213
  239. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  240. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  241. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  242. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  243. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  244. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  245. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  246. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  247. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  248. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  249. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  250. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  251. data/spec/files/double_migration/001_create_sessions.rb +0 -9
  252. data/spec/files/double_migration/002_create_nodes.rb +0 -19
  253. data/spec/files/double_migration/003_3_create_users.rb +0 -4
  254. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  255. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  256. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  257. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  258. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  259. data/spec/files/empty_migration/001_create_sessions.rb +0 -9
  260. data/spec/files/empty_migration/002_create_nodes.rb +0 -0
  261. data/spec/files/empty_migration/003_3_create_users.rb +0 -4
  262. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  263. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  264. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  265. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  266. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  267. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  268. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  269. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  270. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  271. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  272. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  273. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  274. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  275. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  276. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  277. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  278. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  279. data/spec/files/reversible_migrations/006_reversible.rb +0 -10
  280. data/spec/files/reversible_migrations/007_reversible.rb +0 -10
  281. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  282. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  283. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  284. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  285. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  286. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  287. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  288. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  289. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  290. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  291. data/spec/guards_helper.rb +0 -59
  292. data/spec/integration/associations_test.rb +0 -2597
  293. data/spec/integration/database_test.rb +0 -113
  294. data/spec/integration/dataset_test.rb +0 -2037
  295. data/spec/integration/eager_loader_test.rb +0 -687
  296. data/spec/integration/migrator_test.rb +0 -262
  297. data/spec/integration/model_test.rb +0 -203
  298. data/spec/integration/plugin_test.rb +0 -2423
  299. data/spec/integration/prepared_statement_test.rb +0 -405
  300. data/spec/integration/schema_test.rb +0 -903
  301. data/spec/integration/spec_helper.rb +0 -71
  302. data/spec/integration/timezone_test.rb +0 -86
  303. data/spec/integration/transaction_test.rb +0 -603
  304. data/spec/integration/type_test.rb +0 -127
  305. data/spec/model/association_reflection_spec.rb +0 -803
  306. data/spec/model/associations_spec.rb +0 -4738
  307. data/spec/model/base_spec.rb +0 -875
  308. data/spec/model/class_dataset_methods_spec.rb +0 -146
  309. data/spec/model/dataset_methods_spec.rb +0 -198
  310. data/spec/model/eager_loading_spec.rb +0 -2377
  311. data/spec/model/hooks_spec.rb +0 -370
  312. data/spec/model/inflector_spec.rb +0 -26
  313. data/spec/model/model_spec.rb +0 -956
  314. data/spec/model/plugins_spec.rb +0 -429
  315. data/spec/model/record_spec.rb +0 -2118
  316. data/spec/model/spec_helper.rb +0 -46
  317. data/spec/model/validations_spec.rb +0 -220
  318. data/spec/model_no_assoc_spec.rb +0 -1
  319. data/spec/model_spec.rb +0 -1
  320. data/spec/plugin_spec.rb +0 -1
  321. data/spec/sequel_coverage.rb +0 -15
  322. data/spec/sequel_warning.rb +0 -5
  323. data/spec/spec_config.rb +0 -12
@@ -1,4 +0,0 @@
1
- if !ARGV.empty? && ARGV.first != 'none'
2
- require_relative "adapters/#{ARGV.first}_spec"
3
- end
4
- Dir['./spec/integration/*_test.rb'].each{|f| require f}
@@ -1,170 +0,0 @@
1
- SEQUEL_ADAPTER_TEST = :db2
2
-
3
- require_relative 'spec_helper'
4
-
5
- if DB.table_exists?(:test)
6
- DB.drop_table(:test)
7
- end
8
-
9
- describe Sequel::Database do
10
- before do
11
- @db = DB
12
- @db.create_table(:test){String :a}
13
- @ds = @db[:test]
14
- end
15
-
16
- after do
17
- @db.drop_table(:test)
18
- end
19
-
20
- it "should provide disconnect functionality after preparing a connection" do
21
- @ds.prepare(:first, :a).call
22
- @db.disconnect
23
- @db.pool.size.must_equal 0
24
- end
25
-
26
- it "should return version correctly" do
27
- @db.db2_version.must_match(/DB2 v/i)
28
- end
29
- end
30
-
31
- describe "Simple Dataset operations" do
32
- before(:all) do
33
- DB.use_clob_as_blob = true
34
- DB.create_table!(:items) do
35
- Integer :id, :primary_key => true
36
- Integer :number
37
- column :bin_string, 'varchar(20) for bit data'
38
- column :bin_clob, 'clob'
39
- end
40
- @ds = DB[:items]
41
- end
42
- after(:each) do
43
- @ds.delete
44
- end
45
- after(:all) do
46
- DB.use_clob_as_blob = false
47
- DB.drop_table(:items)
48
- end
49
-
50
- it "should insert with a primary key specified" do
51
- @ds.insert(:id => 1, :number => 10)
52
- @ds.insert(:id => 100, :number => 20)
53
- @ds.select_hash(:id, :number).must_equal(1 => 10, 100 => 20)
54
- end
55
-
56
- it "should insert into binary columns" do
57
- @ds.insert(:id => 1, :bin_string => Sequel.blob("\1"), :bin_clob => Sequel.blob("\2"))
58
- @ds.select(:bin_string, :bin_clob).first.must_equal(:bin_string => "\1", :bin_clob => "\2")
59
- end
60
- end
61
-
62
- describe Sequel::Database do
63
- before do
64
- @db = DB
65
- end
66
- after do
67
- @db.drop_table(:items)
68
- end
69
-
70
- it "should parse primary keys from the schema properly" do
71
- @db.create_table!(:items){Integer :number}
72
- @db.schema(:items).collect{|k,v| k if v[:primary_key]}.compact.must_equal []
73
- @db.create_table!(:items){primary_key :number}
74
- @db.schema(:items).collect{|k,v| k if v[:primary_key]}.compact.must_equal [:number]
75
- @db.create_table!(:items){Integer :number1, :null => false; Integer :number2, :null => false; primary_key [:number1, :number2]}
76
- @db.schema(:items).collect{|k,v| k if v[:primary_key]}.compact.must_equal [:number1, :number2]
77
- end
78
-
79
- it "should not error on alter_table operations that need REORG" do
80
- @db.create_table!(:items) do
81
- varchar :a
82
- end
83
- @db.alter_table(:items) do
84
- add_column :b, :varchar, :null => true
85
- set_column_allow_null :a, false
86
- add_index :a, :unique => true
87
- end
88
- end
89
- end
90
-
91
- describe "Sequel::IBMDB::Database#convert_smallint_to_bool" do
92
- before do
93
- @db = DB
94
- @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
95
- @ds = @db[:booltest]
96
- end
97
- after do
98
- @db.convert_smallint_to_bool = true
99
- @db.drop_table(:booltest)
100
- end
101
-
102
- it "should consider smallint datatypes as boolean if set, but not larger smallints" do
103
- @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :boolean
104
- @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
105
- @db.convert_smallint_to_bool = false
106
- @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :integer
107
- @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
108
- end
109
-
110
- it "should return smallints as bools and integers as integers when set" do
111
- @db.convert_smallint_to_bool = true
112
- @ds.delete
113
- @ds.insert(:b=>true, :i=>10)
114
- @ds.all.must_equal [{:b=>true, :i=>10}]
115
- @ds.delete
116
- @ds.insert(:b=>false, :i=>0)
117
- @ds.all.must_equal [{:b=>false, :i=>0}]
118
- @ds.delete
119
- @ds.insert(:b=>true, :i=>1)
120
- @ds.all.must_equal [{:b=>true, :i=>1}]
121
-
122
- @ds = @ds.with_convert_smallint_to_bool(false)
123
- @ds.delete
124
- @ds.insert(:b=>true, :i=>10)
125
- @ds.all.must_equal [{:b=>1, :i=>10}]
126
- end
127
-
128
- it "should return all smallints as integers when unset" do
129
- @db.convert_smallint_to_bool = false
130
- @ds.delete
131
- @ds.insert(:b=>true, :i=>10)
132
- @ds.all.must_equal [{:b=>1, :i=>10}]
133
- @ds.delete
134
- @ds.insert(:b=>false, :i=>0)
135
- @ds.all.must_equal [{:b=>0, :i=>0}]
136
-
137
- @ds.delete
138
- @ds.insert(:b=>1, :i=>10)
139
- @ds.all.must_equal [{:b=>1, :i=>10}]
140
- @ds.delete
141
- @ds.insert(:b=>0, :i=>0)
142
- @ds.all.must_equal [{:b=>0, :i=>0}]
143
-
144
- @ds = @ds.with_convert_smallint_to_bool(true)
145
- @ds.delete
146
- @ds.insert(:b=>true, :i=>10)
147
- @ds.all.must_equal [{:b=>true, :i=>10}]
148
- end
149
- end if DB.adapter_scheme == :ibmdb
150
-
151
- describe "Simple Dataset operations in transactions" do
152
- before do
153
- DB.create_table!(:items_insert_in_transaction) do
154
- Integer :id, :primary_key => true
155
- integer :number
156
- end
157
- @ds = DB[:items_insert_in_transaction]
158
- end
159
- after do
160
- DB.drop_table(:items_insert_in_transaction)
161
- end
162
-
163
- it "should insert correctly with a primary key specified inside a transaction" do
164
- DB.transaction do
165
- @ds.insert(:id=>100, :number=>20)
166
- @ds.count.must_equal 1
167
- @ds.order(:id).all.must_equal [{:id=>100, :number=>20}]
168
- end
169
- end
170
- end
@@ -1,828 +0,0 @@
1
- SEQUEL_ADAPTER_TEST = :mssql
2
-
3
- require_relative 'spec_helper'
4
-
5
- describe "A MSSQL database" do
6
- before do
7
- @db = DB
8
- end
9
-
10
- it "should be able to read fractional part of timestamp" do
11
- rs = @db["select getutcdate() as full_date, cast(round(datepart(millisecond, getutcdate()), 0) as int) as milliseconds"].first
12
- rs[:milliseconds].must_be_close_to(rs[:full_date].usec/1000, 2)
13
- end
14
-
15
- it "should be able to write fractional part of timestamp" do
16
- t = Time.utc(2001, 12, 31, 23, 59, 59, 996000)
17
- (t.usec/1000).must_equal @db["select cast(round(datepart(millisecond, ?), 0) as int) as milliseconds", t].get
18
- end
19
-
20
- it "should not raise an error when getting the server version" do
21
- @db.server_version
22
- @db.dataset.server_version
23
- end
24
- end
25
-
26
- describe "A MSSQL database" do
27
- before do
28
- @db = DB
29
- @db.create_table! :test3 do
30
- Integer :value
31
- Time :time
32
- end
33
- end
34
- after do
35
- @db.drop_table?(:test3)
36
- end
37
-
38
- it "should work with NOLOCK" do
39
- @db.transaction{@db[:test3].nolock.all.must_equal []}
40
- end
41
- end
42
-
43
- describe "MSSQL decimal locale handling" do
44
- before do
45
- @locale = WIN32OLE.locale
46
- @decimal = BigDecimal('1234.56')
47
- end
48
- after do
49
- WIN32OLE.locale = @locale
50
- end
51
-
52
- it "should work with current locale" do
53
- DB.get(Sequel.cast(@decimal, 'decimal(16,4)').as(:v)).must_equal @decimal
54
- end
55
-
56
- it "should work with 1031 locale" do
57
- WIN32OLE.locale = 1031
58
- DB.get(Sequel.cast(@decimal, 'decimal(16,4)').as(:v)).must_equal @decimal
59
- end
60
-
61
- it "should work with 1033 locale" do
62
- WIN32OLE.locale = 1033
63
- DB.get(Sequel.cast(@decimal, 'decimal(16,4)').as(:v)).must_equal @decimal
64
- end
65
- end if DB.adapter_scheme == :ado
66
-
67
- describe "MSSQL" do
68
- before(:all) do
69
- @db = DB
70
- @db.create_table!(:test3){Integer :v3}
71
- @db.create_table!(:test4){Integer :v4}
72
- @db[:test3].import([:v3], [[1], [2]])
73
- @db[:test4].import([:v4], [[1], [3]])
74
- end
75
- after(:all) do
76
- @db.drop_table?(:test3, :test4)
77
- end
78
-
79
- it "should should support CROSS APPLY" do
80
- @db[:test3].cross_apply(@db[:test4].where(Sequel[:test3][:v3]=>Sequel[:test4][:v4])).select_order_map([:v3, :v4]).must_equal [[1,1]]
81
- end
82
-
83
- it "should should support OUTER APPLY" do
84
- @db[:test3].outer_apply(@db[:test4].where(Sequel[:test3][:v3]=>Sequel[:test4][:v4])).select_order_map([:v3, :v4]).must_equal [[1,1], [2, nil]]
85
- end
86
-
87
- cspecify "should handle time values with fractional seconds", [:ado] do
88
- # ado: Returns nil values
89
- t = Sequel::SQLTime.create(10, 20, 30, 999900)
90
- v = @db.get(Sequel.cast(t, 'time'))
91
- v = Sequel.string_to_time(v) if v.is_a?(String)
92
- pr = lambda{|x| [:hour, :min, :sec, :usec].map{|m| x.send(m)}}
93
- pr[v].must_equal(pr[t])
94
- end
95
-
96
- cspecify "should get datetimeoffset values as Time with fractional seconds", [:odbc], [:ado], [:tinytds, proc{|db| TinyTds::VERSION < '0.9'}] do
97
- # odbc: Returns string rounded to nearest second
98
- # ado: Returns nil values
99
- # tiny_tds < 0.9: Returns wrong value for hour
100
- t = Time.local(2010, 11, 12, 10, 20, 30, 999000)
101
- v = @db.get(Sequel.cast(t, 'datetimeoffset'))
102
- v = Sequel.string_to_datetime(v) if v.is_a?(String)
103
- pr = lambda{|x| [:year, :month, :day, :hour, :min, :sec, :usec].map{|m| x.send(m)}}
104
- pr[v].must_equal(pr[t])
105
- end
106
- end
107
-
108
- # This spec is currently disabled as the SQL Server 2008 R2 Express doesn't support
109
- # full text searching. Even if full text searching is supported,
110
- # you may need to create a full text catalog on the database first via:
111
- # CREATE FULLTEXT CATALOG ftscd AS DEFAULT
112
- describe "MSSQL full_text_search" do
113
- before do
114
- @db = DB
115
- @db.drop_table?(:posts)
116
- end
117
- after do
118
- @db.drop_table?(:posts)
119
- end
120
-
121
- it "should support fulltext indexes and full_text_search" do
122
- log do
123
- @db.create_table(:posts){Integer :id, :null=>false; String :title; String :body; index :id, :name=>:fts_id_idx, :unique=>true; full_text_index :title, :key_index=>:fts_id_idx; full_text_index [:title, :body], :key_index=>:fts_id_idx}
124
- @db[:posts].insert(:title=>'ruby rails', :body=>'y')
125
- @db[:posts].insert(:title=>'sequel', :body=>'ruby')
126
- @db[:posts].insert(:title=>'ruby scooby', :body=>'x')
127
-
128
- @db[:posts].full_text_search(:title, 'rails').all.must_equal [{:title=>'ruby rails', :body=>'y'}]
129
- @db[:posts].full_text_search([:title, :body], ['sequel', 'ruby']).all.must_equal [{:title=>'sequel', :body=>'ruby'}]
130
-
131
- @db[:posts].full_text_search(:title, :$n).call(:select, :n=>'rails').must_equal [{:title=>'ruby rails', :body=>'y'}]
132
- @db[:posts].full_text_search(:title, :$n).prepare(:select, :fts_select).call(:n=>'rails').must_equal [{:title=>'ruby rails', :body=>'y'}]
133
- end
134
- end
135
- end if false
136
-
137
- describe "MSSQL Dataset#output" do
138
- before(:all) do
139
- @db = DB
140
- @db.create_table!(:items){String :name; Integer :value}
141
- @db.create_table!(:out){String :name; Integer :value}
142
- @ds = @db[:items]
143
- end
144
- after do
145
- @ds.delete
146
- @db[:out].delete
147
- end
148
- after(:all) do
149
- @db.drop_table?(:items, :out)
150
- end
151
-
152
- it "should handle OUTPUT clauses without INTO for DELETE statements" do
153
- @ds.insert(:name=>'a', :value=>1)
154
- @ds.output(nil, [Sequel[:deleted][:name], Sequel[:deleted][:value]]).with_sql(:delete_sql).all.must_equal [{:name=>"a", :value=>1}]
155
- @ds.insert(:name=>'a', :value=>1)
156
- @ds.output(nil, [Sequel[:deleted][:name]]).with_sql(:delete_sql).all.must_equal [{:name=>"a"}]
157
- @ds.insert(:name=>'a', :value=>1)
158
- @ds.output(nil, [Sequel::SQL::ColumnAll.new(:deleted)]).with_sql(:delete_sql).all.must_equal [{:name=>"a", :value=>1}]
159
- end
160
-
161
- it "should handle OUTPUT clauses with INTO for DELETE statements" do
162
- @ds.insert(:name=>'a', :value=>1)
163
- @ds.output(:out, {:name => Sequel[:deleted][:name], :value => Sequel[:deleted][:value]}).delete
164
- @db[:out].all.must_equal [{:name=>"a", :value=>1}]
165
- end
166
-
167
- it "should handle OUTPUT clauses without INTO for INSERT statements" do
168
- @ds.output(nil, [Sequel[:inserted][:name], Sequel[:inserted][:value]]).with_sql(:insert_sql, :name => "name", :value => 1).all.must_equal [{:name=>"name", :value=>1}]
169
- @ds.all.must_equal [{:name=>"name", :value=>1}]
170
- end
171
-
172
- it "should handle OUTPUT clauses with INTO for INSERT statements" do
173
- @ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:inserted][:value]}).insert(:name => "name", :value => 1)
174
- @db[:out].all.must_equal [{:name=>"name", :value=>1}]
175
- end
176
-
177
- it "should handle OUTPUT clauses without INTO for UPDATE statements" do
178
- @ds.insert(:name=>'a', :value=>1)
179
- @ds.output(nil, [Sequel[:inserted][:name], Sequel[:deleted][:value]]).with_sql(:update_sql, :value => 2).all.must_equal [{:name=>"a", :value=>1}]
180
- @ds.all.must_equal [{:name=>"a", :value=>2}]
181
- @ds.output(nil, [Sequel[:inserted][:name]]).with_sql(:update_sql, :value => 3).all.must_equal [{:name=>"a"}]
182
- @ds.all.must_equal [{:name=>"a", :value=>3}]
183
- @ds.output(nil, [Sequel::SQL::ColumnAll.new(:inserted)]).with_sql(:update_sql, :value => 4).all.must_equal [{:name=>"a", :value=>4}]
184
- end
185
-
186
- it "should handle OUTPUT clauses with INTO for UPDATE statements" do
187
- @ds.insert(:name=>'a', :value=>1)
188
- @ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:deleted][:value]}).update(:value => 2)
189
- @db[:out].all.must_equal [{:name=>"a", :value=>1}]
190
- end
191
-
192
- it "should execute OUTPUT clauses in DELETE statements" do
193
- @ds.insert(:name => "name", :value => 1)
194
- @ds.output(:out, [Sequel[:deleted][:name], Sequel[:deleted][:value]]).delete
195
- @db[:out].all.must_equal [{:name => "name", :value => 1}]
196
- @ds.insert(:name => "name", :value => 2)
197
- @ds.output(:out, {:name => Sequel[:deleted][:name], :value => Sequel[:deleted][:value]}).delete
198
- @db[:out].all.must_equal [{:name => "name", :value => 1}, {:name => "name", :value => 2}]
199
- end
200
-
201
- it "should execute OUTPUT clauses in INSERT statements" do
202
- @ds.output(:out, [Sequel[:inserted][:name], Sequel[:inserted][:value]]).insert(:name => "name", :value => 1)
203
- @db[:out].all.must_equal [{:name => "name", :value => 1}]
204
- @ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:inserted][:value]}).insert(:name => "name", :value => 2)
205
- @db[:out].all.must_equal [{:name => "name", :value => 1}, {:name => "name", :value => 2}]
206
- end
207
-
208
- it "should execute OUTPUT clauses in UPDATE statements" do
209
- @ds.insert(:name => "name", :value => 1)
210
- @ds.output(:out, [Sequel[:inserted][:name], Sequel[:deleted][:value]]).update(:value => 2)
211
- @db[:out].all.must_equal [{:name => "name", :value => 1}]
212
- @ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:deleted][:value]}).update(:value => 3)
213
- @db[:out].all.must_equal [{:name => "name", :value => 1}, {:name => "name", :value => 2}]
214
- end
215
- end
216
-
217
- describe "MSSQL dataset using #with and #with_recursive" do
218
- before(:all) do
219
- @db = DB
220
- @ds = DB[:x]
221
- @ds1 = @ds.with(:t, @db[:x])
222
- @ds2 = @ds.with_recursive(:t, @db[:x], @db[:t].where(false))
223
- @db.create_table!(:x){Integer :v; Integer :y}
224
- end
225
- before do
226
- @db[:x].insert(:v=>1, :y=>2)
227
- end
228
- after do
229
- @db[:x].delete
230
- end
231
- after(:all) do
232
- @db.drop_table?(:x)
233
- end
234
-
235
- it "should handle CTEs in UPDATE queries" do
236
- @ds1.update(:v => @db[:t].select(:y))
237
- @ds.all.must_equal [{:v=>2, :y=>2}]
238
- @ds2.update(:v => Sequel.+(@db[:t].select(:y), 1))
239
- @ds.all.must_equal [{:v=>3, :y=>2}]
240
- end
241
-
242
- it "should handle CTEs in DELETE queries" do
243
- @ds1.where(@db[:t].select(:y)=>1).delete
244
- @ds.all.must_equal [{:v=>1, :y=>2}]
245
- @ds1.where(@db[:t].select(:y)=>2).delete
246
- @ds.all.must_equal []
247
-
248
- @db[:x].insert(:v=>1, :y=>2)
249
- @ds2.where(@db[:t].select(:y)=>1).delete
250
- @ds.all.must_equal [{:v=>1, :y=>2}]
251
- @ds2.where(@db[:t].select(:y)=>2).delete
252
- @ds.all.must_equal []
253
- end
254
-
255
- it "should handle CTEs in INSERT queries" do
256
- @ds1.insert(:v => @db[:t].select(:y), :y => @db[:t].select(:v))
257
- @ds.select_order_map([:v, :y]).must_equal [[1, 2], [2, 1]]
258
- @ds1.insert(:v => Sequel.+(@db[:t].where(:v=>1).select(:y), 2), :y => Sequel.+(@db[:t].where(:y=>1).select(:v), 3))
259
- @ds.select_order_map([:v, :y]).must_equal [[1, 2], [2, 1], [4, 5]]
260
- end
261
-
262
- it "should handle WITH clause on joined dataset" do
263
- @ds.cross_join(@ds1.select(Sequel[:v].as(:v1), Sequel[:y].as(:y1))).all.must_equal [{:v=>1, :y=>2, :v1=>1, :y1=>2}]
264
- @ds.cross_join(@ds2.select(Sequel[:v].as(:v1), Sequel[:y].as(:y1))).all.must_equal [{:v=>1, :y=>2, :v1=>1, :y1=>2}]
265
- end
266
- end
267
-
268
- describe "MSSQL::Dataset#import" do
269
- before do
270
- @db = DB
271
- @ds = @db[:test]
272
- end
273
- after do
274
- @db.drop_table?(:test)
275
- end
276
-
277
- it "#import should work correctly with an arbitrary output value" do
278
- @db.create_table!(:test){primary_key :x; Integer :y}
279
- @ds.output(nil, [Sequel[:inserted][:y], Sequel[:inserted][:x]]).import([:y], [[3], [4]]).must_equal [{:y=>3, :x=>1}, {:y=>4, :x=>2}]
280
- @ds.all.must_equal [{:x=>1, :y=>3}, {:x=>2, :y=>4}]
281
- end
282
-
283
- it "should handle WITH statements" do
284
- @db.create_table!(:test){Integer :x; Integer :y}
285
- @db[:testx].with(:testx, @db[:test]).import([:x, :y], [[1, 2], [3, 4], [5, 6]], :slice => 2)
286
- @ds.select_order_map([:x, :y]).must_equal [[1, 2], [3, 4], [5, 6]]
287
- end
288
- end
289
-
290
- describe "MSSQL joined datasets" do
291
- before do
292
- @db = DB
293
- @db.create_table!(:a){Integer :v}
294
- @db[:a].insert(:v=>1)
295
- end
296
- after do
297
- @db.drop_table?(:a)
298
- end
299
-
300
- it "should handle DELETE statements" do
301
- @db[:a].inner_join(Sequel[:a].as(:b), :v=>:v).delete.must_equal 1
302
- @db[:a].empty?.must_equal true
303
- end
304
-
305
- it "should handle UPDATE statements" do
306
- @db[:a].inner_join(Sequel[:a].as(:b), :v=>:v).update(:v=>2).must_equal 1
307
- @db[:a].all.must_equal [{:v=>2}]
308
- end
309
- end
310
-
311
- describe "Offset support" do
312
- before do
313
- @db = DB
314
- @db.create_table!(:i){Integer :id; Integer :parent_id}
315
- @ds = @db[:i].order(:id)
316
- @hs = []
317
- @ds = @ds.with_row_proc(proc{|r| @hs << r.dup; r[:id] *= 2; r[:parent_id] *= 3; r})
318
- @ds.import [:id, :parent_id], [[1,nil],[2,nil],[3,1],[4,1],[5,3],[6,5]]
319
- end
320
- after do
321
- @db.drop_table?(:i)
322
- end
323
-
324
- it "should return correct rows" do
325
- @ds.limit(2, 2).all.must_equal [{:id=>6, :parent_id=>3}, {:id=>8, :parent_id=>3}]
326
- end
327
-
328
- it "should not include offset column in hashes passed to row_proc" do
329
- @ds.limit(2, 2).all
330
- @hs.must_equal [{:id=>3, :parent_id=>1}, {:id=>4, :parent_id=>1}]
331
- end
332
- end
333
-
334
- describe "Update/Delete on limited datasets" do
335
- before do
336
- @db = DB
337
- @db.create_table!(:i){Integer :id}
338
- @ds = @db[:i]
339
- @ds.import [:id], [[1], [2]]
340
- end
341
- after do
342
- @db.drop_table?(:i)
343
- end
344
-
345
- it "should handle deletes and updates on limited datasets" do
346
- @ds.limit(1).update(:id=>Sequel[:id]+10)
347
- [[2, 11], [1, 12]].must_include @ds.select_order_map(:id)
348
- @ds.limit(1).delete
349
- [[1], [2]].must_include @ds.select_order_map(:id)
350
- end
351
-
352
- it "should raise error for updates on ordered, limited datasets" do
353
- end
354
-
355
- it "should raise error for updates and deletes on datasets with offsets or limits with orders" do
356
- proc{@ds.offset(1).delete}.must_raise Sequel::InvalidOperation
357
- proc{@ds.offset(1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
358
- proc{@ds.limit(1, 1).delete}.must_raise Sequel::InvalidOperation
359
- proc{@ds.limit(1, 1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
360
- proc{@ds.order(:id).limit(1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
361
- proc{@ds.order(:id).limit(1).delete}.must_raise Sequel::InvalidOperation
362
- end
363
- end if DB.dataset.send(:is_2012_or_later?)
364
-
365
- describe "Common Table Expressions" do
366
- before do
367
- @db = DB
368
- @db.create_table!(:i1){Integer :id; Integer :parent_id}
369
- @db.create_table!(:i2){Integer :id; Integer :parent_id}
370
- @ds = @db[:i1]
371
- @ds2 = @db[:i2]
372
- @ds.import [:id, :parent_id], [[1,nil],[2,nil],[3,1],[4,1],[5,3],[6,5]]
373
- end
374
- after do
375
- @db.drop_table?(:i1, :i2)
376
- end
377
-
378
- it "using #with should be able to update" do
379
- @ds.insert(:id=>1)
380
- @ds2.insert(:id=>2, :parent_id=>1)
381
- @ds2.insert(:id=>3, :parent_id=>2)
382
- @ds.with(:t, @ds2).filter(:id => @db[:t].select(:id)).update(:parent_id => @db[:t].filter(:id => Sequel[:i1][:id]).select(:parent_id).limit(1))
383
- @ds[:id => 1].must_equal(:id => 1, :parent_id => nil)
384
- @ds[:id => 2].must_equal(:id => 2, :parent_id => 1)
385
- @ds[:id => 3].must_equal(:id => 3, :parent_id => 2)
386
- @ds[:id => 4].must_equal(:id => 4, :parent_id => 1)
387
- end
388
-
389
- it "using #with_recursive should be able to update" do
390
- ds = @ds.with_recursive(:t, @ds.filter(:parent_id=>1).or(:id => 1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
391
- ds.exclude(:id => @db[:t].select(:i)).update(:parent_id => 1)
392
- @ds[:id => 1].must_equal(:id => 1, :parent_id => nil)
393
- @ds[:id => 2].must_equal(:id => 2, :parent_id => 1)
394
- @ds[:id => 5].must_equal(:id => 5, :parent_id => 3)
395
- end
396
-
397
- it "using #with should be able to insert" do
398
- @ds2.insert(:id=>7)
399
- @ds.with(:t, @ds2).insert(@db[:t])
400
- @ds[:id => 7].must_equal(:id => 7, :parent_id => nil)
401
- end
402
-
403
- it "using #with_recursive should be able to insert" do
404
- ds = @ds2.with_recursive(:t, @ds.filter(:parent_id=>1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
405
- ds.insert @db[:t]
406
- @ds2.all.must_equal [{:id => 3, :parent_id => 1}, {:id => 4, :parent_id => 1}, {:id => 5, :parent_id => 3}, {:id => 6, :parent_id => 5}]
407
- end
408
-
409
- it "using #with should be able to delete" do
410
- @ds2.insert(:id=>6)
411
- @ds2.insert(:id=>5)
412
- @ds2.insert(:id=>4)
413
- @ds.with(:t, @ds2).filter(:id => @db[:t].select(:id)).delete
414
- @ds.all.must_equal [{:id => 1, :parent_id => nil}, {:id => 2, :parent_id => nil}, {:id => 3, :parent_id => 1}]
415
- end
416
-
417
- it "using #with_recursive should be able to delete" do
418
- @ds.insert(:id=>7, :parent_id=>2)
419
- ds = @ds.with_recursive(:t, @ds.filter(:parent_id=>1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
420
- ds.filter(Sequel[:i1][:id] => @db[:t].select(:i)).delete
421
- @ds.all.must_equal [{:id => 1, :parent_id => nil}, {:id => 2, :parent_id => nil}, {:id => 7, :parent_id => 2}]
422
- end
423
-
424
- it "using #with should be able to import" do
425
- @ds2.insert(:id=>7)
426
- @ds.with(:t, @ds2).import [:id, :parent_id], @db[:t].select(:id, :parent_id)
427
- @ds[:id => 7].must_equal(:id => 7, :parent_id => nil)
428
- end
429
-
430
- it "using #with_recursive should be able to import" do
431
- ds = @ds2.with_recursive(:t, @ds.filter(:parent_id=>1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
432
- ds.import [:id, :parent_id], @db[:t].select(:i, :pi)
433
- @ds2.all.must_equal [{:id => 3, :parent_id => 1}, {:id => 4, :parent_id => 1}, {:id => 5, :parent_id => 3}, {:id => 6, :parent_id => 5}]
434
- end
435
- end
436
-
437
- describe "MSSSQL::Dataset#insert" do
438
- before do
439
- @db = DB
440
- @db.create_table!(:test5){primary_key :xid; Integer :value}
441
- @db.create_table! :test4 do
442
- String :name, :size => 20
443
- column :value, 'varbinary(max)'
444
- end
445
- @ds = @db[:test5]
446
- end
447
- after do
448
- @db.drop_table?(:test5, :test4)
449
- end
450
-
451
- it "should have insert_select return nil if disable_insert_output is used" do
452
- @ds.disable_insert_output.insert_select(:value=>10).must_be_nil
453
- end
454
-
455
- it "should have insert_select return nil if the server version is not 2005+" do
456
- @ds = @ds.with_extend do
457
- def server_version() 8000760 end
458
- end
459
- @ds.insert_select(:value=>10).must_be_nil
460
- end
461
-
462
- it "should have insert_select insert the record and return the inserted record" do
463
- h = @ds.insert_select(:value=>10)
464
- h[:value].must_equal 10
465
- @ds.first(:xid=>h[:xid])[:value].must_equal 10
466
- end
467
-
468
- cspecify "should allow large text and binary values", [:odbc] do
469
- blob = Sequel::SQL::Blob.new("0" * (65*1024))
470
- @db[:test4].insert(:name => 'max varbinary test', :value => blob)
471
- b = @db[:test4].where(:name => 'max varbinary test').get(:value)
472
- b.length.must_equal blob.length
473
- b.must_equal blob
474
- end
475
-
476
- it "should play nicely with simple_select_all?" do
477
- DB[:test4].disable_insert_output.send(:simple_select_all?).must_equal true
478
- end
479
- end
480
-
481
- describe "MSSSQL::Dataset#into" do
482
- before do
483
- @db = DB
484
- @db.drop_table?(:t, :new)
485
- end
486
- after do
487
- @db.drop_table?(:t, :new)
488
- end
489
-
490
- it "should select rows into a new table" do
491
- @db.create_table!(:t) {Integer :id; String :value}
492
- @db[:t].insert(:id => 1, :value => "test")
493
- @db[:t].into(:new).with_sql(:select_sql).insert
494
- @db[:new].all.must_equal [{:id => 1, :value => "test"}]
495
- end
496
- end
497
-
498
- describe "A MSSQL database" do
499
- before do
500
- @db = DB
501
- end
502
- after do
503
- @db.drop_table?(:a)
504
- end
505
-
506
- it "should handle many existing types for set_column_allow_null" do
507
- @db.create_table!(:a){column :a, 'integer'}
508
- @db.alter_table(:a){set_column_allow_null :a, false}
509
- @db.create_table!(:a){column :a, 'decimal(24, 2)'}
510
- @db.alter_table(:a){set_column_allow_null :a, false}
511
- @db.schema(:a).first.last[:column_size].must_equal 24
512
- @db.schema(:a).first.last[:scale].must_equal 2
513
- @db.create_table!(:a){column :a, 'decimal(10)'}
514
- @db.schema(:a).first.last[:column_size].must_equal 10
515
- @db.schema(:a).first.last[:scale].must_equal 0
516
- @db.alter_table(:a){set_column_allow_null :a, false}
517
- @db.create_table!(:a){column :a, 'nchar(2)'}
518
- @db.alter_table(:a){set_column_allow_null :a, false}
519
- s = @db.schema(:a).first.last
520
- (s[:max_chars] || s[:column_size]).must_equal 2
521
- end
522
- end
523
-
524
- describe "MSSQL::Database#rename_table" do
525
- it "should work on non-schema bound tables which need escaping" do
526
- DB.create_table! :'foo bar' do
527
- text :name
528
- end
529
- DB.rename_table 'foo bar', 'foo'
530
- DB.drop_table :foo
531
- end
532
-
533
- it "should work on schema bound tables within the same schema" do
534
- DB.execute(<<-SQL)
535
- IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'MY')
536
- EXECUTE sp_executesql N'create schema MY'
537
- SQL
538
- DB.create_table! Sequel[:MY][:foo] do
539
- text :name
540
- end
541
- DB.rename_table Sequel[:MY][:foo], Sequel[:MY][:bar]
542
- DB.rename_table Sequel[:MY][:bar], :foo
543
- DB.drop_table Sequel[:MY][:foo]
544
- end
545
- end
546
-
547
- describe "MSSQL::Dataset#count" do
548
- it "should work with a distinct query with an order clause" do
549
- DB.create_table!(:items){String :name; Integer :value}
550
- DB[:items].insert(:name => "name", :value => 1)
551
- DB[:items].insert(:name => "name", :value => 1)
552
- DB[:items].select(:name, :value).distinct.order(:name).count.must_equal 1
553
- DB[:items].select(:name, :value).group(:name, :value).order(:name).count.must_equal 1
554
- end
555
- end
556
-
557
- describe "MSSQL::Database#create_table" do
558
- it "should support collate with various other column options" do
559
- DB.create_table!(:items){ String :name, :size => 128, :collate => :sql_latin1_general_cp1_ci_as, :default => 'foo', :null => false, :unique => true}
560
- DB[:items].insert
561
- DB[:items].select_map(:name).must_equal ["foo"]
562
- end
563
- end
564
-
565
- describe "MSSQL::Database#mssql_unicode_strings = false" do
566
- before do
567
- DB.mssql_unicode_strings = false
568
- end
569
- after do
570
- DB.drop_table?(:items)
571
- DB.mssql_unicode_strings = true
572
- end
573
-
574
- it "should work correctly" do
575
- DB.create_table!(:items){String :name}
576
- DB[:items].mssql_unicode_strings.must_equal false
577
- DB[:items].insert(:name=>'foo')
578
- DB[:items].select_map(:name).must_equal ['foo']
579
- end
580
-
581
- it "should be overridable at the dataset level" do
582
- DB.create_table!(:items){String :name}
583
- ds = DB[:items]
584
- ds.mssql_unicode_strings.must_equal false
585
- ds1 = ds.with_mssql_unicode_strings(true)
586
- ds.mssql_unicode_strings.must_equal false
587
- ds1.mssql_unicode_strings.must_equal true
588
- ds1.insert(:name=>'foo')
589
- ds1.select_map(:name).must_equal ['foo']
590
- end
591
- end
592
-
593
- describe "A MSSQL database adds index with include" do
594
- before :all do
595
- @table_name = :test_index_include
596
- @db = DB
597
- @db.create_table! @table_name do
598
- integer :col1
599
- integer :col2
600
- integer :col3
601
- end
602
- end
603
-
604
- after :all do
605
- @db.drop_table? @table_name
606
- end
607
-
608
- it "should be able add index with include" do
609
- @db.alter_table @table_name do
610
- add_index [:col1], :include => [:col2,:col3]
611
- end
612
- @db.indexes(@table_name).keys.must_include(:"#{@table_name}_col1_index")
613
- end
614
- end
615
-
616
- describe "MSSQL set_column_allow_null" do
617
- before do
618
- @db = DB
619
- end
620
- after do
621
- @db.drop_table?(:test3)
622
- end
623
-
624
- it "should work with nvarchar(MAX) columns" do
625
- @db.create_table!(:test3) do
626
- column :t, 'nvarchar(MAX)'
627
- end
628
- @db.alter_table(:test3) do
629
- set_column_not_null :t
630
- end
631
- end
632
-
633
- it "should work with text columns" do
634
- @db.create_table!(:test3) do
635
- column :t, 'text'
636
- end
637
- @db.alter_table(:test3) do
638
- set_column_not_null :t
639
- end
640
- end
641
- end
642
-
643
- describe "MSSQL::Database#drop_column with a schema" do
644
- before do
645
- DB.run "create schema test" rescue nil
646
- end
647
- after do
648
- DB.drop_table(Sequel[:test][:items])
649
- DB.run "drop schema test" rescue nil
650
- end
651
-
652
- it "drops columns with a default value" do
653
- DB.create_table!(Sequel[:test][:items]){ Integer :id; String :name, :default => 'widget' }
654
- DB.drop_column(Sequel[:test][:items], :name)
655
- DB[Sequel[:test][:items]].columns.must_equal [:id]
656
- end
657
- end
658
-
659
- describe "Database#foreign_key_list" do
660
- before(:all) do
661
- DB.create_table! :items do
662
- primary_key :id
663
- Integer :sku
664
- end
665
- DB.create_table! :prices do
666
- Integer :item_id
667
- datetime :valid_from
668
- float :price
669
- primary_key [:item_id, :valid_from]
670
- foreign_key [:item_id], :items, :key => :id, :name => :fk_prices_items
671
- end
672
- DB.create_table! :sales do
673
- Integer :id
674
- Integer :price_item_id
675
- datetime :price_valid_from
676
- foreign_key [:price_item_id, :price_valid_from], :prices, :key => [:item_id, :valid_from], :name => :fk_sales_prices, :on_delete => :cascade
677
- end
678
- end
679
- after(:all) do
680
- DB.drop_table :sales
681
- DB.drop_table :prices
682
- DB.drop_table :items
683
- end
684
- it "should support typical foreign keys" do
685
- DB.foreign_key_list(:prices).must_equal [{:name => :fk_prices_items,
686
- :table => :items,
687
- :columns => [:item_id],
688
- :key => [:id],
689
- :on_update => :no_action,
690
- :on_delete => :no_action }]
691
- end
692
- it "should support a foreign key with multiple columns" do
693
- DB.foreign_key_list(:sales).must_equal [{:name => :fk_sales_prices,
694
- :table => :prices,
695
- :columns => [:price_item_id, :price_valid_from],
696
- :key => [:item_id, :valid_from],
697
- :on_update => :no_action,
698
- :on_delete => :cascade }]
699
- end
700
-
701
- describe "with multiple schemas" do
702
- before(:all) do
703
- DB.execute_ddl "create schema vendor"
704
- DB.create_table! Sequel[:vendor][:vendors] do
705
- primary_key :id
706
- varchar :name
707
- end
708
- DB.create_table! Sequel[:vendor][:mapping] do
709
- Integer :vendor_id
710
- Integer :item_id
711
- foreign_key [:vendor_id], Sequel[:vendor][:vendors], :name => :fk_mapping_vendor
712
- foreign_key [:item_id], :items, :name => :fk_mapping_item
713
- end
714
- end
715
- after(:all) do
716
- DB.drop_table? Sequel[:vendor][:mapping]
717
- DB.drop_table? Sequel[:vendor][:vendors]
718
- DB.execute_ddl "drop schema vendor"
719
- end
720
- it "should support mixed schema bound tables" do
721
- DB.foreign_key_list(Sequel[:vendor][:mapping]).sort_by{|h| h[:name].to_s}.must_equal [{:name => :fk_mapping_item, :table => :items, :columns => [:item_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }, {:name => :fk_mapping_vendor, :table => Sequel.qualify(:vendor, :vendors), :columns => [:vendor_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }]
722
- end
723
- end
724
- end
725
-
726
- describe "MSSQL optimistic locking plugin" do
727
- before do
728
- @db = DB
729
- @db.create_table! :items do
730
- primary_key :id
731
- String :name, :size => 20
732
- column :timestamp, 'timestamp'
733
- end
734
- end
735
- after do
736
- @db.drop_table?(:items)
737
- end
738
-
739
- it "should not allow stale updates" do
740
- c = Class.new(Sequel::Model(:items))
741
- c.plugin :mssql_optimistic_locking
742
- o = c.create(:name=>'test')
743
- o2 = c.first
744
- ts = o.timestamp
745
- ts.wont_equal nil
746
- o.name = 'test2'
747
- o.save
748
- o.timestamp.wont_equal ts
749
- proc{o2.save}.must_raise(Sequel::NoExistingObject)
750
- end
751
- end unless DB.adapter_scheme == :odbc
752
-
753
- describe "MSSQL Stored Procedure support" do
754
- before do
755
- @db = DB
756
- @now = DateTime.now.to_s
757
- @db.execute('CREATE PROCEDURE dbo.SequelTest
758
- (@Input varchar(25), @IntegerInput int, @Output varchar(25) OUTPUT, @IntegerOutput int OUTPUT) AS
759
- BEGIN SET @Output = @Input SET @IntegerOutput = @IntegerInput RETURN @IntegerInput END')
760
- end
761
- after do
762
- @db.execute('DROP PROCEDURE dbo.SequelTest')
763
- end
764
-
765
- describe "with unnamed parameters" do
766
- it "should return a hash of output variables" do
767
- r = @db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, :output]})
768
- r.must_be_kind_of(Hash)
769
- r.values_at(:var2, :var3).must_equal [@now, '1']
770
- end
771
-
772
- it "should support typed output variables" do
773
- @db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, [:output, 'int']]})[:var3].must_equal 1
774
- end
775
-
776
- it "should support named output variables" do
777
- @db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, [:output, nil, 'output'], :output]})[:output].must_equal @now
778
- end
779
-
780
- it "should return the number of Affected Rows" do
781
- @db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, :output]})[:numrows].must_equal 1
782
- end
783
-
784
- it "should return the Result Code" do
785
- @db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, :output]})[:result].must_equal 1
786
- end
787
- end
788
-
789
- describe "with named parameters" do
790
- it "should return a hash of output variables" do
791
- r = @db.call_mssql_sproc(:SequelTest, :args => {
792
- 'Input' => @now,
793
- 'IntegerInput' => 1,
794
- 'Output' => [:output, nil, 'output'],
795
- 'IntegerOutput' => [:output, nil, 'integer_output']
796
- })
797
- r.must_be_kind_of(Hash)
798
- r.values_at(:output, :integer_output).must_equal [@now, '1']
799
- end
800
-
801
- it "should support typed output variables" do
802
- @db.call_mssql_sproc(:SequelTest, :args => {
803
- 'Input' => @now,
804
- 'IntegerInput' => 1,
805
- 'Output' => [:output, nil, 'output'],
806
- 'IntegerOutput' => [:output, 'int', 'integer_output']
807
- })[:integer_output].must_equal 1
808
- end
809
-
810
- it "should return the number of Affected Rows" do
811
- @db.call_mssql_sproc(:SequelTest, :args => {
812
- 'Input' => @now,
813
- 'IntegerInput' => 1,
814
- 'Output' => [:output, nil, 'output'],
815
- 'IntegerOutput' => [:output, nil, 'integer_output']
816
- })[:numrows].must_equal 1
817
- end
818
-
819
- it "should return the Result Code" do
820
- @db.call_mssql_sproc(:SequelTest, :args => {
821
- 'Input' => @now,
822
- 'IntegerInput' => 1,
823
- 'Output' => [:output, nil, 'output'],
824
- 'IntegerOutput' => [:output, nil, 'integer_output']
825
- })[:result].must_equal 1
826
- end
827
- end
828
- end unless DB.adapter_scheme == :odbc