sequel 4.46.0 → 4.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +210 -0
- data/Rakefile +1 -1
- data/doc/advanced_associations.rdoc +1 -1
- data/doc/opening_databases.rdoc +3 -2
- data/doc/release_notes/4.47.0.txt +56 -0
- data/doc/release_notes/4.48.0.txt +293 -0
- data/doc/release_notes/4.49.0.txt +222 -0
- data/lib/sequel/adapters/ado/access.rb +2 -1
- data/lib/sequel/adapters/do/postgres.rb +5 -2
- data/lib/sequel/adapters/ibmdb.rb +30 -8
- data/lib/sequel/adapters/jdbc/as400.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +12 -3
- data/lib/sequel/adapters/jdbc/derby.rb +4 -5
- data/lib/sequel/adapters/jdbc/h2.rb +10 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
- data/lib/sequel/adapters/jdbc.rb +39 -23
- data/lib/sequel/adapters/mock.rb +27 -19
- data/lib/sequel/adapters/mysql.rb +17 -16
- data/lib/sequel/adapters/mysql2.rb +5 -6
- data/lib/sequel/adapters/oracle.rb +5 -9
- data/lib/sequel/adapters/postgres.rb +91 -103
- data/lib/sequel/adapters/shared/db2.rb +22 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -4
- data/lib/sequel/adapters/shared/mysql.rb +79 -25
- data/lib/sequel/adapters/shared/oracle.rb +26 -3
- data/lib/sequel/adapters/shared/postgres.rb +199 -95
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +72 -82
- data/lib/sequel/adapters/sqlanywhere.rb +4 -1
- data/lib/sequel/adapters/sqlite.rb +5 -3
- data/lib/sequel/adapters/swift/postgres.rb +5 -2
- data/lib/sequel/adapters/tinytds.rb +0 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/adapters/utils/pg_types.rb +2 -76
- data/lib/sequel/ast_transformer.rb +1 -1
- data/lib/sequel/connection_pool/sharded_single.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/connection_pool.rb +9 -2
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database/connecting.rb +8 -8
- data/lib/sequel/database/dataset.rb +6 -3
- data/lib/sequel/database/dataset_defaults.rb +14 -1
- data/lib/sequel/database/misc.rb +1 -1
- data/lib/sequel/database/query.rb +3 -0
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset/actions.rb +72 -10
- data/lib/sequel/dataset/dataset_module.rb +58 -0
- data/lib/sequel/dataset/graph.rb +1 -1
- data/lib/sequel/dataset/misc.rb +1 -0
- data/lib/sequel/dataset/prepared_statements.rb +3 -3
- data/lib/sequel/dataset/query.rb +22 -11
- data/lib/sequel/dataset.rb +1 -1
- data/lib/sequel/exceptions.rb +8 -0
- data/lib/sequel/extensions/_model_pg_row.rb +5 -2
- data/lib/sequel/extensions/core_extensions.rb +4 -1
- data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
- data/lib/sequel/extensions/filter_having.rb +2 -0
- data/lib/sequel/extensions/freeze_datasets.rb +2 -0
- data/lib/sequel/extensions/from_block.rb +1 -1
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/hash_aliases.rb +2 -0
- data/lib/sequel/extensions/identifier_mangling.rb +0 -7
- data/lib/sequel/extensions/meta_def.rb +2 -0
- data/lib/sequel/extensions/migration.rb +11 -8
- data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/null_dataset.rb +1 -0
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +207 -130
- data/lib/sequel/extensions/pg_hstore.rb +38 -20
- data/lib/sequel/extensions/pg_inet.rb +18 -6
- data/lib/sequel/extensions/pg_interval.rb +19 -12
- data/lib/sequel/extensions/pg_json.rb +25 -14
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/extensions/pg_range.rb +133 -100
- data/lib/sequel/extensions/pg_range_ops.rb +4 -3
- data/lib/sequel/extensions/pg_row.rb +68 -39
- data/lib/sequel/extensions/pg_row_ops.rb +11 -5
- data/lib/sequel/extensions/query_literals.rb +2 -0
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
- data/lib/sequel/extensions/s.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +29 -25
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
- data/lib/sequel/extensions/server_block.rb +32 -15
- data/lib/sequel/extensions/set_overrides.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +0 -1
- data/lib/sequel/extensions/symbol_aref.rb +0 -4
- data/lib/sequel/model/associations.rb +35 -7
- data/lib/sequel/model/base.rb +113 -87
- data/lib/sequel/model/dataset_module.rb +5 -43
- data/lib/sequel/model/errors.rb +2 -1
- data/lib/sequel/model/inflections.rb +17 -5
- data/lib/sequel/model.rb +26 -58
- data/lib/sequel/plugins/active_model.rb +2 -2
- data/lib/sequel/plugins/association_autoreloading.rb +2 -0
- data/lib/sequel/plugins/association_dependencies.rb +3 -3
- data/lib/sequel/plugins/association_pks.rb +73 -46
- data/lib/sequel/plugins/association_proxies.rb +1 -1
- data/lib/sequel/plugins/auto_validations.rb +6 -2
- data/lib/sequel/plugins/boolean_readers.rb +2 -2
- data/lib/sequel/plugins/boolean_subsets.rb +1 -1
- data/lib/sequel/plugins/caching.rb +19 -13
- data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
- data/lib/sequel/plugins/column_conflicts.rb +7 -2
- data/lib/sequel/plugins/column_select.rb +3 -3
- data/lib/sequel/plugins/composition.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +8 -8
- data/lib/sequel/plugins/dataset_associations.rb +25 -13
- data/lib/sequel/plugins/defaults_setter.rb +13 -1
- data/lib/sequel/plugins/eager_each.rb +1 -1
- data/lib/sequel/plugins/force_encoding.rb +2 -2
- data/lib/sequel/plugins/hook_class_methods.rb +9 -12
- data/lib/sequel/plugins/identifier_columns.rb +2 -0
- data/lib/sequel/plugins/instance_filters.rb +3 -1
- data/lib/sequel/plugins/instance_hooks.rb +17 -9
- data/lib/sequel/plugins/json_serializer.rb +19 -12
- data/lib/sequel/plugins/lazy_attributes.rb +8 -7
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
- data/lib/sequel/plugins/modification_detection.rb +3 -0
- data/lib/sequel/plugins/nested_attributes.rb +6 -2
- data/lib/sequel/plugins/pg_array_associations.rb +5 -0
- data/lib/sequel/plugins/pg_row.rb +4 -2
- data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/plugins/rcte_tree.rb +4 -24
- data/lib/sequel/plugins/serialization.rb +9 -15
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
- data/lib/sequel/plugins/split_values.rb +6 -5
- data/lib/sequel/plugins/static_cache.rb +31 -25
- data/lib/sequel/plugins/subset_conditions.rb +3 -1
- data/lib/sequel/plugins/table_select.rb +1 -1
- data/lib/sequel/plugins/touch.rb +4 -2
- data/lib/sequel/plugins/validation_class_methods.rb +5 -6
- data/lib/sequel/plugins/validation_helpers.rb +14 -8
- data/lib/sequel/plugins/xml_serializer.rb +4 -4
- data/lib/sequel/sql.rb +18 -9
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +115 -14
- data/spec/adapters/mssql_spec.rb +4 -4
- data/spec/adapters/mysql_spec.rb +83 -29
- data/spec/adapters/oracle_spec.rb +28 -24
- data/spec/adapters/postgres_spec.rb +40 -24
- data/spec/adapters/sqlanywhere_spec.rb +88 -86
- data/spec/adapters/sqlite_spec.rb +29 -24
- data/spec/bin_spec.rb +7 -1
- data/spec/core/connection_pool_spec.rb +45 -14
- data/spec/core/database_spec.rb +155 -0
- data/spec/core/dataset_spec.rb +219 -36
- data/spec/core/schema_spec.rb +16 -0
- data/spec/core/spec_helper.rb +1 -0
- data/spec/core_extensions_spec.rb +6 -2
- data/spec/extensions/active_model_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +34 -2
- data/spec/extensions/auto_literal_strings_spec.rb +5 -1
- data/spec/extensions/auto_validations_spec.rb +2 -0
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +106 -19
- data/spec/extensions/column_conflicts_spec.rb +11 -0
- data/spec/extensions/column_select_spec.rb +1 -0
- data/spec/extensions/composition_spec.rb +13 -0
- data/spec/extensions/connection_validator_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +20 -8
- data/spec/extensions/defaults_setter_spec.rb +15 -1
- data/spec/extensions/filter_having_spec.rb +5 -3
- data/spec/extensions/hash_aliases_spec.rb +3 -1
- data/spec/extensions/identifier_columns_spec.rb +3 -1
- data/spec/extensions/implicit_subquery_spec.rb +4 -2
- data/spec/extensions/json_serializer_spec.rb +18 -0
- data/spec/extensions/lazy_attributes_spec.rb +3 -3
- data/spec/extensions/many_through_many_spec.rb +4 -4
- data/spec/extensions/meta_def_spec.rb +9 -0
- data/spec/extensions/migration_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +14 -3
- data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
- data/spec/extensions/null_dataset_spec.rb +1 -1
- data/spec/extensions/pg_array_associations_spec.rb +29 -18
- data/spec/extensions/pg_array_spec.rb +44 -25
- data/spec/extensions/pg_hstore_spec.rb +10 -0
- data/spec/extensions/pg_inet_spec.rb +26 -0
- data/spec/extensions/pg_interval_spec.rb +20 -0
- data/spec/extensions/pg_json_spec.rb +24 -0
- data/spec/extensions/pg_range_spec.rb +98 -14
- data/spec/extensions/pg_row_spec.rb +14 -4
- data/spec/extensions/pg_typecast_on_load_spec.rb +11 -9
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/query_literals_spec.rb +3 -1
- data/spec/extensions/schema_dumper_spec.rb +108 -94
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
- data/spec/extensions/serialization_spec.rb +1 -1
- data/spec/extensions/server_block_spec.rb +7 -0
- data/spec/extensions/single_table_inheritance_spec.rb +17 -1
- data/spec/extensions/spec_helper.rb +7 -1
- data/spec/extensions/static_cache_spec.rb +75 -24
- data/spec/extensions/string_agg_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +9 -0
- data/spec/extensions/validation_helpers_spec.rb +10 -5
- data/spec/extensions/whitelist_security_spec.rb +26 -0
- data/spec/integration/associations_test.rb +8 -0
- data/spec/integration/dataset_test.rb +45 -44
- data/spec/integration/model_test.rb +53 -4
- data/spec/integration/plugin_test.rb +28 -4
- data/spec/integration/prepared_statement_test.rb +3 -0
- data/spec/integration/schema_test.rb +21 -1
- data/spec/integration/transaction_test.rb +40 -40
- data/spec/model/association_reflection_spec.rb +43 -1
- data/spec/model/associations_spec.rb +29 -9
- data/spec/model/class_dataset_methods_spec.rb +20 -4
- data/spec/model/dataset_methods_spec.rb +12 -3
- data/spec/model/eager_loading_spec.rb +8 -8
- data/spec/model/model_spec.rb +45 -1
- data/spec/model/plugins_spec.rb +34 -0
- data/spec/model/record_spec.rb +1 -1
- data/spec/spec_config.rb +2 -0
- metadata +11 -4
- data/spec/adapters/firebird_spec.rb +0 -405
- data/spec/adapters/informix_spec.rb +0 -100
@@ -1,405 +0,0 @@
|
|
1
|
-
SEQUEL_ADAPTER_TEST = :firebird
|
2
|
-
|
3
|
-
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
4
|
-
|
5
|
-
def DB.sqls
|
6
|
-
(@sqls ||= [])
|
7
|
-
end
|
8
|
-
logger = Object.new
|
9
|
-
def logger.method_missing(m, msg)
|
10
|
-
DB.sqls.push(msg)
|
11
|
-
end
|
12
|
-
DB.loggers = [logger]
|
13
|
-
|
14
|
-
DB.create_table! :test do
|
15
|
-
varchar :name, :size => 50
|
16
|
-
integer :val, :index => true
|
17
|
-
end
|
18
|
-
|
19
|
-
DB.create_table! :test2 do
|
20
|
-
integer :val
|
21
|
-
timestamp :time_stamp
|
22
|
-
end
|
23
|
-
|
24
|
-
DB.create_table! :test3 do
|
25
|
-
integer :val
|
26
|
-
timestamp :time_stamp
|
27
|
-
end
|
28
|
-
|
29
|
-
DB.create_table! :test5 do
|
30
|
-
primary_key :xid
|
31
|
-
integer :val
|
32
|
-
end
|
33
|
-
|
34
|
-
DB.create_table! :test6 do
|
35
|
-
primary_key :xid
|
36
|
-
blob :val
|
37
|
-
String :val2
|
38
|
-
varchar :val3, :size=>200
|
39
|
-
String :val4, :text=>true
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "A Firebird database" do
|
43
|
-
before do
|
44
|
-
@db = DB
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should provide disconnect functionality" do
|
48
|
-
@db.tables
|
49
|
-
@db.pool.size.must_equal 1
|
50
|
-
@db.disconnect
|
51
|
-
@db.pool.size.must_equal 0
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should raise Sequel::Error on error" do
|
55
|
-
proc{@db << "SELECT 1 + 'a'"}.must_raise(Sequel::Error)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "A Firebird dataset" do
|
60
|
-
before do
|
61
|
-
@d = DB[:test].with_quote_identifiers(true)
|
62
|
-
@d.delete
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should return the correct record count" do
|
66
|
-
@d.count.must_equal 0
|
67
|
-
@d << {:name => 'abc', :val => 123}
|
68
|
-
@d << {:name => 'abc', :val => 456}
|
69
|
-
@d << {:name => 'def', :val => 789}
|
70
|
-
@d.count.must_equal 3
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should return the correct records" do
|
74
|
-
@d.to_a.must_equal []
|
75
|
-
@d << {:name => 'abc', :val => 123}
|
76
|
-
@d << {:name => 'abc', :val => 456}
|
77
|
-
@d << {:name => 'def', :val => 789}
|
78
|
-
|
79
|
-
@d.order(:val).to_a.must_equal [
|
80
|
-
{:name => 'abc', :val => 123},
|
81
|
-
{:name => 'abc', :val => 456},
|
82
|
-
{:name => 'def', :val => 789}
|
83
|
-
]
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should update records correctly" do
|
87
|
-
@d << {:name => 'abc', :val => 123}
|
88
|
-
@d << {:name => 'abc', :val => 456}
|
89
|
-
@d << {:name => 'def', :val => 789}
|
90
|
-
@d.filter(:name => 'abc').update(:val => 530)
|
91
|
-
|
92
|
-
@d[:name => 'def'][:val].must_equal 789
|
93
|
-
@d.filter(:val => 530).count.must_equal 2
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should delete records correctly" do
|
97
|
-
@d << {:name => 'abc', :val => 123}
|
98
|
-
@d << {:name => 'abc', :val => 456}
|
99
|
-
@d << {:name => 'def', :val => 789}
|
100
|
-
@d.filter(:name => 'abc').delete
|
101
|
-
|
102
|
-
@d.count.must_equal 1
|
103
|
-
@d.first[:name].must_equal 'def'
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should be able to literalize booleans" do
|
107
|
-
@d.literal(true)
|
108
|
-
@d.literal(false)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should quote columns and tables using double quotes if quoting identifiers" do
|
112
|
-
@d.select(:name).sql.must_equal \
|
113
|
-
'SELECT "NAME" FROM "TEST"'
|
114
|
-
|
115
|
-
@d.select('COUNT(*)'.lit).sql.must_equal \
|
116
|
-
'SELECT COUNT(*) FROM "TEST"'
|
117
|
-
|
118
|
-
@d.select(:max[:val]).sql.must_equal \
|
119
|
-
'SELECT max("VAL") FROM "TEST"'
|
120
|
-
|
121
|
-
@d.select(:now[]).sql.must_equal \
|
122
|
-
'SELECT now() FROM "TEST"'
|
123
|
-
|
124
|
-
@d.select(:max[Sequel[:items][:val]]).sql.must_equal \
|
125
|
-
'SELECT max("ITEMS"."VAL") FROM "TEST"'
|
126
|
-
|
127
|
-
@d.order(:name.desc).sql.must_equal \
|
128
|
-
'SELECT * FROM "TEST" ORDER BY "NAME" DESC'
|
129
|
-
|
130
|
-
@d.select('TEST.NAME AS item_:name'.lit).sql.must_equal \
|
131
|
-
'SELECT TEST.NAME AS item_:name FROM "TEST"'
|
132
|
-
|
133
|
-
@d.select('"NAME"'.lit).sql.must_equal \
|
134
|
-
'SELECT "NAME" FROM "TEST"'
|
135
|
-
|
136
|
-
@d.select('max(TEST."NAME") AS "max_:name"'.lit).sql.must_equal \
|
137
|
-
'SELECT max(TEST."NAME") AS "max_:name" FROM "TEST"'
|
138
|
-
|
139
|
-
@d.select(:test[:ABC, 'hello']).sql.must_equal \
|
140
|
-
"SELECT test(\"ABC\", 'hello') FROM \"TEST\""
|
141
|
-
|
142
|
-
@d.select(:test[Sequel[:ABC][:DEF], 'hello']).sql.must_equal \
|
143
|
-
"SELECT test(\"ABC\".\"DEF\", 'hello') FROM \"TEST\""
|
144
|
-
|
145
|
-
@d.select(:test[Sequel[:ABC][:DEF], 'hello'].as(:X2)).sql.must_equal \
|
146
|
-
"SELECT test(\"ABC\".\"DEF\", 'hello') AS \"X2\" FROM \"TEST\""
|
147
|
-
|
148
|
-
@d.insert_sql(:val => 333).must_match \
|
149
|
-
/\AINSERT INTO "TEST" \("VAL"\) VALUES \(333\)( RETURNING NULL)?\z/
|
150
|
-
|
151
|
-
@d.insert_sql(:X => :Y).must_match \
|
152
|
-
/\AINSERT INTO "TEST" \("X"\) VALUES \("Y"\)( RETURNING NULL)?\z/
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should quote fields correctly when reversing the order if quoting identifiers" do
|
156
|
-
@d.reverse_order(:name).sql.must_equal \
|
157
|
-
'SELECT * FROM "TEST" ORDER BY "NAME" DESC'
|
158
|
-
|
159
|
-
@d.reverse_order(:name.desc).sql.must_equal \
|
160
|
-
'SELECT * FROM "TEST" ORDER BY "NAME" ASC'
|
161
|
-
|
162
|
-
@d.reverse_order(:name, :test.desc).sql.must_equal \
|
163
|
-
'SELECT * FROM "TEST" ORDER BY "NAME" DESC, "TEST" ASC'
|
164
|
-
|
165
|
-
@d.reverse_order(:name.desc, :test).sql.must_equal \
|
166
|
-
'SELECT * FROM "TEST" ORDER BY "NAME" ASC, "TEST" DESC'
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should support transactions" do
|
170
|
-
DB.transaction do
|
171
|
-
@d << {:name => 'abc', :val => 1}
|
172
|
-
end
|
173
|
-
|
174
|
-
@d.count.must_equal 1
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should have #transaction yield the connection" do
|
178
|
-
DB.transaction do |conn|
|
179
|
-
conn.wont_equal nil
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should correctly rollback transactions" do
|
184
|
-
proc do
|
185
|
-
DB.transaction do
|
186
|
-
@d << {:name => 'abc', :val => 1}
|
187
|
-
raise RuntimeError, 'asdf'
|
188
|
-
end
|
189
|
-
end.must_raise(RuntimeError)
|
190
|
-
|
191
|
-
@d.count.must_equal 0
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should handle returning inside of the block by committing" do
|
195
|
-
def DB.ret_commit
|
196
|
-
transaction do
|
197
|
-
self[:test] << {:name => 'abc'}
|
198
|
-
return
|
199
|
-
self[:test] << {:name => 'd'}
|
200
|
-
end
|
201
|
-
end
|
202
|
-
@d.count.must_equal 0
|
203
|
-
DB.ret_commit
|
204
|
-
@d.count.must_equal 1
|
205
|
-
DB.ret_commit
|
206
|
-
@d.count.must_equal 2
|
207
|
-
proc do
|
208
|
-
DB.transaction do
|
209
|
-
raise RuntimeError, 'asdf'
|
210
|
-
end
|
211
|
-
end.must_raise(RuntimeError)
|
212
|
-
|
213
|
-
@d.count.must_equal 2
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should quote and upcase reserved keywords" do
|
217
|
-
@d = DB[:testing]
|
218
|
-
@d.select(:select).sql.must_equal \
|
219
|
-
'SELECT "SELECT" FROM "TESTING"'
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "A Firebird dataset with a timestamp field" do
|
224
|
-
before do
|
225
|
-
@d = DB[:test3]
|
226
|
-
@d.delete
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should store milliseconds in time fields" do
|
230
|
-
t = Time.now
|
231
|
-
@d << {:val=>1, :time_stamp=>t}
|
232
|
-
@d.literal(@d[:val =>'1'][:time_stamp]).must_equal @d.literal(t)
|
233
|
-
@d[:val=>'1'][:time_stamp].usec.must_equal t.usec - t.usec % 100
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "A Firebird database" do
|
238
|
-
before do
|
239
|
-
@db = DB
|
240
|
-
@db.drop_table?(:posts)
|
241
|
-
@db.sqls.clear
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should allow us to name the sequences" do
|
245
|
-
@db.create_table(:posts){primary_key :id, :sequence_name => "seq_test"}
|
246
|
-
check_sqls do
|
247
|
-
@db.sqls.must_equal [
|
248
|
-
"DROP SEQUENCE SEQ_TEST",
|
249
|
-
"CREATE TABLE POSTS (ID integer PRIMARY KEY )",
|
250
|
-
"CREATE SEQUENCE SEQ_TEST",
|
251
|
-
" CREATE TRIGGER BI_POSTS_ID for POSTS\n ACTIVE BEFORE INSERT position 0\n as begin\n if ((new.ID is null) or (new.ID = 0)) then\n begin\n new.ID = next value for seq_test;\n end\n end\n\n"
|
252
|
-
]
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should allow us to set the starting position for the sequences" do
|
257
|
-
@db.create_table(:posts){primary_key :id, :sequence_start_position => 999}
|
258
|
-
check_sqls do
|
259
|
-
@db.sqls.must_equal [
|
260
|
-
"DROP SEQUENCE SEQ_POSTS_ID",
|
261
|
-
"CREATE TABLE POSTS (ID integer PRIMARY KEY )",
|
262
|
-
"CREATE SEQUENCE SEQ_POSTS_ID",
|
263
|
-
"ALTER SEQUENCE SEQ_POSTS_ID RESTART WITH 999",
|
264
|
-
" CREATE TRIGGER BI_POSTS_ID for POSTS\n ACTIVE BEFORE INSERT position 0\n as begin\n if ((new.ID is null) or (new.ID = 0)) then\n begin\n new.ID = next value for seq_posts_id;\n end\n end\n\n"
|
265
|
-
]
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should allow us to name and set the starting position for the sequences" do
|
270
|
-
@db.create_table(:posts){primary_key :id, :sequence_name => "seq_test", :sequence_start_position => 999}
|
271
|
-
check_sqls do
|
272
|
-
@db.sqls.must_equal [
|
273
|
-
"DROP SEQUENCE SEQ_TEST",
|
274
|
-
"CREATE TABLE POSTS (ID integer PRIMARY KEY )",
|
275
|
-
"CREATE SEQUENCE SEQ_TEST",
|
276
|
-
"ALTER SEQUENCE SEQ_TEST RESTART WITH 999",
|
277
|
-
" CREATE TRIGGER BI_POSTS_ID for POSTS\n ACTIVE BEFORE INSERT position 0\n as begin\n if ((new.ID is null) or (new.ID = 0)) then\n begin\n new.ID = next value for seq_test;\n end\n end\n\n"
|
278
|
-
]
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should allow us to name the triggers" do
|
283
|
-
@db.create_table(:posts){primary_key :id, :trigger_name => "trig_test"}
|
284
|
-
check_sqls do
|
285
|
-
@db.sqls.must_equal [
|
286
|
-
"DROP SEQUENCE SEQ_POSTS_ID",
|
287
|
-
"CREATE TABLE POSTS (ID integer PRIMARY KEY )",
|
288
|
-
"CREATE SEQUENCE SEQ_POSTS_ID",
|
289
|
-
" CREATE TRIGGER TRIG_TEST for POSTS\n ACTIVE BEFORE INSERT position 0\n as begin\n if ((new.ID is null) or (new.ID = 0)) then\n begin\n new.ID = next value for seq_posts_id;\n end\n end\n\n"
|
290
|
-
]
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
it "should allow us to not create the sequence" do
|
295
|
-
@db.create_table(:posts){primary_key :id, :create_sequence => false}
|
296
|
-
check_sqls do
|
297
|
-
@db.sqls.must_equal [
|
298
|
-
"CREATE TABLE POSTS (ID integer PRIMARY KEY )",
|
299
|
-
" CREATE TRIGGER BI_POSTS_ID for POSTS\n ACTIVE BEFORE INSERT position 0\n as begin\n if ((new.ID is null) or (new.ID = 0)) then\n begin\n new.ID = next value for seq_posts_id;\n end\n end\n\n"
|
300
|
-
]
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should allow us to not create the trigger" do
|
305
|
-
@db.create_table(:posts){primary_key :id, :create_trigger => false}
|
306
|
-
check_sqls do
|
307
|
-
@db.sqls.must_equal [
|
308
|
-
"DROP SEQUENCE SEQ_POSTS_ID",
|
309
|
-
"CREATE TABLE POSTS (ID integer PRIMARY KEY )",
|
310
|
-
"CREATE SEQUENCE SEQ_POSTS_ID",
|
311
|
-
]
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
it "should allow us to not create either the sequence nor the trigger" do
|
316
|
-
@db.create_table(:posts){primary_key :id, :create_sequence => false, :create_trigger => false}
|
317
|
-
check_sqls do
|
318
|
-
@db.sqls.must_equal [
|
319
|
-
"CREATE TABLE POSTS (ID integer PRIMARY KEY )"
|
320
|
-
]
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should support column operations" do
|
325
|
-
@db.create_table!(:test2){varchar :name, :size => 50; integer :val}
|
326
|
-
@db[:test2] << {}
|
327
|
-
@db[:test2].columns.must_equal [:name, :val]
|
328
|
-
|
329
|
-
@db.add_column :test2, :xyz, :varchar, :size => 50
|
330
|
-
@db[:test2].columns.must_equal [:name, :val, :xyz]
|
331
|
-
|
332
|
-
@db[:test2].columns.must_equal [:name, :val, :xyz]
|
333
|
-
@db.drop_column :test2, :xyz
|
334
|
-
|
335
|
-
@db[:test2].columns.must_equal [:name, :val]
|
336
|
-
|
337
|
-
@db[:test2].delete
|
338
|
-
@db.add_column :test2, :xyz, :varchar, :default => '000', :size => 50#, :create_domain => 'xyz_varchar'
|
339
|
-
@db[:test2] << {:name => 'mmm', :val => 111, :xyz => 'qqqq'}
|
340
|
-
|
341
|
-
@db[:test2].columns.must_equal [:name, :val, :xyz]
|
342
|
-
@db.rename_column :test2, :xyz, :zyx
|
343
|
-
@db[:test2].columns.must_equal [:name, :val, :zyx]
|
344
|
-
@db[:test2].first[:zyx].must_equal 'qqqq'
|
345
|
-
|
346
|
-
@db.add_column :test2, :xyz, :decimal, :elements => [12, 2]
|
347
|
-
@db[:test2].delete
|
348
|
-
@db[:test2] << {:name => 'mmm', :val => 111, :xyz => 56.4}
|
349
|
-
@db.set_column_type :test2, :xyz, :varchar, :size => 50
|
350
|
-
|
351
|
-
@db[:test2].first[:xyz].must_equal "56.40"
|
352
|
-
end
|
353
|
-
|
354
|
-
it "should allow us to retrieve the primary key for a table" do
|
355
|
-
@db.create_table!(:test2){primary_key :id}
|
356
|
-
@db.primary_key(:test2).must_equal ["id"]
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
describe "Postgres::Dataset#insert" do
|
361
|
-
before do
|
362
|
-
@ds = DB[:test5]
|
363
|
-
@ds.delete
|
364
|
-
end
|
365
|
-
|
366
|
-
it "should have insert_returning_sql use the RETURNING keyword" do
|
367
|
-
@ds.insert_returning_sql(:XID, :val=>10).must_equal "INSERT INTO TEST5 (VAL) VALUES (10) RETURNING XID"
|
368
|
-
@ds.insert_returning_sql('*'.lit, :val=>10).must_equal "INSERT INTO TEST5 (VAL) VALUES (10) RETURNING *"
|
369
|
-
@ds.insert_returning_sql('NULL'.lit, :val=>10).must_equal "INSERT INTO TEST5 (VAL) VALUES (10) RETURNING NULL"
|
370
|
-
end
|
371
|
-
|
372
|
-
it "should correctly return the inserted record's primary key value" do
|
373
|
-
value1 = 10
|
374
|
-
id1 = @ds.insert(:val=>value1)
|
375
|
-
@ds.first(:XID=>id1)[:val].must_equal value1
|
376
|
-
value2 = 20
|
377
|
-
id2 = @ds.insert(:val=>value2)
|
378
|
-
@ds.first(:XID=>id2)[:val].must_equal value2
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should return nil if the table has no primary key" do
|
382
|
-
ds = DB[:test]
|
383
|
-
ds.delete
|
384
|
-
ds.insert(:name=>'a').must_be_nil
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
describe "Postgres::Dataset#insert" do
|
389
|
-
before do
|
390
|
-
@ds = DB[:test6]
|
391
|
-
@ds.delete
|
392
|
-
end
|
393
|
-
|
394
|
-
it "should insert and retrieve a blob successfully" do
|
395
|
-
value1 = "\1\2\2\2\2222\2\2\2"
|
396
|
-
value2 = "abcd"
|
397
|
-
value3 = "efgh"
|
398
|
-
value4 = "ijkl"
|
399
|
-
id1 = @ds.insert(:val=>value1, :val2=>value2, :val3=>value3, :val4=>value4)
|
400
|
-
@ds.first(:XID=>id1)[:val].must_equal value1
|
401
|
-
@ds.first(:XID=>id1)[:val2].must_equal value2
|
402
|
-
@ds.first(:XID=>id1)[:val3].must_equal value3
|
403
|
-
@ds.first(:XID=>id1)[:val4].must_equal value4
|
404
|
-
end
|
405
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
SEQUEL_ADAPTER_TEST = :informix
|
2
|
-
|
3
|
-
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
4
|
-
|
5
|
-
if DB.table_exists?(:test)
|
6
|
-
DB.drop_table :test
|
7
|
-
end
|
8
|
-
DB.create_table :test do
|
9
|
-
text :name
|
10
|
-
integer :value
|
11
|
-
|
12
|
-
index :value
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "A Informix database" do
|
16
|
-
it "should provide disconnect functionality" do
|
17
|
-
DB.execute("select user from dual")
|
18
|
-
DB.pool.size.must_equal 1
|
19
|
-
DB.disconnect
|
20
|
-
DB.pool.size.must_equal 0
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "A Informix dataset" do
|
25
|
-
before do
|
26
|
-
@d = DB[:test]
|
27
|
-
@d.delete # remove all records
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should return the correct record count" do
|
31
|
-
@d.count.must_equal 0
|
32
|
-
@d << {:name => 'abc', :value => 123}
|
33
|
-
@d << {:name => 'abc', :value => 456}
|
34
|
-
@d << {:name => 'def', :value => 789}
|
35
|
-
@d.count.must_equal 3
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return the correct records" do
|
39
|
-
@d.to_a.must_equal []
|
40
|
-
@d << {:name => 'abc', :value => 123}
|
41
|
-
@d << {:name => 'abc', :value => 456}
|
42
|
-
@d << {:name => 'def', :value => 789}
|
43
|
-
|
44
|
-
@d.order(:value).to_a.must_equal [
|
45
|
-
{:name => 'abc', :value => 123},
|
46
|
-
{:name => 'abc', :value => 456},
|
47
|
-
{:name => 'def', :value => 789}
|
48
|
-
]
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should update records correctly" do
|
52
|
-
@d << {:name => 'abc', :value => 123}
|
53
|
-
@d << {:name => 'abc', :value => 456}
|
54
|
-
@d << {:name => 'def', :value => 789}
|
55
|
-
@d.filter(:name => 'abc').update(:value => 530)
|
56
|
-
|
57
|
-
# the third record should stay the same
|
58
|
-
# floating-point precision bullshit
|
59
|
-
@d[:name => 'def'][:value].must_equal 789
|
60
|
-
@d.filter(:value => 530).count.must_equal 2
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should delete records correctly" do
|
64
|
-
@d << {:name => 'abc', :value => 123}
|
65
|
-
@d << {:name => 'abc', :value => 456}
|
66
|
-
@d << {:name => 'def', :value => 789}
|
67
|
-
@d.filter(:name => 'abc').delete
|
68
|
-
|
69
|
-
@d.count.must_equal 1
|
70
|
-
@d.first[:name].must_equal 'def'
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should be able to literalize booleans" do
|
74
|
-
@d.literal(true)
|
75
|
-
@d.literal(false)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should support transactions" do
|
79
|
-
DB.transaction do
|
80
|
-
@d << {:name => 'abc', :value => 1}
|
81
|
-
end
|
82
|
-
|
83
|
-
@d.count.must_equal 1
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should support #first and #last" do
|
87
|
-
@d << {:name => 'abc', :value => 123}
|
88
|
-
@d << {:name => 'abc', :value => 456}
|
89
|
-
@d << {:name => 'def', :value => 789}
|
90
|
-
|
91
|
-
@d.order(:value).first.must_equal(:name => 'abc', :value => 123)
|
92
|
-
@d.order(:value).last.must_equal(:name => 'def', :value => 789)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should return last inserted id" do
|
96
|
-
first = @d.insert :name => 'abc', :value => 123
|
97
|
-
second = @d.insert :name => 'abc', :value => 123
|
98
|
-
(second - first).must_equal 1
|
99
|
-
end
|
100
|
-
end
|