sequel 3.48.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +114 -0
- data/Rakefile +10 -7
- data/doc/association_basics.rdoc +25 -23
- data/doc/code_order.rdoc +7 -0
- data/doc/core_extensions.rdoc +0 -10
- data/doc/object_model.rdoc +4 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.0.0.txt +262 -0
- data/doc/security.rdoc +0 -28
- data/doc/testing.rdoc +8 -14
- data/lib/sequel/adapters/ado.rb +7 -11
- data/lib/sequel/adapters/ado/access.rb +8 -8
- data/lib/sequel/adapters/ado/mssql.rb +4 -4
- data/lib/sequel/adapters/amalgalite.rb +6 -6
- data/lib/sequel/adapters/cubrid.rb +7 -7
- data/lib/sequel/adapters/db2.rb +5 -9
- data/lib/sequel/adapters/dbi.rb +2 -6
- data/lib/sequel/adapters/do.rb +4 -4
- data/lib/sequel/adapters/firebird.rb +4 -4
- data/lib/sequel/adapters/ibmdb.rb +8 -8
- data/lib/sequel/adapters/informix.rb +2 -10
- data/lib/sequel/adapters/jdbc.rb +17 -17
- data/lib/sequel/adapters/jdbc/as400.rb +2 -2
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/informix.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
- data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
- data/lib/sequel/adapters/mock.rb +7 -7
- data/lib/sequel/adapters/mysql.rb +3 -3
- data/lib/sequel/adapters/mysql2.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +2 -6
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -5
- data/lib/sequel/adapters/oracle.rb +13 -17
- data/lib/sequel/adapters/postgres.rb +20 -25
- data/lib/sequel/adapters/shared/cubrid.rb +3 -3
- data/lib/sequel/adapters/shared/db2.rb +2 -2
- data/lib/sequel/adapters/shared/firebird.rb +7 -7
- data/lib/sequel/adapters/shared/mssql.rb +9 -9
- data/lib/sequel/adapters/shared/mysql.rb +29 -13
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
- data/lib/sequel/adapters/shared/oracle.rb +22 -13
- data/lib/sequel/adapters/shared/postgres.rb +61 -46
- data/lib/sequel/adapters/shared/sqlite.rb +9 -9
- data/lib/sequel/adapters/sqlite.rb +17 -11
- data/lib/sequel/adapters/swift.rb +3 -3
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +8 -8
- data/lib/sequel/ast_transformer.rb +3 -1
- data/lib/sequel/connection_pool.rb +4 -2
- data/lib/sequel/connection_pool/sharded_single.rb +2 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
- data/lib/sequel/connection_pool/threaded.rb +7 -7
- data/lib/sequel/core.rb +4 -67
- data/lib/sequel/database.rb +1 -0
- data/lib/sequel/database/connecting.rb +2 -8
- data/lib/sequel/database/dataset.rb +2 -7
- data/lib/sequel/database/dataset_defaults.rb +0 -18
- data/lib/sequel/database/features.rb +4 -4
- data/lib/sequel/database/misc.rb +6 -8
- data/lib/sequel/database/query.rb +5 -61
- data/lib/sequel/database/schema_generator.rb +22 -20
- data/lib/sequel/database/schema_methods.rb +48 -20
- data/lib/sequel/database/transactions.rb +7 -17
- data/lib/sequel/dataset.rb +2 -0
- data/lib/sequel/dataset/actions.rb +23 -91
- data/lib/sequel/dataset/features.rb +1 -4
- data/lib/sequel/dataset/graph.rb +3 -47
- data/lib/sequel/dataset/misc.rb +4 -33
- data/lib/sequel/dataset/prepared_statements.rb +3 -1
- data/lib/sequel/dataset/query.rb +116 -240
- data/lib/sequel/dataset/sql.rb +19 -97
- data/lib/sequel/deprecated.rb +0 -16
- data/lib/sequel/exceptions.rb +0 -3
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/columns_introspection.rb +1 -12
- data/lib/sequel/extensions/constraint_validations.rb +3 -3
- data/lib/sequel/extensions/core_extensions.rb +0 -9
- data/lib/sequel/extensions/date_arithmetic.rb +1 -2
- data/lib/sequel/extensions/graph_each.rb +11 -0
- data/lib/sequel/extensions/migration.rb +5 -5
- data/lib/sequel/extensions/null_dataset.rb +11 -13
- data/lib/sequel/extensions/pagination.rb +3 -6
- data/lib/sequel/extensions/pg_array.rb +6 -4
- data/lib/sequel/extensions/pg_array_ops.rb +35 -1
- data/lib/sequel/extensions/pg_json.rb +12 -2
- data/lib/sequel/extensions/pg_json_ops.rb +266 -0
- data/lib/sequel/extensions/pg_range.rb +2 -2
- data/lib/sequel/extensions/pg_range_ops.rb +0 -8
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/pretty_table.rb +0 -4
- data/lib/sequel/extensions/query.rb +3 -8
- data/lib/sequel/extensions/schema_caching.rb +0 -7
- data/lib/sequel/extensions/schema_dumper.rb +10 -17
- data/lib/sequel/extensions/select_remove.rb +0 -4
- data/lib/sequel/extensions/set_overrides.rb +28 -0
- data/lib/sequel/extensions/to_dot.rb +6 -10
- data/lib/sequel/model.rb +6 -7
- data/lib/sequel/model/associations.rb +127 -182
- data/lib/sequel/model/base.rb +88 -211
- data/lib/sequel/model/errors.rb +0 -13
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/no_core_ext.rb +0 -1
- data/lib/sequel/plugins/after_initialize.rb +11 -17
- data/lib/sequel/plugins/association_autoreloading.rb +1 -47
- data/lib/sequel/plugins/association_dependencies.rb +2 -2
- data/lib/sequel/plugins/auto_validations.rb +2 -8
- data/lib/sequel/plugins/blacklist_security.rb +32 -2
- data/lib/sequel/plugins/caching.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/composition.rb +10 -8
- data/lib/sequel/plugins/constraint_validations.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +4 -0
- data/lib/sequel/plugins/defaults_setter.rb +8 -6
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/force_encoding.rb +13 -8
- data/lib/sequel/plugins/hook_class_methods.rb +1 -7
- data/lib/sequel/plugins/json_serializer.rb +13 -74
- data/lib/sequel/plugins/lazy_attributes.rb +2 -4
- data/lib/sequel/plugins/list.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +4 -11
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/optimistic_locking.rb +3 -5
- data/lib/sequel/plugins/pg_array_associations.rb +453 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
- data/lib/sequel/plugins/prepared_statements.rb +1 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +5 -4
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +7 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -2
- data/lib/sequel/plugins/tree.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +19 -4
- data/lib/sequel/plugins/validation_class_methods.rb +0 -30
- data/lib/sequel/plugins/validation_helpers.rb +13 -31
- data/lib/sequel/plugins/xml_serializer.rb +18 -57
- data/lib/sequel/sql.rb +20 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/db2_spec.rb +14 -23
- data/spec/adapters/firebird_spec.rb +25 -29
- data/spec/adapters/informix_spec.rb +11 -14
- data/spec/adapters/mssql_spec.rb +71 -77
- data/spec/adapters/mysql_spec.rb +165 -172
- data/spec/adapters/oracle_spec.rb +36 -39
- data/spec/adapters/postgres_spec.rb +175 -100
- data/spec/adapters/spec_helper.rb +13 -11
- data/spec/adapters/sqlite_spec.rb +36 -44
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +55 -55
- data/spec/core/dataset_spec.rb +45 -249
- data/spec/core/deprecated_spec.rb +0 -8
- data/spec/core/expression_filters_spec.rb +23 -5
- data/spec/core/object_graph_spec.rb +4 -66
- data/spec/core/schema_spec.rb +35 -12
- data/spec/core/spec_helper.rb +3 -2
- data/spec/core_extensions_spec.rb +17 -19
- data/spec/extensions/arbitrary_servers_spec.rb +2 -3
- data/spec/extensions/association_dependencies_spec.rb +14 -14
- data/spec/extensions/auto_validations_spec.rb +7 -0
- data/spec/extensions/blacklist_security_spec.rb +5 -5
- data/spec/extensions/blank_spec.rb +2 -0
- data/spec/extensions/class_table_inheritance_spec.rb +2 -2
- data/spec/extensions/columns_introspection_spec.rb +2 -29
- data/spec/extensions/composition_spec.rb +10 -17
- data/spec/extensions/core_refinements_spec.rb +5 -1
- data/spec/extensions/dataset_associations_spec.rb +18 -0
- data/spec/extensions/date_arithmetic_spec.rb +2 -2
- data/spec/extensions/defaults_setter_spec.rb +9 -9
- data/spec/extensions/dirty_spec.rb +0 -5
- data/spec/extensions/eval_inspect_spec.rb +2 -0
- data/spec/extensions/force_encoding_spec.rb +2 -18
- data/spec/extensions/hash_aliases_spec.rb +8 -0
- data/spec/extensions/hook_class_methods_spec.rb +39 -58
- data/spec/extensions/inflector_spec.rb +2 -0
- data/spec/extensions/instance_filters_spec.rb +8 -8
- data/spec/extensions/json_serializer_spec.rb +1 -41
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +106 -109
- data/spec/extensions/migration_spec.rb +2 -0
- data/spec/extensions/named_timezones_spec.rb +1 -0
- data/spec/extensions/pg_array_associations_spec.rb +603 -0
- data/spec/extensions/pg_array_ops_spec.rb +25 -0
- data/spec/extensions/pg_array_spec.rb +9 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +1 -0
- data/spec/extensions/pg_json_ops_spec.rb +131 -0
- data/spec/extensions/pg_json_spec.rb +10 -4
- data/spec/extensions/pg_range_ops_spec.rb +2 -5
- data/spec/extensions/pg_range_spec.rb +6 -2
- data/spec/extensions/pg_row_ops_spec.rb +2 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
- data/spec/extensions/rcte_tree_spec.rb +15 -15
- data/spec/extensions/schema_dumper_spec.rb +0 -1
- data/spec/extensions/schema_spec.rb +9 -9
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +18 -29
- data/spec/extensions/set_overrides_spec.rb +4 -0
- data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
- data/spec/extensions/single_table_inheritance_spec.rb +4 -4
- data/spec/extensions/spec_helper.rb +8 -9
- data/spec/extensions/sql_expr_spec.rb +2 -0
- data/spec/extensions/string_date_time_spec.rb +2 -0
- data/spec/extensions/string_stripper_spec.rb +2 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
- data/spec/extensions/thread_local_timezones_spec.rb +2 -0
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +24 -24
- data/spec/extensions/tree_spec.rb +7 -7
- data/spec/extensions/typecast_on_load_spec.rb +8 -1
- data/spec/extensions/update_primary_key_spec.rb +10 -10
- data/spec/extensions/validation_class_methods_spec.rb +10 -39
- data/spec/extensions/validation_helpers_spec.rb +29 -47
- data/spec/extensions/xml_serializer_spec.rb +1 -23
- data/spec/integration/associations_test.rb +231 -40
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +64 -64
- data/spec/integration/eager_loader_test.rb +28 -28
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +2 -2
- data/spec/integration/plugin_test.rb +21 -21
- data/spec/integration/prepared_statement_test.rb +7 -7
- data/spec/integration/schema_test.rb +115 -110
- data/spec/integration/spec_helper.rb +17 -27
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +10 -10
- data/spec/integration/type_test.rb +2 -2
- data/spec/model/association_reflection_spec.rb +2 -28
- data/spec/model/associations_spec.rb +239 -188
- data/spec/model/base_spec.rb +27 -68
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +160 -172
- data/spec/model/hooks_spec.rb +62 -79
- data/spec/model/model_spec.rb +36 -51
- data/spec/model/plugins_spec.rb +5 -19
- data/spec/model/record_spec.rb +125 -151
- data/spec/model/spec_helper.rb +8 -6
- data/spec/model/validations_spec.rb +4 -17
- data/spec/spec_config.rb +2 -10
- metadata +50 -56
- data/lib/sequel/deprecated_core_extensions.rb +0 -135
- data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
- data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
- data/lib/sequel/plugins/identity_map.rb +0 -260
- data/lib/sequel_core.rb +0 -2
- data/lib/sequel_model.rb +0 -2
- data/spec/extensions/association_autoreloading_spec.rb +0 -102
- data/spec/extensions/identity_map_spec.rb +0 -337
- data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
- data/spec/extensions/pg_statement_cache_spec.rb +0 -208
- data/spec/rcov.opts +0 -8
- data/spec/spec_config.rb.example +0 -10
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
|
-
|
3
|
-
describe "pg_auto_parameterize extension" do
|
4
|
-
before do
|
5
|
-
@db = Sequel.connect('mock://postgres', :quote_identifiers=>false)
|
6
|
-
@db.synchronize{|c| def c.escape_bytea(v) v*2 end}
|
7
|
-
@db.extend_datasets{def use_cursor(*) clone end}
|
8
|
-
@db.extension :pg_auto_parameterize
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should automatically parameterize queries strings, blobs, numerics, dates, and times" do
|
12
|
-
pr = proc do |ds, sql, *args|
|
13
|
-
arg = args[0]
|
14
|
-
parg = args[1] || arg
|
15
|
-
s = ds.filter(:a=>arg).sql
|
16
|
-
s.should == sql
|
17
|
-
s.args.should == (parg == :nil ? nil : [parg])
|
18
|
-
end
|
19
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::int4)', 1)
|
20
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::int8)', 18446744073709551616)
|
21
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::double precision)', 1.1)
|
22
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::numeric)', BigDecimal.new('1.01'))
|
23
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1)', "a")
|
24
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::bytea)', Sequel.blob("a\0b"))
|
25
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = 1)', Sequel.lit('1'), :nil)
|
26
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::time)', Sequel::SQLTime.create(1, 2, 3, 500000))
|
27
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::date)', Date.today)
|
28
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::timestamp)', DateTime.new(2012, 1, 2, 3, 4, 5))
|
29
|
-
pr.call(@db[:table], 'SELECT * FROM table WHERE (a = $1::timestamp)', Time.utc(2012, 1, 2, 3, 4, 5))
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should extract parameters from query string when executing" do
|
33
|
-
@db.fetch = {:a=>1}
|
34
|
-
@db.numrows = 1
|
35
|
-
@db.autoid = 1
|
36
|
-
|
37
|
-
@db[:table].filter(:a=>1).all.should == [{:a=>1}]
|
38
|
-
@db.sqls.should == ['SELECT * FROM table WHERE (a = $1::int4) -- args: [1]']
|
39
|
-
|
40
|
-
@db[:table].filter(:a=>1).update(:b=>'a').should == 1
|
41
|
-
@db.sqls.should == ['UPDATE table SET b = $1 WHERE (a = $2::int4) -- args: ["a", 1]']
|
42
|
-
|
43
|
-
@db[:table].filter(:a=>1).delete.should == 1
|
44
|
-
@db.sqls.should == ['DELETE FROM table WHERE (a = $1::int4) -- args: [1]']
|
45
|
-
|
46
|
-
@db[:table].insert(:a=>1).should == 1
|
47
|
-
@db.sqls.should == ['INSERT INTO table (a) VALUES ($1::int4) RETURNING id -- args: [1]']
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should not automatically paramiterize if no_auto_parameterize is used" do
|
51
|
-
@db[:table].no_auto_parameterize.filter(:a=>1).sql.should == 'SELECT * FROM table WHERE (a = 1)'
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should not automatically parameterize prepared statements" do
|
55
|
-
@db[:table].filter(:a=>1, :b=>:$b).prepare(:select).sql.should =~ /SELECT \* FROM table WHERE \(\((a = 1|b = \$b)\) AND \((a = 1|b = \$b)\)\)/
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should show args with string when inspecting SQL " do
|
59
|
-
@db[:table].filter(:a=>1).sql.inspect.should == '"SELECT * FROM table WHERE (a = $1::int4); [1]"'
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not auto parameterize when using cursors" do
|
63
|
-
@db[:table].filter(:a=>1).use_cursor.opts[:no_auto_parameterize].should be_true
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should have a working create_view" do
|
67
|
-
@db.create_view :foo, @db[:table].filter(:a=>1)
|
68
|
-
@db.sqls.should == ["CREATE VIEW foo AS SELECT * FROM table WHERE (a = 1)"]
|
69
|
-
end
|
70
|
-
end
|
@@ -1,208 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
|
-
|
3
|
-
Sequel::Postgres::StatementCache::PGError = Sequel::Error
|
4
|
-
|
5
|
-
describe "pg_statement_cache and pg_auto_parameterize extensions" do
|
6
|
-
before do
|
7
|
-
@dbp = proc do |opts|
|
8
|
-
@db = Sequel.connect 'mock://postgres', :quote_identifiers=>false, :statement_cache_opts=>{:max_size=>4}.merge(opts),
|
9
|
-
:after_connect=>(proc do |c|
|
10
|
-
c.extend(Module.new do
|
11
|
-
def execute_query(sql, args)
|
12
|
-
raise Sequel::Postgres::StatementCache::PGError if @db.exec_raise
|
13
|
-
@db.execute(sql, :arguments=>args, :no_eq=>true)
|
14
|
-
end
|
15
|
-
def prepare(name, sql)
|
16
|
-
raise Sequel::Postgres::StatementCache::PGError if sql =~ /prepare_raise/
|
17
|
-
@ps ||= {}
|
18
|
-
@ps[name] = sql
|
19
|
-
@db._sqls << "PREPARE #{name} AS #{sql}"
|
20
|
-
end
|
21
|
-
def exec_prepared(name, args=nil)
|
22
|
-
@db._sqls << "EXECUTE #{name} (#{@ps[name]})#{" -- args: #{args.inspect}" if args}"
|
23
|
-
end
|
24
|
-
end)
|
25
|
-
end)
|
26
|
-
@db.extension :pg_auto_parameterize, :pg_statement_cache
|
27
|
-
@db.extend(Module.new do
|
28
|
-
attr_accessor :exec_raise
|
29
|
-
def _execute(c, sql, opts={})
|
30
|
-
opts[:no_eq] ? super : c.send(:execute_query, sql, opts[:arguments])
|
31
|
-
end
|
32
|
-
def _sqls
|
33
|
-
@sqls
|
34
|
-
end
|
35
|
-
def statement_cache
|
36
|
-
synchronize{|c| c.statement_cache}
|
37
|
-
end
|
38
|
-
end)
|
39
|
-
@db
|
40
|
-
end
|
41
|
-
@db = @dbp.call({})
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should automatically prepare statements executed multiple times" do
|
45
|
-
@db[:table].filter(:b=>2).all
|
46
|
-
3.times{|i| @db[:table].filter(:a=>i).all}
|
47
|
-
@db.sqls.should == ["SELECT * FROM table WHERE (b = $1::int4) -- args: [2]",
|
48
|
-
"SELECT * FROM table WHERE (a = $1::int4) -- args: [0]",
|
49
|
-
"PREPARE sequel_pgap_2 AS SELECT * FROM table WHERE (a = $1::int4)",
|
50
|
-
"EXECUTE sequel_pgap_2 (SELECT * FROM table WHERE (a = $1::int4)) -- args: [1]",
|
51
|
-
"EXECUTE sequel_pgap_2 (SELECT * FROM table WHERE (a = $1::int4)) -- args: [2]"]
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should work correctly for queries without parameters" do
|
55
|
-
@db[:table].filter(:b).all
|
56
|
-
3.times{|i| @db[:table].filter(:a).all}
|
57
|
-
@db.sqls.should == ["SELECT * FROM table WHERE b",
|
58
|
-
"SELECT * FROM table WHERE a",
|
59
|
-
"PREPARE sequel_pgap_2 AS SELECT * FROM table WHERE a",
|
60
|
-
"EXECUTE sequel_pgap_2 (SELECT * FROM table WHERE a)",
|
61
|
-
"EXECUTE sequel_pgap_2 (SELECT * FROM table WHERE a)"]
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should correctly return the size of the cache" do
|
65
|
-
sc = @db.statement_cache
|
66
|
-
sc.size.should == 0
|
67
|
-
@db[:table].filter(:b=>2).all
|
68
|
-
sc.size.should == 1
|
69
|
-
3.times{|i| @db[:table].filter(:a=>i).all}
|
70
|
-
sc.size.should == 2
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should correctly clear the cache" do
|
74
|
-
sc = @db.statement_cache
|
75
|
-
sc.size.should == 0
|
76
|
-
@db[:table].filter(:b=>2).all
|
77
|
-
sc.size.should == 1
|
78
|
-
3.times{|i| @db[:table].filter(:a=>i).all}
|
79
|
-
sc.size.should == 2
|
80
|
-
sc.clear
|
81
|
-
sc.size.should == 0
|
82
|
-
3.times{|i| @db[:table].filter(:a=>i).all}
|
83
|
-
sc.size.should == 1
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should correctly yield each entry in the cache" do
|
87
|
-
@db[:table].filter(:b=>2).all
|
88
|
-
3.times{|i| @db[:table].filter(:a=>i).all}
|
89
|
-
a = []
|
90
|
-
@db.statement_cache.each{|k, v| a << [k, v]}
|
91
|
-
a.sort!
|
92
|
-
a[0][0].should == "SELECT * FROM table WHERE (a = $1::int4)"
|
93
|
-
a[1][0].should == "SELECT * FROM table WHERE (b = $1::int4)"
|
94
|
-
s1 = a[1][1]
|
95
|
-
s1.cache_id.should == 1
|
96
|
-
s1.num_executes.should == 1
|
97
|
-
s1 = a[0][1]
|
98
|
-
s1.cache_id.should == 2
|
99
|
-
s1.num_executes.should == 3
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should automatically cleanup the cache when it goes beyond its maximum size" do
|
103
|
-
sc = @db.statement_cache
|
104
|
-
4.times{|i| @db[:table].filter(:"a#{i}"=>1).all}
|
105
|
-
sc.size.should == 4
|
106
|
-
@db[:table].filter(:b=>1).all
|
107
|
-
sc.size.should == 2
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should clear statement caches when altering tables" do
|
111
|
-
@db[:table].filter(:b=>2).all
|
112
|
-
sc = @db.statement_cache
|
113
|
-
@db.alter_table(:foo){drop_column :bar}
|
114
|
-
sc.size.should == 0
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should clear statement caches when dropping tables" do
|
118
|
-
@db[:table].filter(:b=>2).all
|
119
|
-
sc = @db.statement_cache
|
120
|
-
@db.drop_table(:foo)
|
121
|
-
sc.size.should == 0
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should deallocate prepared statements when clearing the cache" do
|
125
|
-
3.times{|i| @db[:table].filter(:a=>i).all}
|
126
|
-
@db.sqls
|
127
|
-
@db.statement_cache.clear
|
128
|
-
@db.sqls.should == ["DEALLOCATE sequel_pgap_1"]
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should deallocate prepared statements when cleaning up the cache" do
|
132
|
-
@db = @dbp.call(:sorter=>proc{|t, s| -s.num_executes})
|
133
|
-
4.times{|i| @db[:table].filter(:"a#{i}"=>1).all}
|
134
|
-
@db[:table].filter(:a0=>1).all
|
135
|
-
@db.sqls
|
136
|
-
@db[:table].filter(:b=>1).all
|
137
|
-
@db.sqls.should == ["DEALLOCATE sequel_pgap_1", "SELECT * FROM table WHERE (b = $1::int4) -- args: [1]"]
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should not deallocate nonprepared statements when clearing the cache" do
|
141
|
-
4.times{|i| @db[:table].filter(:"a#{i}"=>1).all}
|
142
|
-
@db.sqls
|
143
|
-
@db.statement_cache.clear
|
144
|
-
@db.sqls.should == []
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should not deallocate nonprepared statements when cleaning up the cache" do
|
148
|
-
@db = @dbp.call(:sorter=>proc{|t, s| -s.num_executes})
|
149
|
-
4.times{|i| @db[:table].filter(:"a#{i}"=>1).all}
|
150
|
-
@db.sqls
|
151
|
-
@db[:table].filter(:b=>1).all
|
152
|
-
@db.sqls.should == ["SELECT * FROM table WHERE (b = $1::int4) -- args: [1]"]
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should have a configurable max_size and min_size" do
|
156
|
-
@db = @dbp.call(:max_size=>10, :min_size=>2)
|
157
|
-
10.times{|i| @db[:table].filter(:"a#{i}"=>1).all}
|
158
|
-
sc = @db.statement_cache
|
159
|
-
sc.size.should == 10
|
160
|
-
@db[:table].filter(:b=>1).all
|
161
|
-
sc.size.should == 2
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should have a configurable prepare_after" do
|
165
|
-
@db = @dbp.call(:prepare_after=>3)
|
166
|
-
4.times{|i| @db[:table].filter(:a=>i).all}
|
167
|
-
@db.sqls.should == ["SELECT * FROM table WHERE (a = $1::int4) -- args: [0]",
|
168
|
-
"SELECT * FROM table WHERE (a = $1::int4) -- args: [1]",
|
169
|
-
"PREPARE sequel_pgap_1 AS SELECT * FROM table WHERE (a = $1::int4)",
|
170
|
-
"EXECUTE sequel_pgap_1 (SELECT * FROM table WHERE (a = $1::int4)) -- args: [2]",
|
171
|
-
"EXECUTE sequel_pgap_1 (SELECT * FROM table WHERE (a = $1::int4)) -- args: [3]"]
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should have a configurable sorter" do
|
175
|
-
@db = @dbp.call(:sorter=>proc{|t, s| s.num_executes})
|
176
|
-
4.times{|i| (i+1).times{@db[:table].filter(:"a#{i}"=>1).all}}
|
177
|
-
@db[:table].filter(:b=>1).all
|
178
|
-
sc = @db.statement_cache
|
179
|
-
a = []
|
180
|
-
sc.each{|k, v| a << [k, v]}
|
181
|
-
a.sort!
|
182
|
-
a[0][0].should == "SELECT * FROM table WHERE (a3 = $1::int4)"
|
183
|
-
a[1][0].should == "SELECT * FROM table WHERE (b = $1::int4)"
|
184
|
-
s1 = a[1][1]
|
185
|
-
s1.num_executes.should == 1
|
186
|
-
s1 = a[0][1]
|
187
|
-
s1.cache_id.should == 4
|
188
|
-
s1.num_executes.should == 4
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should ignore errors when preparing queries" do
|
192
|
-
3.times{|i| @db[:table].filter(:prepare_raise=>1).all}
|
193
|
-
@db.sqls.should == ["SELECT * FROM table WHERE (prepare_raise = $1::int4) -- args: [1]",
|
194
|
-
"SELECT * FROM table WHERE (prepare_raise = $1::int4) -- args: [1]",
|
195
|
-
"SELECT * FROM table WHERE (prepare_raise = $1::int4) -- args: [1]"]
|
196
|
-
end
|
197
|
-
|
198
|
-
it "should ignore errors when deallocating queries" do
|
199
|
-
3.times{|i| @db[:table].filter(:a=>1).all}
|
200
|
-
@db.exec_raise = true
|
201
|
-
@db.statement_cache.clear
|
202
|
-
@db.sqls.should == ["SELECT * FROM table WHERE (a = $1::int4) -- args: [1]",
|
203
|
-
"PREPARE sequel_pgap_1 AS SELECT * FROM table WHERE (a = $1::int4)",
|
204
|
-
"EXECUTE sequel_pgap_1 (SELECT * FROM table WHERE (a = $1::int4)) -- args: [1]",
|
205
|
-
"EXECUTE sequel_pgap_1 (SELECT * FROM table WHERE (a = $1::int4)) -- args: [1]"]
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
data/spec/rcov.opts
DELETED
data/spec/spec_config.rb.example
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# database objects for running adapter specs
|
2
|
-
# ADO_DB = Sequel.connect(:adapter => 'ado', :driver => "{Microsoft Access Driver (*.mdb)}; DBQ=c:\\Nwind.mdb")
|
3
|
-
# INFORMIX_DB = Sequel.connect('informix://localhost/mydb')
|
4
|
-
# INTEGRATION_URL = 'sqlite:/'
|
5
|
-
# MYSQL_USER = 'root'
|
6
|
-
# MYSQL_URL = "mysql://#{MYSQL_USER}@localhost/sandbox"
|
7
|
-
# MYSQL_SOCKET_FILE = '/tmp/mysql.sock'
|
8
|
-
# ORACLE_DB = Sequel.connect('oracle://hr:hr@localhost/XE')
|
9
|
-
# POSTGRES_URL = 'postgres://postgres:postgres@localhost:5432/reality_spec'
|
10
|
-
# SQLITE_URL = 'sqlite:/'
|