sequel 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGELOG +76 -0
  2. data/Rakefile +2 -2
  3. data/bin/sequel +9 -4
  4. data/doc/opening_databases.rdoc +279 -0
  5. data/doc/release_notes/3.2.0.txt +268 -0
  6. data/doc/virtual_rows.rdoc +42 -51
  7. data/lib/sequel/adapters/ado.rb +2 -5
  8. data/lib/sequel/adapters/db2.rb +5 -0
  9. data/lib/sequel/adapters/do.rb +3 -0
  10. data/lib/sequel/adapters/firebird.rb +6 -4
  11. data/lib/sequel/adapters/informix.rb +5 -3
  12. data/lib/sequel/adapters/jdbc.rb +10 -8
  13. data/lib/sequel/adapters/jdbc/h2.rb +17 -4
  14. data/lib/sequel/adapters/mysql.rb +6 -19
  15. data/lib/sequel/adapters/odbc.rb +14 -18
  16. data/lib/sequel/adapters/openbase.rb +8 -0
  17. data/lib/sequel/adapters/shared/mssql.rb +14 -8
  18. data/lib/sequel/adapters/shared/mysql.rb +53 -28
  19. data/lib/sequel/adapters/shared/oracle.rb +21 -12
  20. data/lib/sequel/adapters/shared/postgres.rb +46 -26
  21. data/lib/sequel/adapters/shared/progress.rb +10 -5
  22. data/lib/sequel/adapters/shared/sqlite.rb +28 -12
  23. data/lib/sequel/adapters/sqlite.rb +4 -3
  24. data/lib/sequel/adapters/utils/stored_procedures.rb +18 -9
  25. data/lib/sequel/connection_pool.rb +4 -3
  26. data/lib/sequel/database.rb +110 -10
  27. data/lib/sequel/database/schema_sql.rb +12 -3
  28. data/lib/sequel/dataset.rb +40 -3
  29. data/lib/sequel/dataset/convenience.rb +0 -11
  30. data/lib/sequel/dataset/graph.rb +25 -11
  31. data/lib/sequel/dataset/sql.rb +176 -68
  32. data/lib/sequel/extensions/migration.rb +37 -21
  33. data/lib/sequel/extensions/schema_dumper.rb +8 -61
  34. data/lib/sequel/model.rb +3 -3
  35. data/lib/sequel/model/associations.rb +9 -1
  36. data/lib/sequel/model/base.rb +8 -1
  37. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  38. data/lib/sequel/sql.rb +125 -18
  39. data/lib/sequel/version.rb +1 -1
  40. data/spec/adapters/ado_spec.rb +1 -0
  41. data/spec/adapters/firebird_spec.rb +1 -0
  42. data/spec/adapters/informix_spec.rb +1 -0
  43. data/spec/adapters/mysql_spec.rb +23 -8
  44. data/spec/adapters/oracle_spec.rb +1 -0
  45. data/spec/adapters/postgres_spec.rb +52 -4
  46. data/spec/adapters/spec_helper.rb +2 -2
  47. data/spec/adapters/sqlite_spec.rb +2 -1
  48. data/spec/core/connection_pool_spec.rb +16 -0
  49. data/spec/core/database_spec.rb +174 -0
  50. data/spec/core/dataset_spec.rb +121 -26
  51. data/spec/core/expression_filters_spec.rb +156 -0
  52. data/spec/core/object_graph_spec.rb +20 -1
  53. data/spec/core/schema_spec.rb +5 -5
  54. data/spec/extensions/migration_spec.rb +140 -74
  55. data/spec/extensions/schema_dumper_spec.rb +3 -69
  56. data/spec/extensions/single_table_inheritance_spec.rb +6 -0
  57. data/spec/integration/dataset_test.rb +84 -2
  58. data/spec/integration/schema_test.rb +24 -5
  59. data/spec/integration/spec_helper.rb +8 -6
  60. data/spec/model/eager_loading_spec.rb +9 -0
  61. data/spec/model/record_spec.rb +35 -8
  62. metadata +8 -7
  63. data/lib/sequel/adapters/utils/date_format.rb +0 -21
  64. data/lib/sequel/adapters/utils/savepoint_transactions.rb +0 -80
  65. data/lib/sequel/adapters/utils/unsupported.rb +0 -50
