sequel 3.48.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +114 -0
  3. data/Rakefile +10 -7
  4. data/doc/association_basics.rdoc +25 -23
  5. data/doc/code_order.rdoc +7 -0
  6. data/doc/core_extensions.rdoc +0 -10
  7. data/doc/object_model.rdoc +4 -1
  8. data/doc/querying.rdoc +3 -3
  9. data/doc/release_notes/4.0.0.txt +262 -0
  10. data/doc/security.rdoc +0 -28
  11. data/doc/testing.rdoc +8 -14
  12. data/lib/sequel/adapters/ado.rb +7 -11
  13. data/lib/sequel/adapters/ado/access.rb +8 -8
  14. data/lib/sequel/adapters/ado/mssql.rb +4 -4
  15. data/lib/sequel/adapters/amalgalite.rb +6 -6
  16. data/lib/sequel/adapters/cubrid.rb +7 -7
  17. data/lib/sequel/adapters/db2.rb +5 -9
  18. data/lib/sequel/adapters/dbi.rb +2 -6
  19. data/lib/sequel/adapters/do.rb +4 -4
  20. data/lib/sequel/adapters/firebird.rb +4 -4
  21. data/lib/sequel/adapters/ibmdb.rb +8 -8
  22. data/lib/sequel/adapters/informix.rb +2 -10
  23. data/lib/sequel/adapters/jdbc.rb +17 -17
  24. data/lib/sequel/adapters/jdbc/as400.rb +2 -2
  25. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
  26. data/lib/sequel/adapters/jdbc/db2.rb +1 -1
  27. data/lib/sequel/adapters/jdbc/derby.rb +1 -1
  28. data/lib/sequel/adapters/jdbc/h2.rb +2 -2
  29. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  30. data/lib/sequel/adapters/jdbc/informix.rb +1 -1
  31. data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
  32. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  33. data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
  34. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
  35. data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
  36. data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
  37. data/lib/sequel/adapters/mock.rb +7 -7
  38. data/lib/sequel/adapters/mysql.rb +3 -3
  39. data/lib/sequel/adapters/mysql2.rb +4 -4
  40. data/lib/sequel/adapters/odbc.rb +2 -6
  41. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  42. data/lib/sequel/adapters/openbase.rb +1 -5
  43. data/lib/sequel/adapters/oracle.rb +13 -17
  44. data/lib/sequel/adapters/postgres.rb +20 -25
  45. data/lib/sequel/adapters/shared/cubrid.rb +3 -3
  46. data/lib/sequel/adapters/shared/db2.rb +2 -2
  47. data/lib/sequel/adapters/shared/firebird.rb +7 -7
  48. data/lib/sequel/adapters/shared/mssql.rb +9 -9
  49. data/lib/sequel/adapters/shared/mysql.rb +29 -13
  50. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
  51. data/lib/sequel/adapters/shared/oracle.rb +22 -13
  52. data/lib/sequel/adapters/shared/postgres.rb +61 -46
  53. data/lib/sequel/adapters/shared/sqlite.rb +9 -9
  54. data/lib/sequel/adapters/sqlite.rb +17 -11
  55. data/lib/sequel/adapters/swift.rb +3 -3
  56. data/lib/sequel/adapters/swift/mysql.rb +1 -1
  57. data/lib/sequel/adapters/swift/sqlite.rb +1 -1
  58. data/lib/sequel/adapters/tinytds.rb +8 -8
  59. data/lib/sequel/ast_transformer.rb +3 -1
  60. data/lib/sequel/connection_pool.rb +4 -2
  61. data/lib/sequel/connection_pool/sharded_single.rb +2 -2
  62. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
  63. data/lib/sequel/connection_pool/threaded.rb +7 -7
  64. data/lib/sequel/core.rb +4 -67
  65. data/lib/sequel/database.rb +1 -0
  66. data/lib/sequel/database/connecting.rb +2 -8
  67. data/lib/sequel/database/dataset.rb +2 -7
  68. data/lib/sequel/database/dataset_defaults.rb +0 -18
  69. data/lib/sequel/database/features.rb +4 -4
  70. data/lib/sequel/database/misc.rb +6 -8
  71. data/lib/sequel/database/query.rb +5 -61
  72. data/lib/sequel/database/schema_generator.rb +22 -20
  73. data/lib/sequel/database/schema_methods.rb +48 -20
  74. data/lib/sequel/database/transactions.rb +7 -17
  75. data/lib/sequel/dataset.rb +2 -0
  76. data/lib/sequel/dataset/actions.rb +23 -91
  77. data/lib/sequel/dataset/features.rb +1 -4
  78. data/lib/sequel/dataset/graph.rb +3 -47
  79. data/lib/sequel/dataset/misc.rb +4 -33
  80. data/lib/sequel/dataset/prepared_statements.rb +3 -1
  81. data/lib/sequel/dataset/query.rb +116 -240
  82. data/lib/sequel/dataset/sql.rb +19 -97
  83. data/lib/sequel/deprecated.rb +0 -16
  84. data/lib/sequel/exceptions.rb +0 -3
  85. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  86. data/lib/sequel/extensions/columns_introspection.rb +1 -12
  87. data/lib/sequel/extensions/constraint_validations.rb +3 -3
  88. data/lib/sequel/extensions/core_extensions.rb +0 -9
  89. data/lib/sequel/extensions/date_arithmetic.rb +1 -2
  90. data/lib/sequel/extensions/graph_each.rb +11 -0
  91. data/lib/sequel/extensions/migration.rb +5 -5
  92. data/lib/sequel/extensions/null_dataset.rb +11 -13
  93. data/lib/sequel/extensions/pagination.rb +3 -6
  94. data/lib/sequel/extensions/pg_array.rb +6 -4
  95. data/lib/sequel/extensions/pg_array_ops.rb +35 -1
  96. data/lib/sequel/extensions/pg_json.rb +12 -2
  97. data/lib/sequel/extensions/pg_json_ops.rb +266 -0
  98. data/lib/sequel/extensions/pg_range.rb +2 -2
  99. data/lib/sequel/extensions/pg_range_ops.rb +0 -8
  100. data/lib/sequel/extensions/pg_row.rb +2 -2
  101. data/lib/sequel/extensions/pretty_table.rb +0 -4
  102. data/lib/sequel/extensions/query.rb +3 -8
  103. data/lib/sequel/extensions/schema_caching.rb +0 -7
  104. data/lib/sequel/extensions/schema_dumper.rb +10 -17
  105. data/lib/sequel/extensions/select_remove.rb +0 -4
  106. data/lib/sequel/extensions/set_overrides.rb +28 -0
  107. data/lib/sequel/extensions/to_dot.rb +6 -10
  108. data/lib/sequel/model.rb +6 -7
  109. data/lib/sequel/model/associations.rb +127 -182
  110. data/lib/sequel/model/base.rb +88 -211
  111. data/lib/sequel/model/errors.rb +0 -13
  112. data/lib/sequel/model/plugins.rb +2 -2
  113. data/lib/sequel/no_core_ext.rb +0 -1
  114. data/lib/sequel/plugins/after_initialize.rb +11 -17
  115. data/lib/sequel/plugins/association_autoreloading.rb +1 -47
  116. data/lib/sequel/plugins/association_dependencies.rb +2 -2
  117. data/lib/sequel/plugins/auto_validations.rb +2 -8
  118. data/lib/sequel/plugins/blacklist_security.rb +32 -2
  119. data/lib/sequel/plugins/caching.rb +1 -1
  120. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  121. data/lib/sequel/plugins/composition.rb +10 -8
  122. data/lib/sequel/plugins/constraint_validations.rb +2 -2
  123. data/lib/sequel/plugins/dataset_associations.rb +4 -0
  124. data/lib/sequel/plugins/defaults_setter.rb +8 -6
  125. data/lib/sequel/plugins/dirty.rb +6 -6
  126. data/lib/sequel/plugins/force_encoding.rb +13 -8
  127. data/lib/sequel/plugins/hook_class_methods.rb +1 -7
  128. data/lib/sequel/plugins/json_serializer.rb +13 -74
  129. data/lib/sequel/plugins/lazy_attributes.rb +2 -4
  130. data/lib/sequel/plugins/list.rb +1 -1
  131. data/lib/sequel/plugins/many_through_many.rb +4 -11
  132. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
  133. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  134. data/lib/sequel/plugins/optimistic_locking.rb +3 -5
  135. data/lib/sequel/plugins/pg_array_associations.rb +453 -0
  136. data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
  137. data/lib/sequel/plugins/prepared_statements.rb +1 -1
  138. data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
  139. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
  140. data/lib/sequel/plugins/rcte_tree.rb +1 -1
  141. data/lib/sequel/plugins/serialization.rb +5 -4
  142. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  143. data/lib/sequel/plugins/sharding.rb +7 -1
  144. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  145. data/lib/sequel/plugins/timestamps.rb +1 -1
  146. data/lib/sequel/plugins/touch.rb +2 -2
  147. data/lib/sequel/plugins/tree.rb +1 -1
  148. data/lib/sequel/plugins/typecast_on_load.rb +19 -4
  149. data/lib/sequel/plugins/validation_class_methods.rb +0 -30
  150. data/lib/sequel/plugins/validation_helpers.rb +13 -31
  151. data/lib/sequel/plugins/xml_serializer.rb +18 -57
  152. data/lib/sequel/sql.rb +20 -22
  153. data/lib/sequel/version.rb +2 -2
  154. data/spec/adapters/db2_spec.rb +14 -23
  155. data/spec/adapters/firebird_spec.rb +25 -29
  156. data/spec/adapters/informix_spec.rb +11 -14
  157. data/spec/adapters/mssql_spec.rb +71 -77
  158. data/spec/adapters/mysql_spec.rb +165 -172
  159. data/spec/adapters/oracle_spec.rb +36 -39
  160. data/spec/adapters/postgres_spec.rb +175 -100
  161. data/spec/adapters/spec_helper.rb +13 -11
  162. data/spec/adapters/sqlite_spec.rb +36 -44
  163. data/spec/core/connection_pool_spec.rb +2 -1
  164. data/spec/core/database_spec.rb +55 -55
  165. data/spec/core/dataset_spec.rb +45 -249
  166. data/spec/core/deprecated_spec.rb +0 -8
  167. data/spec/core/expression_filters_spec.rb +23 -5
  168. data/spec/core/object_graph_spec.rb +4 -66
  169. data/spec/core/schema_spec.rb +35 -12
  170. data/spec/core/spec_helper.rb +3 -2
  171. data/spec/core_extensions_spec.rb +17 -19
  172. data/spec/extensions/arbitrary_servers_spec.rb +2 -3
  173. data/spec/extensions/association_dependencies_spec.rb +14 -14
  174. data/spec/extensions/auto_validations_spec.rb +7 -0
  175. data/spec/extensions/blacklist_security_spec.rb +5 -5
  176. data/spec/extensions/blank_spec.rb +2 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +2 -2
  178. data/spec/extensions/columns_introspection_spec.rb +2 -29
  179. data/spec/extensions/composition_spec.rb +10 -17
  180. data/spec/extensions/core_refinements_spec.rb +5 -1
  181. data/spec/extensions/dataset_associations_spec.rb +18 -0
  182. data/spec/extensions/date_arithmetic_spec.rb +2 -2
  183. data/spec/extensions/defaults_setter_spec.rb +9 -9
  184. data/spec/extensions/dirty_spec.rb +0 -5
  185. data/spec/extensions/eval_inspect_spec.rb +2 -0
  186. data/spec/extensions/force_encoding_spec.rb +2 -18
  187. data/spec/extensions/hash_aliases_spec.rb +8 -0
  188. data/spec/extensions/hook_class_methods_spec.rb +39 -58
  189. data/spec/extensions/inflector_spec.rb +2 -0
  190. data/spec/extensions/instance_filters_spec.rb +8 -8
  191. data/spec/extensions/json_serializer_spec.rb +1 -41
  192. data/spec/extensions/list_spec.rb +1 -1
  193. data/spec/extensions/many_through_many_spec.rb +106 -109
  194. data/spec/extensions/migration_spec.rb +2 -0
  195. data/spec/extensions/named_timezones_spec.rb +1 -0
  196. data/spec/extensions/pg_array_associations_spec.rb +603 -0
  197. data/spec/extensions/pg_array_ops_spec.rb +25 -0
  198. data/spec/extensions/pg_array_spec.rb +9 -1
  199. data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
  200. data/spec/extensions/pg_hstore_spec.rb +1 -0
  201. data/spec/extensions/pg_json_ops_spec.rb +131 -0
  202. data/spec/extensions/pg_json_spec.rb +10 -4
  203. data/spec/extensions/pg_range_ops_spec.rb +2 -5
  204. data/spec/extensions/pg_range_spec.rb +6 -2
  205. data/spec/extensions/pg_row_ops_spec.rb +2 -0
  206. data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
  207. data/spec/extensions/rcte_tree_spec.rb +15 -15
  208. data/spec/extensions/schema_dumper_spec.rb +0 -1
  209. data/spec/extensions/schema_spec.rb +9 -9
  210. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  211. data/spec/extensions/serialization_spec.rb +18 -29
  212. data/spec/extensions/set_overrides_spec.rb +4 -0
  213. data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
  214. data/spec/extensions/single_table_inheritance_spec.rb +4 -4
  215. data/spec/extensions/spec_helper.rb +8 -9
  216. data/spec/extensions/sql_expr_spec.rb +2 -0
  217. data/spec/extensions/string_date_time_spec.rb +2 -0
  218. data/spec/extensions/string_stripper_spec.rb +2 -0
  219. data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
  220. data/spec/extensions/thread_local_timezones_spec.rb +2 -0
  221. data/spec/extensions/timestamps_spec.rb +1 -1
  222. data/spec/extensions/to_dot_spec.rb +1 -1
  223. data/spec/extensions/touch_spec.rb +24 -24
  224. data/spec/extensions/tree_spec.rb +7 -7
  225. data/spec/extensions/typecast_on_load_spec.rb +8 -1
  226. data/spec/extensions/update_primary_key_spec.rb +10 -10
  227. data/spec/extensions/validation_class_methods_spec.rb +10 -39
  228. data/spec/extensions/validation_helpers_spec.rb +29 -47
  229. data/spec/extensions/xml_serializer_spec.rb +1 -23
  230. data/spec/integration/associations_test.rb +231 -40
  231. data/spec/integration/database_test.rb +1 -1
  232. data/spec/integration/dataset_test.rb +64 -64
  233. data/spec/integration/eager_loader_test.rb +28 -28
  234. data/spec/integration/migrator_test.rb +1 -1
  235. data/spec/integration/model_test.rb +2 -2
  236. data/spec/integration/plugin_test.rb +21 -21
  237. data/spec/integration/prepared_statement_test.rb +7 -7
  238. data/spec/integration/schema_test.rb +115 -110
  239. data/spec/integration/spec_helper.rb +17 -27
  240. data/spec/integration/timezone_test.rb +1 -1
  241. data/spec/integration/transaction_test.rb +10 -10
  242. data/spec/integration/type_test.rb +2 -2
  243. data/spec/model/association_reflection_spec.rb +2 -28
  244. data/spec/model/associations_spec.rb +239 -188
  245. data/spec/model/base_spec.rb +27 -68
  246. data/spec/model/dataset_methods_spec.rb +4 -4
  247. data/spec/model/eager_loading_spec.rb +160 -172
  248. data/spec/model/hooks_spec.rb +62 -79
  249. data/spec/model/model_spec.rb +36 -51
  250. data/spec/model/plugins_spec.rb +5 -19
  251. data/spec/model/record_spec.rb +125 -151
  252. data/spec/model/spec_helper.rb +8 -6
  253. data/spec/model/validations_spec.rb +4 -17
  254. data/spec/spec_config.rb +2 -10
  255. metadata +50 -56
  256. data/lib/sequel/deprecated_core_extensions.rb +0 -135
  257. data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
  258. data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
  259. data/lib/sequel/plugins/identity_map.rb +0 -260
  260. data/lib/sequel_core.rb +0 -2
  261. data/lib/sequel_model.rb +0 -2
  262. data/spec/extensions/association_autoreloading_spec.rb +0 -102
  263. data/spec/extensions/identity_map_spec.rb +0 -337
  264. data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
  265. data/spec/extensions/pg_statement_cache_spec.rb +0 -208
  266. data/spec/rcov.opts +0 -8
  267. data/spec/spec_config.rb.example +0 -10
@@ -1,14 +1,11 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
1
+ SEQUEL_ADAPTER_TEST = :informix
2
2
 
3
- unless defined?(INFORMIX_DB)
4
- INFORMIX_DB = Sequel.connect('informix://localhost/mydb')
5
- end
6
- INTEGRATION_DB = INFORMIX_DB unless defined?(INTEGRATION_DB)
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
7
4
 
8
- if INFORMIX_DB.table_exists?(:test)
9
- INFORMIX_DB.drop_table :test
5
+ if DB.table_exists?(:test)
6
+ DB.drop_table :test
10
7
  end
11
- INFORMIX_DB.create_table :test do
8
+ DB.create_table :test do
12
9
  text :name
13
10
  integer :value
14
11
 
@@ -17,16 +14,16 @@ end
17
14
 
18
15
  describe "A Informix database" do
19
16
  specify "should provide disconnect functionality" do
20
- INFORMIX_DB.execute("select user from dual")
21
- INFORMIX_DB.pool.size.should == 1
22
- INFORMIX_DB.disconnect
23
- INFORMIX_DB.pool.size.should == 0
17
+ DB.execute("select user from dual")
18
+ DB.pool.size.should == 1
19
+ DB.disconnect
20
+ DB.pool.size.should == 0
24
21
  end
25
22
  end
26
23
 
27
24
  describe "A Informix dataset" do
28
25
  before do
29
- @d = INFORMIX_DB[:test]
26
+ @d = DB[:test]
30
27
  @d.delete # remove all records
31
28
  end
32
29
 
@@ -79,7 +76,7 @@ describe "A Informix dataset" do
79
76
  end
80
77
 
81
78
  specify "should support transactions" do
82
- INFORMIX_DB.transaction do
79
+ DB.transaction do
83
80
  @d << {:name => 'abc', :value => 1}
84
81
  end
85
82
 
@@ -1,25 +1,19 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
2
-
3
- require ENV['SEQUEL_MSSQL_SPEC_REQUIRE'] if ENV['SEQUEL_MSSQL_SPEC_REQUIRE']
1
+ SEQUEL_ADAPTER_TEST = :mssql
4
2
 
5
- unless defined?(MSSQL_DB)
6
- MSSQL_URL = 'jdbc:sqlserver://localhost;integratedSecurity=true;database=sandbox' unless defined? MSSQL_URL
7
- MSSQL_DB = Sequel.connect(ENV['SEQUEL_MSSQL_SPEC_DB']||MSSQL_URL)
8
- end
9
- INTEGRATION_DB = MSSQL_DB unless defined?(INTEGRATION_DB)
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
10
4
 
11
- def MSSQL_DB.sqls
5
+ def DB.sqls
12
6
  (@sqls ||= [])
13
7
  end
14
8
  logger = Object.new
15
9
  def logger.method_missing(m, msg)
16
- MSSQL_DB.sqls << msg
10
+ DB.sqls << msg
17
11
  end
18
- MSSQL_DB.loggers = [logger]
12
+ DB.loggers = [logger]
19
13
 
20
14
  describe "A MSSQL database" do
21
15
  before do
22
- @db = MSSQL_DB
16
+ @db = DB
23
17
  end
24
18
 
25
19
  cspecify "should be able to read fractional part of timestamp", :odbc do
@@ -40,7 +34,7 @@ end
40
34
 
41
35
  describe "A MSSQL database" do
42
36
  before do
43
- @db = MSSQL_DB
37
+ @db = DB
44
38
  @db.create_table! :test3 do
45
39
  Integer :value
46
40
  Time :time
@@ -57,7 +51,7 @@ end
57
51
 