@@ -1,21 +0,0 @@
1
- # Module containing overrides for Sequel's standard date/time literalization
2
- # to use the SQL standrd. The SQL standard is used by fewer databases than
3
- # the defacto standard (which is just a normal string).
4
- module Sequel::Dataset::SQLStandardDateFormat
5
- private
6
-
7
- # Use SQL standard syntax for Date
8
- def literal_date(v)
9
- v.strftime("DATE '%Y-%m-%d'")
10
- end
11
-
12
- # Use SQL standard syntax for DateTime
13
- def literal_datetime(v)
14
- v.strftime("TIMESTAMP '%Y-%m-%d %H:%M:%S'")
15
- end
16
-
17
- # Use SQL standard syntax for Time
18
- def literal_time(v)
19
- v.strftime("TIMESTAMP '%Y-%m-%d %H:%M:%S'")
20
- end
21
- end
@@ -1,80 +0,0 @@
1
- # Module included in adapters that support savepoints, currently MySQL and PostgreSQL.
2
- module Sequel
3
- class Database
4
- module SavepointTransactions
5
- SQL_SAVEPOINT = 'SAVEPOINT autopoint_%d'.freeze
6
- SQL_ROLLBACK_TO_SAVEPOINT = 'ROLLBACK TO SAVEPOINT autopoint_%d'.freeze
7
- SQL_RELEASE_SAVEPOINT = 'RELEASE SAVEPOINT autopoint_%d'.freeze
8
-
9
- # Any adapter that includes this module must support savepoints.
10
- def supports_savepoints?
11
- true
12
- end
13
-
14
- private
15
-
16
- # Don't add the current thread to the list of threads with active
17
- # connections if it is already in the list. If there isn't an
18
- # active transaction on this thread, set the transaction depth to
19
- # zero.
20
- def add_transaction
21
- th = Thread.current
22
- unless @transactions.include?(th)
23
- th[:sequel_transaction_depth] = 0
24
- super
25
- end
26
- end
27
-
28
- # If a savepoint is requested, don't reuse an existing transaction
29
- def already_in_transaction?(conn, opts)
30
- super and !opts[:savepoint]
31
- end
32
-
33
- # SQL to start a new savepoint
34
- def begin_savepoint_sql(depth)
35
- SQL_SAVEPOINT % depth
36
- end
37
-
38
- # If there is no active transaction, start a new transaction. Otherwise,
39
- # start a savepoint inside the current transaction. Increment the
40
- def begin_transaction(conn)
41
- th = Thread.current
42
- depth = th[:sequel_transaction_depth]
43
- conn = transaction_statement_object(conn) if respond_to?(:transaction_statement_object, true)
44
- log_connection_execute(conn, depth > 0 ? begin_savepoint_sql(depth) : begin_transaction_sql)
45
- th[:sequel_transaction_depth] += 1
46
- conn
47
- end
48
-
49
- # SQL to commit a savepoint
50
- def commit_savepoint_sql(depth)
51
- SQL_RELEASE_SAVEPOINT % depth
52
- end
53
-
54
- # If currently inside a savepoint, commit/release the savepoint.
55
- # Otherwise, commit the transaction.
56
- def commit_transaction(conn)
57
- depth = Thread.current[:sequel_transaction_depth]
58
- log_connection_execute(conn, depth > 1 ? commit_savepoint_sql(depth-1) : commit_transaction_sql)
59
- end
60
-
61
- # Decrement the current savepoint/transaction depth
62
- def remove_transaction(conn)
63
- depth = (Thread.current[:sequel_transaction_depth] -= 1)
64
- super unless depth > 0
65
- end
66
-
67
- # SQL to rollback to a savepoint
68
- def rollback_savepoint_sql(depth)
69
- SQL_ROLLBACK_TO_SAVEPOINT % depth
70
- end
71
-
72
- # If currently inside a savepoint, rollback to the start of the savepoint.
73
- # Otherwise, rollback the entire transaction.
74
- def rollback_transaction(conn)
75
- depth = Thread.current[:sequel_transaction_depth]
76
- log_connection_execute(conn, depth > 1 ? rollback_savepoint_sql(depth-1) : rollback_transaction_sql)
77
- end
78
- end
79
- end
80
- end
@@ -1,50 +0,0 @@
1
- class Sequel::Dataset
2
- # This module should be included in the dataset class for all databases that
3
- # don't support INTERSECT or EXCEPT.
4
- module UnsupportedIntersectExcept
5
- # Raise an Error if EXCEPT is used
6
- def except(ds, all=false)
7
- raise(Sequel::Error, "EXCEPT not supported")
8
- end
9
-
10
- # Raise an Error if INTERSECT is used
11
- def intersect(ds, all=false)
12
- raise(Sequel::Error, "INTERSECT not supported")
13
- end
14
- end
15
-
16
- # This module should be included in the dataset class for all databases that
17
- # don't support INTERSECT ALL or EXCEPT ALL.
18
- module UnsupportedIntersectExceptAll
19
- # Raise an Error if EXCEPT is used
20
- def except(ds, all=false)
21
- raise(Sequel::Error, "EXCEPT ALL not supported") if all
22
- super(ds)
23
- end
24
-
25
- # Raise an Error if INTERSECT is used
26
- def intersect(ds, all=false)
27
- raise(Sequel::Error, "INTERSECT ALL not supported") if all
28
- super(ds)
29
- end
30
- end
31
-
32
- # This module should be included in the dataset class for all databases that
33
- # don't support IS [NOT] (TRUE|FALSE)
34
- module UnsupportedIsTrue
35
- # Use an = construct instead of IS and an != OR IS NULL construct instead of IS NOT.
36
- def complex_expression_sql(op, args)
37
- case op
38
- when :IS, :'IS NOT'
39
- isnot = op != :IS
40
- return super if (v1 = args.at(1)).nil?
41
- v0 = literal(args.at(0))
42
- s = "(#{v0} #{'!' if isnot}= #{literal(v1)})"
43
- s = "(#{s} OR (#{v0} IS NULL))" if isnot
44
- s
45
- else
46
- super(op, args)
47
- end
48
- end
49
- end
50
- end