58
52
  describe "MSSQL" do
59
53
  before(:all) do
60
- @db = MSSQL_DB
54
+ @db = DB
61
55
  @db.create_table!(:test3){Integer :v3}
62
56
  @db.create_table!(:test4){Integer :v4}
63
57
  @db[:test3].import([:v3], [[1], [2]])
@@ -82,7 +76,7 @@ end
82
76
  # CREATE FULLTEXT CATALOG ftscd AS DEFAULT
83
77
  describe "MSSQL full_text_search" do
84
78
  before do
85
- @db = MSSQL_DB
79
+ @db = DB
86
80
  @db.drop_table?(:posts)
87
81
  end
88
82
  after do
@@ -107,19 +101,19 @@ end if false
107
101
 
108
102
  describe "MSSQL Dataset#join_table" do
109
103
  specify "should emulate the USING clause with ON" do
110
- MSSQL_DB[:items].join(:categories, [:id]).sql.should ==
104
+ DB[:items].join(:categories, [:id]).sql.should ==
111
105
  'SELECT * FROM [ITEMS] INNER JOIN [CATEGORIES] ON ([CATEGORIES].[ID] = [ITEMS].[ID])'
112
106
  ['SELECT * FROM [ITEMS] INNER JOIN [CATEGORIES] ON (([CATEGORIES].[ID1] = [ITEMS].[ID1]) AND ([CATEGORIES].[ID2] = [ITEMS].[ID2]))',
113
107
  'SELECT * FROM [ITEMS] INNER JOIN [CATEGORIES] ON (([CATEGORIES].[ID2] = [ITEMS].[ID2]) AND ([CATEGORIES].[ID1] = [ITEMS].[ID1]))'].
114
- should include(MSSQL_DB[:items].join(:categories, [:id1, :id2]).sql)
115
- MSSQL_DB[:items___i].join(:categories___c, [:id]).sql.should ==
108
+ should include(DB[:items].join(:categories, [:id1, :id2]).sql)
109
+ DB[:items___i].join(:categories___c, [:id]).sql.should ==
116
110
  'SELECT * FROM [ITEMS] AS [I] INNER JOIN [CATEGORIES] AS [C] ON ([C].[ID] = [I].[ID])'
117
111
  end
118
112
  end
119
113
 
120
114
  describe "MSSQL Dataset#output" do
121
115
  before do
122
- @db = MSSQL_DB
116
+ @db = DB
123
117
  @db.create_table!(:items){String :name; Integer :value}
124
118
  @db.create_table!(:out){String :name; Integer :value}
125
119
  @ds = @db[:items]
@@ -197,8 +191,8 @@ end
197
191
 
198
192
  describe "MSSQL dataset using #with and #with_recursive" do
199
193
  before do
200
- @db = MSSQL_DB
201
- @ds = MSSQL_DB[:t]
194
+ @db = DB
195
+ @ds = DB[:t]
202
196
  @ds1 = @ds.with(:t, @db[:x])
203
197
  @ds2 = @ds.with_recursive(:t, @db[:x], @db[:t])
204
198
  end
@@ -226,7 +220,7 @@ end
226
220
 
227
221
  describe "MSSQL::Dataset#import" do
228
222
  before do
229
- @db = MSSQL_DB
223
+ @db = DB
230
224
  @db.sqls.clear
231
225
  @ds = @db[:test]
232
226
  end
@@ -249,7 +243,7 @@ end
249
243
 
250
244
  describe "MSSQL joined datasets" do
251
245
  before do
252
- @db = MSSQL_DB
246
+ @db = DB
253
247
  end
254
248
 
255
249
  specify "should format DELETE statements" do
@@ -265,7 +259,7 @@ end
265
259
 
266
260
  describe "Offset support" do
267
261
  before do
268
- @db = MSSQL_DB
262
+ @db = DB
269
263
  @db.create_table!(:i){Integer :id; Integer :parent_id}
270
264
  @ds = @db[:i].order(:id)
271
265
  @hs = []
@@ -288,7 +282,7 @@ end
288
282
 
289
283
  describe "Common Table Expressions" do
290
284
  before do
291
- @db = MSSQL_DB
285
+ @db = DB
292
286
  @db.create_table!(:i1){Integer :id; Integer :parent_id}
293
287
  @db.create_table!(:i2){Integer :id; Integer :parent_id}
294
288
  @ds = @db[:i1]
@@ -360,7 +354,7 @@ end
360
354
 
361
355
  describe "MSSSQL::Dataset#insert" do
362
356
  before do
363
- @db = MSSQL_DB
357
+ @db = DB
364
358
  @db.create_table!(:test5){primary_key :xid; Integer :value}
365
359
  @db.create_table! :test4 do
366
360
  String :name, :size => 20
@@ -397,13 +391,13 @@ describe "MSSSQL::Dataset#insert" do
397
391
  end
398
392
 
399
393
  specify "should play nicely with simple_select_all?" do
400
- MSSQL_DB[:test4].disable_insert_output.send(:simple_select_all?).should == true
394
+ DB[:test4].disable_insert_output.send(:simple_select_all?).should == true
401
395
  end
402
396
  end
403
397
 
404
398
  describe "MSSSQL::Dataset#into" do
405
399
  before do
406
- @db = MSSQL_DB
400
+ @db = DB
407
401
  end
408
402
 
409
403
  specify "should format SELECT statement" do
@@ -421,7 +415,7 @@ end
421
415
 
422
416
  describe "A MSSQL database" do
423
417
  before do
424
- @db = MSSQL_DB
418
+ @db = DB
425
419
  end
426
420
  after do
427
421
  @db.drop_table?(:a)
@@ -447,68 +441,68 @@ end
447
441
 
448
442
  describe "MSSQL::Database#rename_table" do
449
443
  after do
450
- MSSQL_DB.drop_table?(:foo)
444
+ DB.drop_table?(:foo)
451
445
  end
452
446
 
453
447
  specify "should work on non-schema bound tables which need escaping" do
454
- MSSQL_DB.quote_identifiers = true
455
- MSSQL_DB.create_table! :'foo bar' do
448
+ DB.quote_identifiers = true
449
+ DB.create_table! :'foo bar' do
456
450
  text :name
457
451
  end
458
- MSSQL_DB.drop_table? :foo
459
- proc { MSSQL_DB.rename_table 'foo bar', 'foo' }.should_not raise_error
452
+ DB.drop_table? :foo
453
+ proc { DB.rename_table 'foo bar', 'foo' }.should_not raise_error
460
454
  end
461
455
 
462
456
  specify "should work on schema bound tables" do
463
- MSSQL_DB.execute(<<-SQL)
457
+ DB.execute(<<-SQL)
464
458
  IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'MY')
465
459
  EXECUTE sp_executesql N'create schema MY'
466
460
  SQL
467
- MSSQL_DB.create_table! :MY__foo do
461
+ DB.create_table! :MY__foo do
468
462
  text :name
469
463
  end
470
- proc { MSSQL_DB.rename_table :MY__foo, :MY__bar }.should_not raise_error
471
- proc { MSSQL_DB.rename_table :MY__bar, :foo }.should_not raise_error
464
+ proc { DB.rename_table :MY__foo, :MY__bar }.should_not raise_error
465
+ proc { DB.rename_table :MY__bar, :foo }.should_not raise_error
472
466
  end
473
467
  end
474
468
 
475
469
  describe "MSSQL::Dataset#count" do
476
470
  specify "should work with a distinct query with an order clause" do
477
- MSSQL_DB.create_table!(:items){String :name; Integer :value}
478
- MSSQL_DB[:items].insert(:name => "name", :value => 1)
479
- MSSQL_DB[:items].insert(:name => "name", :value => 1)
480
- MSSQL_DB[:items].select(:name, :value).distinct.order(:name).count.should == 1
481
- MSSQL_DB[:items].select(:name, :value).group(:name, :value).order(:name).count.should == 1
471
+ DB.create_table!(:items){String :name; Integer :value}
472
+ DB[:items].insert(:name => "name", :value => 1)
473
+ DB[:items].insert(:name => "name", :value => 1)
474
+ DB[:items].select(:name, :value).distinct.order(:name).count.should == 1
475
+ DB[:items].select(:name, :value).group(:name, :value).order(:name).count.should == 1
482
476
  end
483
477
  end
484
478
 
485
479
  describe "MSSQL::Database#create_table" do
486
480
  specify "should support collate with various other column options" do
487
- MSSQL_DB.create_table!(:items){ String :name, :size => 128, :collate => :sql_latin1_general_cp1_ci_as, :default => 'foo', :null => false, :unique => true}
488
- MSSQL_DB[:items].insert
489
- MSSQL_DB[:items].select_map(:name).should == ["foo"]
481
+ DB.create_table!(:items){ String :name, :size => 128, :collate => :sql_latin1_general_cp1_ci_as, :default => 'foo', :null => false, :unique => true}
482
+ DB[:items].insert
483
+ DB[:items].select_map(:name).should == ["foo"]
490
484
  end
491
485
  end
492
486
 
493
487
  describe "MSSQL::Database#mssql_unicode_strings = false" do
494
488
  before do
495
- MSSQL_DB.mssql_unicode_strings = false
489
+ DB.mssql_unicode_strings = false
496
490
  end
497
491
  after do
498
- MSSQL_DB.drop_table?(:items)
499
- MSSQL_DB.mssql_unicode_strings = true
492
+ DB.drop_table?(:items)
493
+ DB.mssql_unicode_strings = true
500
494
  end
501
495
 
502
496
  specify "should work correctly" do
503
- MSSQL_DB.create_table!(:items){String :name}
504
- MSSQL_DB[:items].mssql_unicode_strings.should == false
505
- MSSQL_DB[:items].insert(:name=>'foo')
506
- MSSQL_DB[:items].select_map(:name).should == ['foo']
497
+ DB.create_table!(:items){String :name}
498
+ DB[:items].mssql_unicode_strings.should == false
499
+ DB[:items].insert(:name=>'foo')
500
+ DB[:items].select_map(:name).should == ['foo']
507
501
  end
508
502
 
509
503
  specify "should be overridable at the dataset level" do
510
- MSSQL_DB.create_table!(:items){String :name}
511
- ds = MSSQL_DB[:items]
504
+ DB.create_table!(:items){String :name}
505
+ ds = DB[:items]
512
506
  ds.mssql_unicode_strings.should == false
513
507
  ds.mssql_unicode_strings = true
514
508
  ds.mssql_unicode_strings.should == true
@@ -520,7 +514,7 @@ end
520
514
  describe "A MSSQL database adds index with include" do
521
515
  before :all do
522
516
  @table_name = :test_index_include
523
- @db = MSSQL_DB
517
+ @db = DB
524
518
  @db.create_table! @table_name do
525
519
  integer :col1
526
520
  integer :col2
@@ -542,34 +536,34 @@ end
542
536
 
543
537
  describe "MSSQL::Database#drop_column with a schema" do
544
538
  before do
545
- MSSQL_DB.run "create schema test" rescue nil
539
+ DB.run "create schema test" rescue nil
546
540
  end
547
541
  after do
548
- MSSQL_DB.drop_table(:test__items)
549
- MSSQL_DB.run "drop schema test" rescue nil
542
+ DB.drop_table(:test__items)
543
+ DB.run "drop schema test" rescue nil
550
544
  end
551
545
 
552
546
  specify "drops columns with a default value" do
553
- MSSQL_DB.create_table!(:test__items){ Integer :id; String :name, :default => 'widget' }
554
- MSSQL_DB.drop_column(:test__items, :name)
555
- MSSQL_DB[:test__items].columns.should == [:id]
547
+ DB.create_table!(:test__items){ Integer :id; String :name, :default => 'widget' }
548
+ DB.drop_column(:test__items, :name)
549
+ DB[:test__items].columns.should == [:id]
556
550
  end
557
551
  end
558
552
 
559
553
  describe "Database#foreign_key_list" do
560
554
  before(:all) do
561
- MSSQL_DB.create_table! :items do
555
+ DB.create_table! :items do
562
556
  primary_key :id
563
557
  integer :sku
564
558
  end
565
- MSSQL_DB.create_table! :prices do
559
+ DB.create_table! :prices do
566
560
  integer :item_id
567
561
  datetime :valid_from
568
562
  float :price
569
563
  primary_key [:item_id, :valid_from]
570
564
  foreign_key [:item_id], :items, :key => :id, :name => :fk_prices_items
571
565
  end
572
- MSSQL_DB.create_table! :sales do
566
+ DB.create_table! :sales do
573
567
  integer :id
574
568
  integer :price_item_id
575
569
  datetime :price_valid_from
@@ -577,12 +571,12 @@ describe "Database#foreign_key_list" do
577
571
  end
578
572
  end
579
573
  after(:all) do
580
- MSSQL_DB.drop_table :sales
581
- MSSQL_DB.drop_table :prices
582
- MSSQL_DB.drop_table :items
574
+ DB.drop_table :sales
575
+ DB.drop_table :prices
576
+ DB.drop_table :items
583
577
  end
584
578
  it "should support typical foreign keys" do
585
- MSSQL_DB.foreign_key_list(:prices).should == [{:name => :fk_prices_items,
579
+ DB.foreign_key_list(:prices).should == [{:name => :fk_prices_items,
586
580
  :table => :items,
587
581
  :columns => [:item_id],
588
582
  :key => [:id],
@@ -590,7 +584,7 @@ describe "Database#foreign_key_list" do
590
584
  :on_delete => :no_action }]
591
585
  end
592
586
  it "should support a foreign key with multiple columns" do
593
- MSSQL_DB.foreign_key_list(:sales).should == [{:name => :fk_sales_prices,
587
+ DB.foreign_key_list(:sales).should == [{:name => :fk_sales_prices,
594
588
  :table => :prices,
595
589
  :columns => [:price_item_id, :price_valid_from],
596
590
  :key => [:item_id, :valid_from],
@@ -600,12 +594,12 @@ describe "Database#foreign_key_list" do
600
594
 
601
595
  context "with multiple schemas" do
602
596
  before(:all) do
603
- MSSQL_DB.execute_ddl "create schema vendor"
604
- MSSQL_DB.create_table! :vendor__vendors do
597
+ DB.execute_ddl "create schema vendor"
598
+ DB.create_table! :vendor__vendors do
605
599
  primary_key :id
606
600
  varchar :name
607
601
  end
608
- MSSQL_DB.create_table! :vendor__mapping do
602
+ DB.create_table! :vendor__mapping do
609
603
  integer :vendor_id
610
604
  integer :item_id
611
605
  foreign_key [:vendor_id], :vendor__vendors, :name => :fk_mapping_vendor
@@ -613,12 +607,12 @@ describe "Database#foreign_key_list" do
613
607
  end
614
608
  end
615
609
  after(:all) do
616
- MSSQL_DB.drop_table :vendor__mapping
617
- MSSQL_DB.drop_table :vendor__vendors
618
- MSSQL_DB.execute_ddl "drop schema vendor"
610
+ DB.drop_table :vendor__mapping
611
+ DB.drop_table :vendor__vendors
612
+ DB.execute_ddl "drop schema vendor"
619
613
  end
620
614
  it "should support mixed schema bound tables" do
621
- MSSQL_DB.foreign_key_list(:vendor__mapping).sort_by{|h| h[:name].to_s}.should == [{:name => :fk_mapping_item, :table => :items, :columns => [:item_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }, {:name => :fk_mapping_vendor, :table => :vendor__vendors, :columns => [:vendor_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }]
615
+ DB.foreign_key_list(:vendor__mapping).sort_by{|h| h[:name].to_s}.should == [{:name => :fk_mapping_item, :table => :items, :columns => [:item_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }, {:name => :fk_mapping_vendor, :table => :vendor__vendors, :columns => [:vendor_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }]
622
616
  end
623
617
  end
624
618
  end
@@ -1,28 +1,21 @@
1
+ SEQUEL_ADAPTER_TEST = :mysql
2
+
1
3
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
2
4
 
3
- unless defined?(MYSQL_USER)
4
- MYSQL_USER = 'root'
5
- end
6
- unless defined?(MYSQL_DB)
7
- MYSQL_URL = (ENV['SEQUEL_MY_SPEC_DB']||"mysql://#{MYSQL_USER}@localhost/sandbox") unless defined? MYSQL_URL
8
- MYSQL_DB = Sequel.connect(MYSQL_URL)
9
- end
10
5
  unless defined?(MYSQL_SOCKET_FILE)
11
6
  MYSQL_SOCKET_FILE = '/tmp/mysql.sock'
12
7
  end
13
- INTEGRATION_DB = MYSQL_DB unless defined?(INTEGRATION_DB)
14
-
15
- MYSQL_URI = URI.parse(MYSQL_DB.uri)
8
+ MYSQL_URI = URI.parse(DB.uri)
16
9
 
17
- def MYSQL_DB.sqls
10
+ def DB.sqls
18
11
  (@sqls ||= [])
19
12
  end
20
13
  logger = Object.new
21
14
  def logger.method_missing(m, msg)
22
- MYSQL_DB.sqls << msg
15
+ DB.sqls << msg
23
16
  end
24
- MYSQL_DB.loggers = [logger]
25
- MYSQL_DB.drop_table?(:items, :dolls, :booltest)
17
+ DB.loggers = [logger]
18
+ DB.drop_table?(:items, :dolls, :booltest)
26
19
 
27
20
  SQL_BEGIN = 'BEGIN'
28
21
  SQL_ROLLBACK = 'ROLLBACK'
@@ -30,8 +23,8 @@ SQL_COMMIT = 'COMMIT'
30
23
 
31
24
  describe "MySQL", '#create_table' do
32
25
  before do
33
- @db = MYSQL_DB
34
- MYSQL_DB.sqls.clear
26
+ @db = DB
27
+ DB.sqls.clear
35
28
  end
36
29
  after do
37
30
  @db.drop_table?(:dolls)
@@ -99,10 +92,10 @@ describe "MySQL", '#create_table' do
99
92
  end
100
93
  end
101
94
 
102
- if [:mysql, :mysql2].include?(MYSQL_DB.adapter_scheme)
95
+ if [:mysql, :mysql2].include?(DB.adapter_scheme)
103
96
  describe "Sequel::MySQL::Database#convert_tinyint_to_bool" do
104
97
  before do
105
- @db = MYSQL_DB
98
+ @db = DB
106
99
  @db.create_table(:booltest){column :b, 'tinyint(1)'; column :i, 'tinyint(4)'}
107
100
  @ds = @db[:booltest]
108
101
  end
@@ -162,12 +155,12 @@ end
162
155
 
163
156
  describe "A MySQL dataset" do
164
157
  before do
165
- MYSQL_DB.create_table(:items){String :name; Integer :value}
166
- @d = MYSQL_DB[:items]
167
- MYSQL_DB.sqls.clear
158
+ DB.create_table(:items){String :name; Integer :value}
159
+ @d = DB[:items]
160
+ DB.sqls.clear
168
161
  end
169
162
  after do
170
- MYSQL_DB.drop_table?(:items)
163
+ DB.drop_table?(:items)
171
164
  end
172
165
 
173
166
  specify "should quote columns and tables using back-ticks if quoting identifiers" do
@@ -237,7 +230,7 @@ end
237
230
 
238
231
  describe "MySQL datasets" do
239
232
  before do
240
- @d = MYSQL_DB[:orders]
233
+ @d = DB[:orders]
241
234
  end
242
235
 
243
236
  specify "should correctly quote column references" do
@@ -253,7 +246,7 @@ end
253
246
 
254
247
  describe "Dataset#distinct" do
255
248
  before do
256
- @db = MYSQL_DB
249
+ @db = DB
257
250
  @db.create_table!(:a) do
258
251
  Integer :a
259
252
  Integer :b
@@ -276,7 +269,7 @@ end
276
269
 
277
270
  describe "MySQL join expressions" do
278
271
  before do
279
- @ds = MYSQL_DB[:nodes]
272
+ @ds = DB[:nodes]
280
273
  end
281
274
 
282
275
  specify "should raise error for :full_outer join requests." do
@@ -326,7 +319,7 @@ end
326
319
 
327
320
  describe "Joined MySQL dataset" do
328
321
  before do
329
- @ds = MYSQL_DB[:nodes]
322
+ @ds = DB[:nodes]
330
323
  end
331
324
 
332
325
  specify "should quote fields correctly" do
@@ -350,17 +343,17 @@ end
350
343
 
351
344
  describe "A MySQL database" do
352
345
  after do
353
- MYSQL_DB.drop_table?(:test_innodb)
346
+ DB.drop_table?(:test_innodb)
354
347
  end
355
348
 
356
349
  specify "should handle the creation and dropping of an InnoDB table with foreign keys" do
357
- proc{MYSQL_DB.create_table!(:test_innodb, :engine=>:InnoDB){primary_key :id; foreign_key :fk, :test_innodb, :key=>:id}}.should_not raise_error
350
+ proc{DB.create_table!(:test_innodb, :engine=>:InnoDB){primary_key :id; foreign_key :fk, :test_innodb, :key=>:id}}.should_not raise_error
358
351
  end
359
352
  end
360
353
 
361
354
  describe "A MySQL database" do
362
355
  before(:all) do
363
- @db = MYSQL_DB
356
+ @db = DB
364
357
  @db.create_table! :test2 do
365
358
  text :name
366
359
  integer :value
@@ -457,10 +450,10 @@ describe "A MySQL database with table options" do
457
450
  Sequel::MySQL.default_charset = 'utf8'
458
451
  Sequel::MySQL.default_collate = 'utf8_general_ci'
459
452
 
460
- @db = MYSQL_DB
453
+ @db = DB
461
454
  @db.drop_table?(:items)
462
455
 
463
- MYSQL_DB.sqls.clear
456
+ DB.sqls.clear
464
457
  end
465
458
  after do
466
459
  @db.drop_table?(:items)
@@ -494,9 +487,9 @@ end
494
487
 
495
488
  describe "A MySQL database" do
496
489
  before do
497
- @db = MYSQL_DB
490
+ @db = DB
498
491
  @db.drop_table?(:items)
499
- MYSQL_DB.sqls.clear
492
+ DB.sqls.clear
500
493
  end
501
494
  after do
502
495
  @db.drop_table?(:items, :users)
@@ -596,20 +589,20 @@ describe "A MySQL database" do
596
589
  end
597
590
 
598
591
  # Socket tests should only be run if the MySQL server is on localhost
599
- if %w'localhost 127.0.0.1 ::1'.include?(MYSQL_URI.host) and MYSQL_DB.adapter_scheme == :mysql
592
+ if %w'localhost 127.0.0.1 ::1'.include?(MYSQL_URI.host) and DB.adapter_scheme == :mysql
600
593
  describe "A MySQL database" do
601
594
  specify "should accept a socket option" do
602
- db = Sequel.mysql(MYSQL_DB.opts[:database], :host => 'localhost', :user => MYSQL_DB.opts[:user], :password => MYSQL_DB.opts[:password], :socket => MYSQL_SOCKET_FILE)
595
+ db = Sequel.mysql(DB.opts[:database], :host => 'localhost', :user => DB.opts[:user], :password => DB.opts[:password], :socket => MYSQL_SOCKET_FILE)
603
596
  proc {db.test_connection}.should_not raise_error
604
597
  end
605
598
 
606
599
  specify "should accept a socket option without host option" do
607
- db = Sequel.mysql(MYSQL_DB.opts[:database], :user => MYSQL_DB.opts[:user], :password => MYSQL_DB.opts[:password], :socket => MYSQL_SOCKET_FILE)
600
+ db = Sequel.mysql(DB.opts[:database], :user => DB.opts[:user], :password => DB.opts[:password], :socket => MYSQL_SOCKET_FILE)
608
601
  proc {db.test_connection}.should_not raise_error
609
602
  end
610
603
 
611
604
  specify "should fail to connect with invalid socket" do
612
- db = Sequel.mysql(MYSQL_DB.opts[:database], :user => MYSQL_DB.opts[:user], :password => MYSQL_DB.opts[:password], :socket =>'blah')
605
+ db = Sequel.mysql(DB.opts[:database], :user => DB.opts[:user], :password => DB.opts[:password], :socket =>'blah')
613
606
  proc {db.test_connection}.should raise_error
614
607
  end
615
608
  end
@@ -617,93 +610,93 @@ end
617
610
 
618
611
  describe "A MySQL database" do
619
612
  specify "should accept a read_timeout option when connecting" do
620
- db = Sequel.connect(MYSQL_DB.opts.merge(:read_timeout=>22342))
613
+ db = Sequel.connect(DB.opts.merge(:read_timeout=>22342))
621
614
  proc {db.test_connection}.should_not raise_error
622
615
  end
623
616
 
624
617
  specify "should accept a connect_timeout option when connecting" do
625
- db = Sequel.connect(MYSQL_DB.opts.merge(:connect_timeout=>22342))
618
+ db = Sequel.connect(DB.opts.merge(:connect_timeout=>22342))
626
619
  proc {db.test_connection}.should_not raise_error
627
620
  end
628
621
  end
629
622
 
630
623
  describe "MySQL foreign key support" do
631
624
  after do
632
- MYSQL_DB.drop_table?(:testfk, :testpk)
625
+ DB.drop_table?(:testfk, :testpk)
633
626
  end
634
627
 
635
628
  specify "should create table without :key" do
636
- MYSQL_DB.create_table!(:testpk){primary_key :id}
637
- MYSQL_DB.create_table!(:testfk){foreign_key :fk, :testpk}
629
+ DB.create_table!(:testpk){primary_key :id}
630
+ DB.create_table!(:testfk){foreign_key :fk, :testpk}
638
631
  end
639
632
 
640
633
  specify "should create table with composite keys without :key" do
641
- MYSQL_DB.create_table!(:testpk){Integer :id; Integer :id2; primary_key([:id, :id2])}
642
- MYSQL_DB.create_table!(:testfk){Integer :fk; Integer :fk2; foreign_key([:fk, :fk2], :testpk)}
634
+ DB.create_table!(:testpk){Integer :id; Integer :id2; primary_key([:id, :id2])}
635
+ DB.create_table!(:testfk){Integer :fk; Integer :fk2; foreign_key([:fk, :fk2], :testpk)}
643
636
  end
644
637
 
645
638
  specify "should create table with self referential without :key" do
646
- MYSQL_DB.create_table!(:testfk){primary_key :id; foreign_key :fk, :testfk}
639
+ DB.create_table!(:testfk){primary_key :id; foreign_key :fk, :testfk}
647
640
  end
648
641
 
649
642
  specify "should create table with self referential with composite keys without :key" do
650
- MYSQL_DB.create_table!(:testfk){Integer :id; Integer :id2; Integer :fk; Integer :fk2; primary_key([:id, :id2]); foreign_key([:fk, :fk2], :testfk)}
643
+ DB.create_table!(:testfk){Integer :id; Integer :id2; Integer :fk; Integer :fk2; primary_key([:id, :id2]); foreign_key([:fk, :fk2], :testfk)}
651
644
  end
652
645
 
653
646
  specify "should alter table without :key" do
654
- MYSQL_DB.create_table!(:testpk){primary_key :id}
655
- MYSQL_DB.create_table!(:testfk){Integer :id}
656
- MYSQL_DB.alter_table(:testfk){add_foreign_key :fk, :testpk}
647
+ DB.create_table!(:testpk){primary_key :id}
648
+ DB.create_table!(:testfk){Integer :id}
649
+ DB.alter_table(:testfk){add_foreign_key :fk, :testpk}
657
650
  end
658
651
 
659
652
  specify "should alter table with composite keys without :key" do
660
- MYSQL_DB.create_table!(:testpk){Integer :id; Integer :id2; primary_key([:id, :id2])}
661
- MYSQL_DB.create_table!(:testfk){Integer :fk; Integer :fk2}
662
- MYSQL_DB.alter_table(:testfk){add_foreign_key([:fk, :fk2], :testpk)}
653
+ DB.create_table!(:testpk){Integer :id; Integer :id2; primary_key([:id, :id2])}
654
+ DB.create_table!(:testfk){Integer :fk; Integer :fk2}
655
+ DB.alter_table(:testfk){add_foreign_key([:fk, :fk2], :testpk)}
663
656
  end
664
657
 
665
658
  specify "should alter table with self referential without :key" do
666
- MYSQL_DB.create_table!(:testfk){primary_key :id}
667
- MYSQL_DB.alter_table(:testfk){add_foreign_key :fk, :testfk}
659
+ DB.create_table!(:testfk){primary_key :id}
660
+ DB.alter_table(:testfk){add_foreign_key :fk, :testfk}
668
661
  end
669
662
 
670
663
  specify "should alter table with self referential with composite keys without :key" do
671
- MYSQL_DB.create_table!(:testfk){Integer :id; Integer :id2; Integer :fk; Integer :fk2; primary_key([:id, :id2])}
672
- MYSQL_DB.alter_table(:testfk){add_foreign_key [:fk, :fk2], :testfk}
664
+ DB.create_table!(:testfk){Integer :id; Integer :id2; Integer :fk; Integer :fk2; primary_key([:id, :id2])}
665
+ DB.alter_table(:testfk){add_foreign_key [:fk, :fk2], :testfk}
673
666
  end
674
667
  end
675
668
 
676
669
  describe "A grouped MySQL dataset" do
677
670
  before do
678
- MYSQL_DB.create_table! :test2 do
671
+ DB.create_table! :test2 do
679
672
  text :name
680
673
  integer :value
681
674
  end
682
- MYSQL_DB[:test2] << {:name => '11', :value => 10}
683
- MYSQL_DB[:test2] << {:name => '11', :value => 20}
684
- MYSQL_DB[:test2] << {:name => '11', :value => 30}
685
- MYSQL_DB[:test2] << {:name => '12', :value => 10}
686
- MYSQL_DB[:test2] << {:name => '12', :value => 20}
687
- MYSQL_DB[:test2] << {:name => '13', :value => 10}
675
+ DB[:test2] << {:name => '11', :value => 10}
676
+ DB[:test2] << {:name => '11', :value => 20}
677
+ DB[:test2] << {:name => '11', :value => 30}
678
+ DB[:test2] << {:name => '12', :value => 10}
679
+ DB[:test2] << {:name => '12', :value => 20}
680
+ DB[:test2] << {:name => '13', :value => 10}
688
681
  end
689
682
  after do
690
- MYSQL_DB.drop_table?(:test2)
683
+ DB.drop_table?(:test2)
691
684
  end
692
685
 
693
686
  specify "should return the correct count for raw sql query" do
694
- ds = MYSQL_DB["select name FROM test2 WHERE name = '11' GROUP BY name"]
687
+ ds = DB["select name FROM test2 WHERE name = '11' GROUP BY name"]
695
688
  ds.count.should == 1
696
689
  end
697
690
 
698
691
  specify "should return the correct count for a normal dataset" do
699
- ds = MYSQL_DB[:test2].select(:name).where(:name => '11').group(:name)
692
+ ds = DB[:test2].select(:name).where(:name => '11').group(:name)
700
693
  ds.count.should == 1
701
694
  end
702
695
  end
703
696
 
704
697
  describe "A MySQL database" do
705
698
  before do
706
- @db = MYSQL_DB
699
+ @db = DB
707
700
  @db.drop_table?(:posts)
708
701
  @db.sqls.clear
709
702
  end
@@ -785,18 +778,18 @@ end
785
778
 
786
779
  describe "MySQL::Dataset#insert and related methods" do
787
780
  before do
788
- MYSQL_DB.create_table(:items){String :name; Integer :value}
789
- @d = MYSQL_DB[:items]
790
- MYSQL_DB.sqls.clear
781
+ DB.create_table(:items){String :name; Integer :value}
782
+ @d = DB[:items]
783
+ DB.sqls.clear
791
784
  end
792
785
  after do
793
- MYSQL_DB.drop_table?(:items)
786
+ DB.drop_table?(:items)
794
787
  end
795
788
 
796
789
  specify "#insert should insert record with default values when no arguments given" do
797
790
  @d.insert
798
791
  check_sqls do
799
- MYSQL_DB.sqls.should == ["INSERT INTO `items` () VALUES ()"]
792
+ DB.sqls.should == ["INSERT INTO `items` () VALUES ()"]
800
793
  end
801
794
  @d.all.should == [{:name => nil, :value => nil}]
802
795
  end
@@ -804,7 +797,7 @@ describe "MySQL::Dataset#insert and related methods" do
804
797
  specify "#insert should insert record with default values when empty hash given" do
805
798
  @d.insert({})
806
799
  check_sqls do
807
- MYSQL_DB.sqls.should == ["INSERT INTO `items` () VALUES ()"]
800
+ DB.sqls.should == ["INSERT INTO `items` () VALUES ()"]
808
801
  end
809
802
  @d.all.should == [{:name => nil, :value => nil}]
810
803
  end
@@ -812,23 +805,23 @@ describe "MySQL::Dataset#insert and related methods" do
812
805
  specify "#insert should insert record with default values when empty array given" do
813
806
  @d.insert []
814
807
  check_sqls do
815
- MYSQL_DB.sqls.should == ["INSERT INTO `items` () VALUES ()"]
808
+ DB.sqls.should == ["INSERT INTO `items` () VALUES ()"]
816
809
  end
817
810
  @d.all.should == [{:name => nil, :value => nil}]
818
811
  end
819
812
 
820
813
  specify "#on_duplicate_key_update should work with regular inserts" do
821
- MYSQL_DB.add_index :items, :name, :unique=>true
822
- MYSQL_DB.sqls.clear
814
+ DB.add_index :items, :name, :unique=>true
815
+ DB.sqls.clear
823
816
  @d.insert(:name => 'abc', :value => 1)
824
817
  @d.on_duplicate_key_update(:name, :value => 6).insert(:name => 'abc', :value => 1)
825
818
  @d.on_duplicate_key_update(:name, :value => 6).insert(:name => 'def', :value => 2)
826
819
 
827
820
  check_sqls do
828
- MYSQL_DB.sqls.length.should == 3
829
- MYSQL_DB.sqls[0].should =~ /\AINSERT INTO `items` \(`(name|value)`, `(name|value)`\) VALUES \(('abc'|1), (1|'abc')\)\z/
830
- MYSQL_DB.sqls[1].should =~ /\AINSERT INTO `items` \(`(name|value)`, `(name|value)`\) VALUES \(('abc'|1), (1|'abc')\) ON DUPLICATE KEY UPDATE `name`=VALUES\(`name`\), `value`=6\z/
831
- MYSQL_DB.sqls[2].should =~ /\AINSERT INTO `items` \(`(name|value)`, `(name|value)`\) VALUES \(('def'|2), (2|'def')\) ON DUPLICATE KEY UPDATE `name`=VALUES\(`name`\), `value`=6\z/
821
+ DB.sqls.length.should == 3
822
+ DB.sqls[0].should =~ /\AINSERT INTO `items` \(`(name|value)`, `(name|value)`\) VALUES \(('abc'|1), (1|'abc')\)\z/
823
+ DB.sqls[1].should =~ /\AINSERT INTO `items` \(`(name|value)`, `(name|value)`\) VALUES \(('abc'|1), (1|'abc')\) ON DUPLICATE KEY UPDATE `name`=VALUES\(`name`\), `value`=6\z/
824
+ DB.sqls[2].should =~ /\AINSERT INTO `items` \(`(name|value)`, `(name|value)`\) VALUES \(('def'|2), (2|'def')\) ON DUPLICATE KEY UPDATE `name`=VALUES\(`name`\), `value`=6\z/
832
825
  end
833
826
 
834
827
  @d.all.should == [{:name => 'abc', :value => 6}, {:name => 'def', :value => 2}]
@@ -838,7 +831,7 @@ describe "MySQL::Dataset#insert and related methods" do
838
831
  @d.multi_replace([{:name => 'abc'}, {:name => 'def'}])
839
832
 
840
833
  check_sqls do
841
- MYSQL_DB.sqls.should == [
834
+ DB.sqls.should == [
842
835
  SQL_BEGIN,
843
836
  "REPLACE INTO `items` (`name`) VALUES ('abc'), ('def')",
844
837
  SQL_COMMIT
@@ -855,7 +848,7 @@ describe "MySQL::Dataset#insert and related methods" do
855
848
  :commit_every => 2)
856
849
 
857
850
  check_sqls do
858
- MYSQL_DB.sqls.should == [
851
+ DB.sqls.should == [
859
852
  SQL_BEGIN,
860
853
  "REPLACE INTO `items` (`value`) VALUES (1), (2)",
861
854
  SQL_COMMIT,
@@ -878,7 +871,7 @@ describe "MySQL::Dataset#insert and related methods" do
878
871
  :slice => 2)
879
872
 
880
873
  check_sqls do
881
- MYSQL_DB.sqls.should == [
874
+ DB.sqls.should == [
882
875
  SQL_BEGIN,
883
876
  "REPLACE INTO `items` (`value`) VALUES (1), (2)",
884
877
  SQL_COMMIT,
@@ -900,7 +893,7 @@ describe "MySQL::Dataset#insert and related methods" do
900
893
  @d.multi_insert([{:name => 'abc'}, {:name => 'def'}])
901
894
 
902
895
  check_sqls do
903
- MYSQL_DB.sqls.should == [
896
+ DB.sqls.should == [
904
897
  SQL_BEGIN,
905
898
  "INSERT INTO `items` (`name`) VALUES ('abc'), ('def')",
906
899
  SQL_COMMIT
@@ -917,7 +910,7 @@ describe "MySQL::Dataset#insert and related methods" do
917
910
  :commit_every => 2)
918
911
 
919
912
  check_sqls do
920
- MYSQL_DB.sqls.should == [
913
+ DB.sqls.should == [
921
914
  SQL_BEGIN,
922
915
  "INSERT INTO `items` (`value`) VALUES (1), (2)",
923
916
  SQL_COMMIT,
@@ -940,7 +933,7 @@ describe "MySQL::Dataset#insert and related methods" do
940
933
  :slice => 2)
941
934
 
942
935
  check_sqls do
943
- MYSQL_DB.sqls.should == [
936
+ DB.sqls.should == [
944
937
  SQL_BEGIN,
945
938
  "INSERT INTO `items` (`value`) VALUES (1), (2)",
946
939
  SQL_COMMIT,
@@ -962,7 +955,7 @@ describe "MySQL::Dataset#insert and related methods" do
962
955
  @d.import([:name, :value], [['abc', 1], ['def', 2]])
963
956
 
964
957
  check_sqls do
965
- MYSQL_DB.sqls.should == [
958
+ DB.sqls.should == [
966
959
  SQL_BEGIN,
967
960
  "INSERT INTO `items` (`name`, `value`) VALUES ('abc', 1), ('def', 2)",
968
961
  SQL_COMMIT
@@ -979,7 +972,7 @@ describe "MySQL::Dataset#insert and related methods" do
979
972
  @d.insert_ignore.multi_insert([{:name => 'abc'}, {:name => 'def'}])
980
973
 
981
974
  check_sqls do
982
- MYSQL_DB.sqls.should == [
975
+ DB.sqls.should == [
983
976
  SQL_BEGIN,
984
977
  "INSERT IGNORE INTO `items` (`name`) VALUES ('abc'), ('def')",
985
978
  SQL_COMMIT
@@ -994,7 +987,7 @@ describe "MySQL::Dataset#insert and related methods" do
994
987
  specify "#insert_ignore should add the IGNORE keyword for single inserts" do
995
988
  @d.insert_ignore.insert(:name => 'ghi')
996
989
  check_sqls do
997
- MYSQL_DB.sqls.should == ["INSERT IGNORE INTO `items` (`name`) VALUES ('ghi')"]
990
+ DB.sqls.should == ["INSERT IGNORE INTO `items` (`name`) VALUES ('ghi')"]
998
991
  end
999
992
  @d.all.should == [{:name => 'ghi', :value => nil}]
1000
993
  end
@@ -1003,7 +996,7 @@ describe "MySQL::Dataset#insert and related methods" do
1003
996
  @d.on_duplicate_key_update.import([:name,:value], [['abc', 1], ['def',2]])
1004
997
 
1005
998
  check_sqls do
1006
- MYSQL_DB.sqls.should == [
999
+ DB.sqls.should == [
1007
1000
  "SELECT * FROM `items` LIMIT 1",
1008
1001
  SQL_BEGIN,
1009
1002
  "INSERT INTO `items` (`name`, `value`) VALUES ('abc', 1), ('def', 2) ON DUPLICATE KEY UPDATE `name`=VALUES(`name`), `value`=VALUES(`value`)",
@@ -1022,7 +1015,7 @@ describe "MySQL::Dataset#insert and related methods" do
1022
1015
  )
1023
1016
 
1024
1017
  check_sqls do
1025
- MYSQL_DB.sqls.should == [
1018
+ DB.sqls.should == [
1026
1019
  SQL_BEGIN,
1027
1020
  "INSERT INTO `items` (`name`, `value`) VALUES ('abc', 1), ('def', 2) ON DUPLICATE KEY UPDATE `value`=VALUES(`value`)",
1028
1021
  SQL_COMMIT
@@ -1038,21 +1031,21 @@ end
1038
1031
 
1039
1032
  describe "MySQL::Dataset#update and related methods" do
1040
1033
  before do
1041
- MYSQL_DB.create_table(:items){String :name; Integer :value; index :name, :unique=>true}
1042
- @d = MYSQL_DB[:items]
1034
+ DB.create_table(:items){String :name; Integer :value; index :name, :unique=>true}
1035
+ @d = DB[:items]
1043
1036
  end
1044
1037
  after do
1045
- MYSQL_DB.drop_table?(:items)
1038
+ DB.drop_table?(:items)
1046
1039
  end
1047
1040
 
1048
1041
  specify "#update_ignore should not raise error where normal update would fail" do
1049
1042
  @d.insert(:name => 'cow', :value => 0)
1050
1043
  @d.insert(:name => 'cat', :value => 1)
1051
1044
  proc{@d.where(:value => 1).update(:name => 'cow')}.should raise_error(Sequel::DatabaseError)
1052
- MYSQL_DB.sqls.clear
1045
+ DB.sqls.clear
1053
1046
  @d.update_ignore.where(:value => 1).update(:name => 'cow')
1054
1047
  check_sqls do
1055
- MYSQL_DB.sqls.should == ["UPDATE IGNORE `items` SET `name` = 'cow' WHERE (`value` = 1)"]
1048
+ DB.sqls.should == ["UPDATE IGNORE `items` SET `name` = 'cow' WHERE (`value` = 1)"]
1056
1049
  end
1057
1050
  @d.order(:name).all.should == [{:name => 'cat', :value => 1}, {:name => 'cow', :value => 0}]
1058
1051
  end
@@ -1060,16 +1053,16 @@ end
1060
1053
 
1061
1054
  describe "MySQL::Dataset#replace" do
1062
1055
  before do
1063
- MYSQL_DB.create_table(:items){Integer :id, :unique=>true; Integer :value}
1064
- @d = MYSQL_DB[:items]
1065
- MYSQL_DB.sqls.clear
1056
+ DB.create_table(:items){Integer :id, :unique=>true; Integer :value}
1057
+ @d = DB[:items]
1058
+ DB.sqls.clear
1066
1059
  end
1067
1060
  after do
1068
- MYSQL_DB.drop_table?(:items)
1061
+ DB.drop_table?(:items)
1069
1062
  end
1070
1063
 
1071
1064
  specify "should use default values if they exist" do
1072
- MYSQL_DB.alter_table(:items){set_column_default :id, 1; set_column_default :value, 2}
1065
+ DB.alter_table(:items){set_column_default :id, 1; set_column_default :value, 2}
1073
1066
  @d.replace
1074
1067
  @d.all.should == [{:id=>1, :value=>2}]
1075
1068
  @d.replace([])
@@ -1102,7 +1095,7 @@ end
1102
1095
 
1103
1096
  describe "MySQL::Dataset#complex_expression_sql" do
1104
1097
  before do
1105
- @d = MYSQL_DB.dataset
1098
+ @d = DB.dataset
1106
1099
  end
1107
1100
 
1108
1101
  specify "should handle string concatenation with CONCAT if more than one record" do
@@ -1119,28 +1112,28 @@ end
1119
1112
 
1120
1113
  describe "MySQL::Dataset#calc_found_rows" do
1121
1114
  before do
1122
- MYSQL_DB.create_table!(:items){Integer :a}
1115
+ DB.create_table!(:items){Integer :a}
1123
1116
  end
1124
1117
  after do
1125
- MYSQL_DB.drop_table?(:items)
1118
+ DB.drop_table?(:items)
1126
1119
  end
1127
1120
 
1128
1121
  specify "should add the SQL_CALC_FOUND_ROWS keyword when selecting" do
1129
- MYSQL_DB[:items].select(:a).calc_found_rows.limit(1).sql.should == \
1122
+ DB[:items].select(:a).calc_found_rows.limit(1).sql.should == \
1130
1123
  'SELECT SQL_CALC_FOUND_ROWS `a` FROM `items` LIMIT 1'
1131
1124
  end
1132
1125
 
1133
1126
  specify "should count matching rows disregarding LIMIT clause" do
1134
- MYSQL_DB[:items].multi_insert([{:a => 1}, {:a => 1}, {:a => 2}])
1135
- MYSQL_DB.sqls.clear
1127
+ DB[:items].multi_insert([{:a => 1}, {:a => 1}, {:a => 2}])
1128
+ DB.sqls.clear
1136
1129
 
1137
- MYSQL_DB.synchronize do
1138
- MYSQL_DB[:items].calc_found_rows.filter(:a => 1).limit(1).all.should == [{:a => 1}]
1139
- MYSQL_DB.dataset.select(Sequel.function(:FOUND_ROWS).as(:rows)).all.should == [{:rows => 2 }]
1130
+ DB.synchronize do
1131
+ DB[:items].calc_found_rows.filter(:a => 1).limit(1).all.should == [{:a => 1}]
1132
+ DB.dataset.select(Sequel.function(:FOUND_ROWS).as(:rows)).all.should == [{:rows => 2 }]
1140
1133
  end
1141
1134
 
1142
1135
  check_sqls do
1143
- MYSQL_DB.sqls.should == [
1136
+ DB.sqls.should == [
1144
1137
  'SELECT SQL_CALC_FOUND_ROWS * FROM `items` WHERE (`a` = 1) LIMIT 1',
1145
1138
  'SELECT FOUND_ROWS() AS `rows`',
1146
1139
  ]
@@ -1148,34 +1141,34 @@ describe "MySQL::Dataset#calc_found_rows" do
1148
1141
  end
1149
1142
  end
1150
1143
 
1151
- if MYSQL_DB.adapter_scheme == :mysql or MYSQL_DB.adapter_scheme == :jdbc or MYSQL_DB.adapter_scheme == :mysql2
1144
+ if DB.adapter_scheme == :mysql or DB.adapter_scheme == :jdbc or DB.adapter_scheme == :mysql2
1152
1145
  describe "MySQL Stored Procedures" do
1153
1146
  before do
1154
- MYSQL_DB.create_table(:items){Integer :id; Integer :value}
1155
- @d = MYSQL_DB[:items]
1156
- MYSQL_DB.sqls.clear
1147
+ DB.create_table(:items){Integer :id; Integer :value}
1148
+ @d = DB[:items]
1149
+ DB.sqls.clear
1157
1150
  end
1158
1151
  after do
1159
- MYSQL_DB.drop_table?(:items)
1160
- MYSQL_DB.execute('DROP PROCEDURE test_sproc')
1152
+ DB.drop_table?(:items)
1153
+ DB.execute('DROP PROCEDURE test_sproc')
1161
1154
  end
1162
1155
 
1163
1156
  specify "should be callable on the database object" do
1164
- MYSQL_DB.execute_ddl('CREATE PROCEDURE test_sproc() BEGIN DELETE FROM items; END')
1165
- MYSQL_DB[:items].delete
1166
- MYSQL_DB[:items].insert(:value=>1)
1167
- MYSQL_DB[:items].count.should == 1
1168
- MYSQL_DB.call_sproc(:test_sproc)
1169
- MYSQL_DB[:items].count.should == 0
1157
+ DB.execute_ddl('CREATE PROCEDURE test_sproc() BEGIN DELETE FROM items; END')
1158
+ DB[:items].delete
1159
+ DB[:items].insert(:value=>1)
1160
+ DB[:items].count.should == 1
1161
+ DB.call_sproc(:test_sproc)
1162
+ DB[:items].count.should == 0
1170
1163
  end
1171
1164
 
1172
1165
  # Mysql2 doesn't support stored procedures that return result sets, probably because
1173
1166
  # CLIENT_MULTI_RESULTS is not set.
1174
- unless MYSQL_DB.adapter_scheme == :mysql2
1167
+ unless DB.adapter_scheme == :mysql2
1175
1168
  specify "should be callable on the dataset object" do
1176
- MYSQL_DB.execute_ddl('CREATE PROCEDURE test_sproc(a INTEGER) BEGIN SELECT *, a AS b FROM items; END')
1177
- MYSQL_DB[:items].delete
1178
- @d = MYSQL_DB[:items]
1169
+ DB.execute_ddl('CREATE PROCEDURE test_sproc(a INTEGER) BEGIN SELECT *, a AS b FROM items; END')
1170
+ DB[:items].delete
1171
+ @d = DB[:items]
1179
1172
  @d.call_sproc(:select, :test_sproc, 3).should == []
1180
1173
  @d.insert(:value=>1)
1181
1174
  @d.call_sproc(:select, :test_sproc, 4).should == [{:id=>nil, :value=>1, :b=>4}]
@@ -1184,9 +1177,9 @@ if MYSQL_DB.adapter_scheme == :mysql or MYSQL_DB.adapter_scheme == :jdbc or MYSQ
1184
1177
  end
1185
1178
 
1186
1179
  specify "should be callable on the dataset object with multiple arguments" do
1187
- MYSQL_DB.execute_ddl('CREATE PROCEDURE test_sproc(a INTEGER, c INTEGER) BEGIN SELECT *, a AS b, c AS d FROM items; END')
1188
- MYSQL_DB[:items].delete
1189
- @d = MYSQL_DB[:items]
1180
+ DB.execute_ddl('CREATE PROCEDURE test_sproc(a INTEGER, c INTEGER) BEGIN SELECT *, a AS b, c AS d FROM items; END')
1181
+ DB[:items].delete
1182
+ @d = DB[:items]
1190
1183
  @d.call_sproc(:select, :test_sproc, 3, 4).should == []
1191
1184
  @d.insert(:value=>1)
1192
1185
  @d.call_sproc(:select, :test_sproc, 4, 5).should == [{:id=>nil, :value=>1, :b=>4, :d=>5}]
@@ -1196,58 +1189,58 @@ if MYSQL_DB.adapter_scheme == :mysql or MYSQL_DB.adapter_scheme == :jdbc or MYSQ
1196
1189
  end
1197
1190
 
1198
1191
  specify "should deal with nil values" do
1199
- MYSQL_DB.execute_ddl('CREATE PROCEDURE test_sproc(i INTEGER, v INTEGER) BEGIN INSERT INTO items VALUES (i, v); END')
1200
- MYSQL_DB[:items].delete
1201
- MYSQL_DB.call_sproc(:test_sproc, :args=>[1, nil])
1202
- MYSQL_DB[:items].all.should == [{:id=>1, :value=>nil}]
1192
+ DB.execute_ddl('CREATE PROCEDURE test_sproc(i INTEGER, v INTEGER) BEGIN INSERT INTO items VALUES (i, v); END')
1193
+ DB[:items].delete
1194
+ DB.call_sproc(:test_sproc, :args=>[1, nil])
1195
+ DB[:items].all.should == [{:id=>1, :value=>nil}]
1203
1196
  end
1204
1197
  end
1205
1198
  end
1206
1199
 
1207
- if MYSQL_DB.adapter_scheme == :mysql
1200
+ if DB.adapter_scheme == :mysql
1208
1201
  describe "MySQL bad date/time conversions" do
1209
1202
  after do
1210
- MYSQL_DB.convert_invalid_date_time = false
1203
+ DB.convert_invalid_date_time = false
1211
1204
  end
1212
1205
 
1213
1206
  specify "should raise an exception when a bad date/time is used and convert_invalid_date_time is false" do
1214
- MYSQL_DB.convert_invalid_date_time = false
1215
- proc{MYSQL_DB["SELECT CAST('0000-00-00' AS date)"].single_value}.should raise_error(Sequel::InvalidValue)
1216
- proc{MYSQL_DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value}.should raise_error(Sequel::InvalidValue)
1217
- proc{MYSQL_DB["SELECT CAST('25:00:00' AS time)"].single_value}.should raise_error(Sequel::InvalidValue)
1207
+ DB.convert_invalid_date_time = false
1208
+ proc{DB["SELECT CAST('0000-00-00' AS date)"].single_value}.should raise_error(Sequel::InvalidValue)
1209
+ proc{DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value}.should raise_error(Sequel::InvalidValue)
1210
+ proc{DB["SELECT CAST('25:00:00' AS time)"].single_value}.should raise_error(Sequel::InvalidValue)
1218
1211
  end
1219
1212
 
1220
1213
  specify "should not use a nil value bad date/time is used and convert_invalid_date_time is nil or :nil" do
1221
- MYSQL_DB.convert_invalid_date_time = nil
1222
- MYSQL_DB["SELECT CAST('0000-00-00' AS date)"].single_value.should == nil
1223
- MYSQL_DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value.should == nil
1224
- MYSQL_DB["SELECT CAST('25:00:00' AS time)"].single_value.should == nil
1225
- MYSQL_DB.convert_invalid_date_time = :nil
1226
- MYSQL_DB["SELECT CAST('0000-00-00' AS date)"].single_value.should == nil
1227
- MYSQL_DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value.should == nil
1228
- MYSQL_DB["SELECT CAST('25:00:00' AS time)"].single_value.should == nil
1214
+ DB.convert_invalid_date_time = nil
1215
+ DB["SELECT CAST('0000-00-00' AS date)"].single_value.should == nil
1216
+ DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value.should == nil
1217
+ DB["SELECT CAST('25:00:00' AS time)"].single_value.should == nil
1218
+ DB.convert_invalid_date_time = :nil
1219
+ DB["SELECT CAST('0000-00-00' AS date)"].single_value.should == nil
1220
+ DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value.should == nil
1221
+ DB["SELECT CAST('25:00:00' AS time)"].single_value.should == nil
1229
1222
  end
1230
1223
 
1231
1224
  specify "should not use a nil value bad date/time is used and convert_invalid_date_time is :string" do
1232
- MYSQL_DB.convert_invalid_date_time = :string
1233
- MYSQL_DB["SELECT CAST('0000-00-00' AS date)"].single_value.should == '0000-00-00'
1234
- MYSQL_DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value.should == '0000-00-00 00:00:00'
1235
- MYSQL_DB["SELECT CAST('25:00:00' AS time)"].single_value.should == '25:00:00'
1225
+ DB.convert_invalid_date_time = :string
1226
+ DB["SELECT CAST('0000-00-00' AS date)"].single_value.should == '0000-00-00'
1227
+ DB["SELECT CAST('0000-00-00 00:00:00' AS datetime)"].single_value.should == '0000-00-00 00:00:00'
1228
+ DB["SELECT CAST('25:00:00' AS time)"].single_value.should == '25:00:00'
1236
1229
  end
1237
1230
  end
1238
1231
 
1239
1232
  describe "MySQL multiple result sets" do
1240
1233
  before do
1241
- MYSQL_DB.create_table!(:a){Integer :a}
1242
- MYSQL_DB.create_table!(:b){Integer :b}
1243
- @ds = MYSQL_DB['SELECT * FROM a; SELECT * FROM b']
1244
- MYSQL_DB[:a].insert(10)
1245
- MYSQL_DB[:a].insert(15)
1246
- MYSQL_DB[:b].insert(20)
1247
- MYSQL_DB[:b].insert(25)
1234
+ DB.create_table!(:a){Integer :a}
1235
+ DB.create_table!(:b){Integer :b}
1236
+ @ds = DB['SELECT * FROM a; SELECT * FROM b']
1237
+ DB[:a].insert(10)
1238
+ DB[:a].insert(15)
1239
+ DB[:b].insert(20)
1240
+ DB[:b].insert(25)
1248
1241
  end
1249
1242
  after do
1250
- MYSQL_DB.drop_table?(:a, :b)
1243
+ DB.drop_table?(:a, :b)
1251
1244
  end
1252
1245
 
1253
1246
  specify "should combine all results by default" do
@@ -1255,14 +1248,14 @@ if MYSQL_DB.adapter_scheme == :mysql
1255
1248
  end
1256
1249
 
1257
1250
  specify "should work with Database#run" do
1258
- proc{MYSQL_DB.run('SELECT * FROM a; SELECT * FROM b')}.should_not raise_error
1259
- proc{MYSQL_DB.run('SELECT * FROM a; SELECT * FROM b')}.should_not raise_error
1251
+ proc{DB.run('SELECT * FROM a; SELECT * FROM b')}.should_not raise_error
1252
+ proc{DB.run('SELECT * FROM a; SELECT * FROM b')}.should_not raise_error
1260
1253
  end
1261
1254
 
1262
1255
  specify "should work with Database#run and other statements" do
1263
- proc{MYSQL_DB.run('UPDATE a SET a = 1; SELECT * FROM a; DELETE FROM b')}.should_not raise_error
1264
- MYSQL_DB[:a].select_order_map(:a).should == [1, 1]
1265
- MYSQL_DB[:b].all.should == []
1256
+ proc{DB.run('UPDATE a SET a = 1; SELECT * FROM a; DELETE FROM b')}.should_not raise_error
1257
+ DB[:a].select_order_map(:a).should == [1, 1]
1258
+ DB[:b].all.should == []
1266
1259
  end
1267
1260
 
1268
1261
  specify "should split results returned into arrays if split_multiple_result_sets is used" do
@@ -1283,24 +1276,24 @@ if MYSQL_DB.adapter_scheme == :mysql
1283
1276
  end
1284
1277
 
1285
1278
  specify "should not allow splitting a graphed dataset" do
1286
- proc{MYSQL_DB[:a].graph(:b, :b=>:a).split_multiple_result_sets}.should raise_error(Sequel::Error)
1279
+ proc{DB[:a].graph(:b, :b=>:a).split_multiple_result_sets}.should raise_error(Sequel::Error)
1287
1280
  end
1288
1281
  end
1289
1282
  end
1290
1283
 
1291
- if MYSQL_DB.adapter_scheme == :mysql2
1284
+ if DB.adapter_scheme == :mysql2
1292
1285
  describe "Mysql2 streaming" do
1293
1286
  before(:all) do
1294
- MYSQL_DB.create_table!(:a){Integer :a}
1295
- MYSQL_DB.transaction do
1287
+ DB.create_table!(:a){Integer :a}
1288
+ DB.transaction do
1296
1289
  1000.times do |i|
1297
- MYSQL_DB[:a].insert(i)
1290
+ DB[:a].insert(i)
1298
1291
  end
1299
1292
  end
1300
- @ds = MYSQL_DB[:a].stream.order(:a)
1293
+ @ds = DB[:a].stream.order(:a)
1301
1294
  end
1302
1295
  after(:all) do
1303
- MYSQL_DB.drop_table?(:a)
1296
+ DB.drop_table?(:a)
1304
1297
  end
1305
1298
 
1306
1299
  specify "should correctly stream results" do