viking-sequel 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. data/CHANGELOG +3134 -0
  2. data/COPYING +19 -0
  3. data/README.rdoc +723 -0
  4. data/Rakefile +193 -0
  5. data/bin/sequel +196 -0
  6. data/doc/advanced_associations.rdoc +644 -0
  7. data/doc/cheat_sheet.rdoc +218 -0
  8. data/doc/dataset_basics.rdoc +106 -0
  9. data/doc/dataset_filtering.rdoc +158 -0
  10. data/doc/opening_databases.rdoc +296 -0
  11. data/doc/prepared_statements.rdoc +104 -0
  12. data/doc/reflection.rdoc +84 -0
  13. data/doc/release_notes/1.0.txt +38 -0
  14. data/doc/release_notes/1.1.txt +143 -0
  15. data/doc/release_notes/1.3.txt +101 -0
  16. data/doc/release_notes/1.4.0.txt +53 -0
  17. data/doc/release_notes/1.5.0.txt +155 -0
  18. data/doc/release_notes/2.0.0.txt +298 -0
  19. data/doc/release_notes/2.1.0.txt +271 -0
  20. data/doc/release_notes/2.10.0.txt +328 -0
  21. data/doc/release_notes/2.11.0.txt +215 -0
  22. data/doc/release_notes/2.12.0.txt +534 -0
  23. data/doc/release_notes/2.2.0.txt +253 -0
  24. data/doc/release_notes/2.3.0.txt +88 -0
  25. data/doc/release_notes/2.4.0.txt +106 -0
  26. data/doc/release_notes/2.5.0.txt +137 -0
  27. data/doc/release_notes/2.6.0.txt +157 -0
  28. data/doc/release_notes/2.7.0.txt +166 -0
  29. data/doc/release_notes/2.8.0.txt +171 -0
  30. data/doc/release_notes/2.9.0.txt +97 -0
  31. data/doc/release_notes/3.0.0.txt +221 -0
  32. data/doc/release_notes/3.1.0.txt +406 -0
  33. data/doc/release_notes/3.10.0.txt +286 -0
  34. data/doc/release_notes/3.2.0.txt +268 -0
  35. data/doc/release_notes/3.3.0.txt +192 -0
  36. data/doc/release_notes/3.4.0.txt +325 -0
  37. data/doc/release_notes/3.5.0.txt +510 -0
  38. data/doc/release_notes/3.6.0.txt +366 -0
  39. data/doc/release_notes/3.7.0.txt +179 -0
  40. data/doc/release_notes/3.8.0.txt +151 -0
  41. data/doc/release_notes/3.9.0.txt +233 -0
  42. data/doc/schema.rdoc +36 -0
  43. data/doc/sharding.rdoc +113 -0
  44. data/doc/virtual_rows.rdoc +205 -0
  45. data/lib/sequel.rb +1 -0
  46. data/lib/sequel/adapters/ado.rb +90 -0
  47. data/lib/sequel/adapters/ado/mssql.rb +30 -0
  48. data/lib/sequel/adapters/amalgalite.rb +176 -0
  49. data/lib/sequel/adapters/db2.rb +139 -0
  50. data/lib/sequel/adapters/dbi.rb +113 -0
  51. data/lib/sequel/adapters/do.rb +188 -0
  52. data/lib/sequel/adapters/do/mysql.rb +49 -0
  53. data/lib/sequel/adapters/do/postgres.rb +91 -0
  54. data/lib/sequel/adapters/do/sqlite.rb +40 -0
  55. data/lib/sequel/adapters/firebird.rb +283 -0
  56. data/lib/sequel/adapters/informix.rb +77 -0
  57. data/lib/sequel/adapters/jdbc.rb +587 -0
  58. data/lib/sequel/adapters/jdbc/as400.rb +58 -0
  59. data/lib/sequel/adapters/jdbc/h2.rb +133 -0
  60. data/lib/sequel/adapters/jdbc/mssql.rb +57 -0
  61. data/lib/sequel/adapters/jdbc/mysql.rb +78 -0
  62. data/lib/sequel/adapters/jdbc/oracle.rb +50 -0
  63. data/lib/sequel/adapters/jdbc/postgresql.rb +108 -0
  64. data/lib/sequel/adapters/jdbc/sqlite.rb +55 -0
  65. data/lib/sequel/adapters/mysql.rb +421 -0
  66. data/lib/sequel/adapters/odbc.rb +143 -0
  67. data/lib/sequel/adapters/odbc/mssql.rb +42 -0
  68. data/lib/sequel/adapters/openbase.rb +64 -0
  69. data/lib/sequel/adapters/oracle.rb +131 -0
  70. data/lib/sequel/adapters/postgres.rb +504 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +490 -0
  72. data/lib/sequel/adapters/shared/mysql.rb +498 -0
  73. data/lib/sequel/adapters/shared/oracle.rb +195 -0
  74. data/lib/sequel/adapters/shared/postgres.rb +830 -0
  75. data/lib/sequel/adapters/shared/progress.rb +44 -0
  76. data/lib/sequel/adapters/shared/sqlite.rb +389 -0
  77. data/lib/sequel/adapters/sqlite.rb +224 -0
  78. data/lib/sequel/adapters/utils/stored_procedures.rb +84 -0
  79. data/lib/sequel/connection_pool.rb +99 -0
  80. data/lib/sequel/connection_pool/sharded_single.rb +84 -0
  81. data/lib/sequel/connection_pool/sharded_threaded.rb +211 -0
  82. data/lib/sequel/connection_pool/single.rb +29 -0
  83. data/lib/sequel/connection_pool/threaded.rb +150 -0
  84. data/lib/sequel/core.rb +293 -0
  85. data/lib/sequel/core_sql.rb +241 -0
  86. data/lib/sequel/database.rb +1079 -0
  87. data/lib/sequel/database/schema_generator.rb +327 -0
  88. data/lib/sequel/database/schema_methods.rb +203 -0
  89. data/lib/sequel/database/schema_sql.rb +320 -0
  90. data/lib/sequel/dataset.rb +32 -0
  91. data/lib/sequel/dataset/actions.rb +441 -0
  92. data/lib/sequel/dataset/features.rb +86 -0
  93. data/lib/sequel/dataset/graph.rb +254 -0
  94. data/lib/sequel/dataset/misc.rb +119 -0
  95. data/lib/sequel/dataset/mutation.rb +64 -0
  96. data/lib/sequel/dataset/prepared_statements.rb +227 -0
  97. data/lib/sequel/dataset/query.rb +709 -0
  98. data/lib/sequel/dataset/sql.rb +996 -0
  99. data/lib/sequel/exceptions.rb +51 -0
  100. data/lib/sequel/extensions/blank.rb +43 -0
  101. data/lib/sequel/extensions/inflector.rb +242 -0
  102. data/lib/sequel/extensions/looser_typecasting.rb +21 -0
  103. data/lib/sequel/extensions/migration.rb +239 -0
  104. data/lib/sequel/extensions/named_timezones.rb +61 -0
  105. data/lib/sequel/extensions/pagination.rb +100 -0
  106. data/lib/sequel/extensions/pretty_table.rb +82 -0
  107. data/lib/sequel/extensions/query.rb +52 -0
  108. data/lib/sequel/extensions/schema_dumper.rb +271 -0
  109. data/lib/sequel/extensions/sql_expr.rb +122 -0
  110. data/lib/sequel/extensions/string_date_time.rb +46 -0
  111. data/lib/sequel/extensions/thread_local_timezones.rb +48 -0
  112. data/lib/sequel/metaprogramming.rb +9 -0
  113. data/lib/sequel/model.rb +120 -0
  114. data/lib/sequel/model/associations.rb +1514 -0
  115. data/lib/sequel/model/base.rb +1069 -0
  116. data/lib/sequel/model/default_inflections.rb +45 -0
  117. data/lib/sequel/model/errors.rb +39 -0
  118. data/lib/sequel/model/exceptions.rb +21 -0
  119. data/lib/sequel/model/inflections.rb +162 -0
  120. data/lib/sequel/model/plugins.rb +70 -0
  121. data/lib/sequel/plugins/active_model.rb +59 -0
  122. data/lib/sequel/plugins/association_dependencies.rb +103 -0
  123. data/lib/sequel/plugins/association_proxies.rb +41 -0
  124. data/lib/sequel/plugins/boolean_readers.rb +53 -0
  125. data/lib/sequel/plugins/caching.rb +141 -0
  126. data/lib/sequel/plugins/class_table_inheritance.rb +214 -0
  127. data/lib/sequel/plugins/composition.rb +138 -0
  128. data/lib/sequel/plugins/force_encoding.rb +72 -0
  129. data/lib/sequel/plugins/hook_class_methods.rb +126 -0
  130. data/lib/sequel/plugins/identity_map.rb +116 -0
  131. data/lib/sequel/plugins/instance_filters.rb +98 -0
  132. data/lib/sequel/plugins/instance_hooks.rb +57 -0
  133. data/lib/sequel/plugins/lazy_attributes.rb +77 -0
  134. data/lib/sequel/plugins/many_through_many.rb +208 -0
  135. data/lib/sequel/plugins/nested_attributes.rb +206 -0
  136. data/lib/sequel/plugins/optimistic_locking.rb +81 -0
  137. data/lib/sequel/plugins/rcte_tree.rb +281 -0
  138. data/lib/sequel/plugins/schema.rb +66 -0
  139. data/lib/sequel/plugins/serialization.rb +166 -0
  140. data/lib/sequel/plugins/single_table_inheritance.rb +74 -0
  141. data/lib/sequel/plugins/subclasses.rb +45 -0
  142. data/lib/sequel/plugins/tactical_eager_loading.rb +61 -0
  143. data/lib/sequel/plugins/timestamps.rb +87 -0
  144. data/lib/sequel/plugins/touch.rb +118 -0
  145. data/lib/sequel/plugins/typecast_on_load.rb +72 -0
  146. data/lib/sequel/plugins/validation_class_methods.rb +405 -0
  147. data/lib/sequel/plugins/validation_helpers.rb +223 -0
  148. data/lib/sequel/sql.rb +1020 -0
  149. data/lib/sequel/timezones.rb +161 -0
  150. data/lib/sequel/version.rb +12 -0
  151. data/lib/sequel_core.rb +1 -0
  152. data/lib/sequel_model.rb +1 -0
  153. data/spec/adapters/firebird_spec.rb +407 -0
  154. data/spec/adapters/informix_spec.rb +97 -0
  155. data/spec/adapters/mssql_spec.rb +403 -0
  156. data/spec/adapters/mysql_spec.rb +1019 -0
  157. data/spec/adapters/oracle_spec.rb +286 -0
  158. data/spec/adapters/postgres_spec.rb +969 -0
  159. data/spec/adapters/spec_helper.rb +51 -0
  160. data/spec/adapters/sqlite_spec.rb +432 -0
  161. data/spec/core/connection_pool_spec.rb +808 -0
  162. data/spec/core/core_sql_spec.rb +417 -0
  163. data/spec/core/database_spec.rb +1662 -0
  164. data/spec/core/dataset_spec.rb +3827 -0
  165. data/spec/core/expression_filters_spec.rb +595 -0
  166. data/spec/core/object_graph_spec.rb +296 -0
  167. data/spec/core/schema_generator_spec.rb +159 -0
  168. data/spec/core/schema_spec.rb +830 -0
  169. data/spec/core/spec_helper.rb +56 -0
  170. data/spec/core/version_spec.rb +7 -0
  171. data/spec/extensions/active_model_spec.rb +76 -0
  172. data/spec/extensions/association_dependencies_spec.rb +127 -0
  173. data/spec/extensions/association_proxies_spec.rb +50 -0
  174. data/spec/extensions/blank_spec.rb +67 -0
  175. data/spec/extensions/boolean_readers_spec.rb +92 -0
  176. data/spec/extensions/caching_spec.rb +250 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +252 -0
  178. data/spec/extensions/composition_spec.rb +194 -0
  179. data/spec/extensions/force_encoding_spec.rb +117 -0
  180. data/spec/extensions/hook_class_methods_spec.rb +470 -0
  181. data/spec/extensions/identity_map_spec.rb +202 -0
  182. data/spec/extensions/inflector_spec.rb +181 -0
  183. data/spec/extensions/instance_filters_spec.rb +55 -0
  184. data/spec/extensions/instance_hooks_spec.rb +133 -0
  185. data/spec/extensions/lazy_attributes_spec.rb +153 -0
  186. data/spec/extensions/looser_typecasting_spec.rb +39 -0
  187. data/spec/extensions/many_through_many_spec.rb +884 -0
  188. data/spec/extensions/migration_spec.rb +332 -0
  189. data/spec/extensions/named_timezones_spec.rb +72 -0
  190. data/spec/extensions/nested_attributes_spec.rb +396 -0
  191. data/spec/extensions/optimistic_locking_spec.rb +100 -0
  192. data/spec/extensions/pagination_spec.rb +99 -0
  193. data/spec/extensions/pretty_table_spec.rb +91 -0
  194. data/spec/extensions/query_spec.rb +85 -0
  195. data/spec/extensions/rcte_tree_spec.rb +205 -0
  196. data/spec/extensions/schema_dumper_spec.rb +357 -0
  197. data/spec/extensions/schema_spec.rb +127 -0
  198. data/spec/extensions/serialization_spec.rb +209 -0
  199. data/spec/extensions/single_table_inheritance_spec.rb +96 -0
  200. data/spec/extensions/spec_helper.rb +91 -0
  201. data/spec/extensions/sql_expr_spec.rb +89 -0
  202. data/spec/extensions/string_date_time_spec.rb +93 -0
  203. data/spec/extensions/subclasses_spec.rb +52 -0
  204. data/spec/extensions/tactical_eager_loading_spec.rb +65 -0
  205. data/spec/extensions/thread_local_timezones_spec.rb +45 -0
  206. data/spec/extensions/timestamps_spec.rb +150 -0
  207. data/spec/extensions/touch_spec.rb +155 -0
  208. data/spec/extensions/typecast_on_load_spec.rb +69 -0
  209. data/spec/extensions/validation_class_methods_spec.rb +984 -0
  210. data/spec/extensions/validation_helpers_spec.rb +438 -0
  211. data/spec/integration/associations_test.rb +281 -0
  212. data/spec/integration/database_test.rb +26 -0
  213. data/spec/integration/dataset_test.rb +963 -0
  214. data/spec/integration/eager_loader_test.rb +734 -0
  215. data/spec/integration/model_test.rb +130 -0
  216. data/spec/integration/plugin_test.rb +814 -0
  217. data/spec/integration/prepared_statement_test.rb +213 -0
  218. data/spec/integration/schema_test.rb +361 -0
  219. data/spec/integration/spec_helper.rb +73 -0
  220. data/spec/integration/timezone_test.rb +55 -0
  221. data/spec/integration/transaction_test.rb +122 -0
  222. data/spec/integration/type_test.rb +96 -0
  223. data/spec/model/association_reflection_spec.rb +175 -0
  224. data/spec/model/associations_spec.rb +2633 -0
  225. data/spec/model/base_spec.rb +418 -0
  226. data/spec/model/dataset_methods_spec.rb +78 -0
  227. data/spec/model/eager_loading_spec.rb +1391 -0
  228. data/spec/model/hooks_spec.rb +240 -0
  229. data/spec/model/inflector_spec.rb +26 -0
  230. data/spec/model/model_spec.rb +593 -0
  231. data/spec/model/plugins_spec.rb +236 -0
  232. data/spec/model/record_spec.rb +1500 -0
  233. data/spec/model/spec_helper.rb +97 -0
  234. data/spec/model/validations_spec.rb +153 -0
  235. data/spec/rcov.opts +6 -0
  236. data/spec/spec_config.rb.example +10 -0
  237. metadata +346 -0
@@ -0,0 +1,58 @@
1
+ module Sequel
2
+ module JDBC
3
+ # Database and Dataset support for AS400 databases accessed via JDBC.
4
+ module AS400
5
+ # Instance methods for AS400 Database objects accessed via JDBC.
6
+ module DatabaseMethods
7
+ # AS400 uses the :as400 database type.
8
+ def database_type
9
+ :as400
10
+ end
11
+
12
+ # Return Sequel::JDBC::AS400::Dataset object with the given opts.
13
+ def dataset(opts=nil)
14
+ Sequel::JDBC::AS400::Dataset.new(self, opts)
15
+ end
16
+
17
+ # TODO: Fix for AS400
18
+ def last_insert_id(conn, opts={})
19
+ nil
20
+ end
21
+ end
22
+
23
+ # Dataset class for AS400 datasets accessed via JDBC.
24
+ class Dataset < JDBC::Dataset
25
+ WILDCARD = Sequel::LiteralString.new('*').freeze
26
+
27
+ # AS400 needs to use a couple of subselects for all limits and offsets.
28
+ def select_sql
29
+ return super unless l = @opts[:limit]
30
+ o = @opts[:offset] || 0
31
+ order = @opts[:order]
32
+ dsa1 = dataset_alias(1)
33
+ dsa2 = dataset_alias(2)
34
+ rn = row_number_column
35
+ irn = Sequel::SQL::Identifier.new(rn).qualify(dsa2)
36
+ subselect_sql(unlimited.
37
+ from_self(:alias=>dsa1).
38
+ select_more(Sequel::SQL::QualifiedIdentifier.new(dsa1, WILDCARD),
39
+ Sequel::SQL::WindowFunction.new(SQL::Function.new(:ROW_NUMBER), Sequel::SQL::Window.new(:order=>order)).as(rn)).
40
+ from_self(:alias=>dsa2).
41
+ select(Sequel::SQL::QualifiedIdentifier.new(dsa2, WILDCARD)).
42
+ where((irn > o) & (irn <= l + o)))
43
+ end
44
+
45
+ def supports_window_functions?
46
+ true
47
+ end
48
+
49
+ private
50
+
51
+ # The alias to use for the row_number column when emulating LIMIT and OFFSET
52
+ def row_number_column
53
+ :x_sequel_row_number_x
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,133 @@
1
+ module Sequel
2
+ module JDBC
3
+ # Database and Dataset support for H2 databases accessed via JDBC.
4
+ module H2
5
+ # Instance methods for H2 Database objects accessed via JDBC.
6
+ module DatabaseMethods
7
+ PRIMARY_KEY_INDEX_RE = /\Aprimary_key/i.freeze
8
+
9
+ # H2 uses the :h2 database type.
10
+ def database_type
11
+ :h2
12
+ end
13
+
14
+ # Return Sequel::JDBC::H2::Dataset object with the given opts.
15
+ def dataset(opts=nil)
16
+ Sequel::JDBC::H2::Dataset.new(self, opts)
17
+ end
18
+
19
+ # H2 uses an IDENTITY type
20
+ def serial_primary_key_options
21
+ {:primary_key => true, :type => :identity}
22
+ end
23
+
24
+ private
25
+
26
+ # H2 needs to add a primary key column as a constraint
27
+ def alter_table_sql(table, op)
28
+ case op[:op]
29
+ when :add_column
30
+ if (pk = op.delete(:primary_key)) || (ref = op.delete(:table))
31
+ sqls = [super(table, op)]
32
+ sqls << "ALTER TABLE #{quote_schema_table(table)} ADD PRIMARY KEY (#{quote_identifier(op[:name])})" if pk
33
+ if ref
34
+ op[:table] = ref
35
+ sqls << "ALTER TABLE #{quote_schema_table(table)} ADD FOREIGN KEY (#{quote_identifier(op[:name])}) #{column_references_sql(op)}"
36
+ end
37
+ sqls
38
+ else
39
+ super(table, op)
40
+ end
41
+ when :rename_column
42
+ "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} RENAME TO #{quote_identifier(op[:new_name])}"
43
+ when :set_column_null
44
+ "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET#{' NOT' unless op[:null]} NULL"
45
+ when :set_column_type
46
+ "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} #{type_literal(op)}"
47
+ else
48
+ super(table, op)
49
+ end
50
+ end
51
+
52
+ # Default to a single connection for a memory database.
53
+ def connection_pool_default_options
54
+ o = super
55
+ uri == 'jdbc:h2:mem:' ? o.merge(:max_connections=>1) : o
56
+ end
57
+
58
+ # Use IDENTITY() to get the last inserted id.
59
+ def last_insert_id(conn, opts={})
60
+ stmt = conn.createStatement
61
+ begin
62
+ rs = stmt.executeQuery('SELECT IDENTITY();')
63
+ rs.next
64
+ rs.getInt(1)
65
+ ensure
66
+ stmt.close
67
+ end
68
+ end
69
+
70
+ def primary_key_index_re
71
+ PRIMARY_KEY_INDEX_RE
72
+ end
73
+ end
74
+
75
+ # Dataset class for H2 datasets accessed via JDBC.
76
+ class Dataset < JDBC::Dataset
77
+ SELECT_CLAUSE_METHODS = clause_methods(:select, %w'distinct columns from join where group having compounds order limit')
78
+
79
+ # Work around H2's lack of a case insensitive LIKE operator
80
+ def complex_expression_sql(op, args)
81
+ case op
82
+ when :ILIKE
83
+ super(:LIKE, [SQL::PlaceholderLiteralString.new("CAST(? AS VARCHAR_IGNORECASE)", [args.at(0)]), args.at(1)])
84
+ when :"NOT ILIKE"
85
+ super(:"NOT LIKE", [SQL::PlaceholderLiteralString.new("CAST(? AS VARCHAR_IGNORECASE)", [args.at(0)]), args.at(1)])
86
+ else
87
+ super(op, args)
88
+ end
89
+ end
90
+
91
+ # H2 requires SQL standard datetimes
92
+ def requires_sql_standard_datetimes?
93
+ true
94
+ end
95
+
96
+ # H2 doesn't support IS TRUE
97
+ def supports_is_true?
98
+ false
99
+ end
100
+
101
+ # H2 doesn't support JOIN USING
102
+ def supports_join_using?
103
+ false
104
+ end
105
+
106
+ # H2 doesn't support multiple columns in IN/NOT IN
107
+ def supports_multiple_column_in?
108
+ false
109
+ end
110
+
111
+ private
112
+
113
+ # H2 expects hexadecimal strings for blob values
114
+ def literal_blob(v)
115
+ literal_string v.unpack("H*").first
116
+ end
117
+
118
+ def convert_type(v)
119
+ case v
120
+ when Java::OrgH2Jdbc::JdbcClob
121
+ convert_type(v.getSubString(1, v.length))
122
+ else
123
+ super(v)
124
+ end
125
+ end
126
+
127
+ def select_clause_methods
128
+ SELECT_CLAUSE_METHODS
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,57 @@
1
+ Sequel.require 'adapters/shared/mssql'
2
+
3
+ module Sequel
4
+ module JDBC
5
+ class Database
6
+ # Alias the generic JDBC version so it can be called directly later
7
+ alias jdbc_schema_parse_table schema_parse_table
8
+ end
9
+
10
+ # Database and Dataset instance methods for MSSQL specific
11
+ # support via JDBC.
12
+ module MSSQL
13
+ # Database instance methods for MSSQL databases accessed via JDBC.
14
+ module DatabaseMethods
15
+ PRIMARY_KEY_INDEX_RE = /\Apk__/i.freeze
16
+
17
+ include Sequel::MSSQL::DatabaseMethods
18
+
19
+ # Return instance of Sequel::JDBC::MSSQL::Dataset with the given opts.
20
+ def dataset(opts=nil)
21
+ Sequel::JDBC::MSSQL::Dataset.new(self, opts)
22
+ end
23
+
24
+ private
25
+
26
+ # Get the last inserted id using SCOPE_IDENTITY().
27
+ def last_insert_id(conn, opts={})
28
+ stmt = conn.createStatement
29
+ begin
30
+ sql = opts[:prepared] ? 'SELECT @@IDENTITY' : 'SELECT SCOPE_IDENTITY()'
31
+ rs = log_yield(sql){stmt.executeQuery(sql)}
32
+ rs.next
33
+ rs.getInt(1)
34
+ ensure
35
+ stmt.close
36
+ end
37
+ end
38
+
39
+ # Call the generic JDBC version instead of MSSQL version,
40
+ # since the JDBC version handles primary keys.
41
+ def schema_parse_table(table, opts={})
42
+ jdbc_schema_parse_table(table, opts)
43
+ end
44
+
45
+ # Primary key indexes appear to start with pk__ on MSSQL
46
+ def primary_key_index_re
47
+ PRIMARY_KEY_INDEX_RE
48
+ end
49
+ end
50
+
51
+ # Dataset class for MSSQL datasets accessed via JDBC.
52
+ class Dataset < JDBC::Dataset
53
+ include Sequel::MSSQL::DatasetMethods
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,78 @@
1
+ Sequel.require 'adapters/shared/mysql'
2
+
3
+ module Sequel
4
+ module JDBC
5
+ # Database and Dataset instance methods for MySQL specific
6
+ # support via JDBC.
7
+ module MySQL
8
+ # Database instance methods for MySQL databases accessed via JDBC.
9
+ module DatabaseMethods
10
+ include Sequel::MySQL::DatabaseMethods
11
+
12
+ # Return instance of Sequel::JDBC::MySQL::Dataset with the given opts.
13
+ def dataset(opts=nil)
14
+ Sequel::JDBC::MySQL::Dataset.new(self, opts)
15
+ end
16
+
17
+ private
18
+
19
+ # The database name for the given database. Need to parse it out
20
+ # of the connection string, since the JDBC does no parsing on the
21
+ # given connection string by default.
22
+ def database_name
23
+ u = URI.parse(uri.sub(/\Ajdbc:/, ''))
24
+ (m = /\/(.*)/.match(u.path)) && m[1]
25
+ end
26
+
27
+ # Get the last inserted id using LAST_INSERT_ID().
28
+ def last_insert_id(conn, opts={})
29
+ if stmt = opts[:stmt]
30
+ rs = stmt.getGeneratedKeys
31
+ begin
32
+ if rs.next
33
+ rs.getInt(1)
34
+ else
35
+ 0
36
+ end
37
+ ensure
38
+ rs.close
39
+ end
40
+ else
41
+ stmt = conn.createStatement
42
+ begin
43
+ rs = stmt.executeQuery('SELECT LAST_INSERT_ID()')
44
+ rs.next
45
+ rs.getInt(1)
46
+ ensure
47
+ stmt.close
48
+ end
49
+ end
50
+ end
51
+
52
+ def requires_return_generated_keys?
53
+ true
54
+ end
55
+ end
56
+
57
+ # Dataset class for MySQL datasets accessed via JDBC.
58
+ class Dataset < JDBC::Dataset
59
+ include Sequel::MySQL::DatasetMethods
60
+
61
+ # Use execute_insert to execute the insert_sql.
62
+ def insert(*values)
63
+ execute_insert(insert_sql(*values))
64
+ end
65
+
66
+ # Use execute_insert to execute the replace_sql.
67
+ def replace(*args)
68
+ execute_insert(replace_sql(*args))
69
+ end
70
+
71
+ # MySQL on JDBC does provides an accurate number of rows matched.
72
+ def provides_accurate_rows_matched?
73
+ true
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ Sequel.require 'adapters/shared/oracle'
2
+
3
+ module Sequel
4
+ module JDBC
5
+ # Database and Dataset support for Oracle databases accessed via JDBC.
6
+ module Oracle
7
+ # Instance methods for Oracle Database objects accessed via JDBC.
8
+ module DatabaseMethods
9
+ include Sequel::Oracle::DatabaseMethods
10
+ TRANSACTION_BEGIN = 'Transaction.begin'.freeze
11
+ TRANSACTION_COMMIT = 'Transaction.commit'.freeze
12
+ TRANSACTION_ROLLBACK = 'Transaction.rollback'.freeze
13
+
14
+ # Return Sequel::JDBC::Oracle::Dataset object with the given opts.
15
+ def dataset(opts=nil)
16
+ Sequel::JDBC::Oracle::Dataset.new(self, opts)
17
+ end
18
+
19
+ private
20
+
21
+ # Use JDBC connection's setAutoCommit to false to start transactions
22
+ def begin_transaction(conn)
23
+ log_yield(TRANSACTION_BEGIN){conn.setAutoCommit(false)}
24
+ conn
25
+ end
26
+
27
+ # Use JDBC connection's commit method to commit transactions
28
+ def commit_transaction(conn)
29
+ log_yield(TRANSACTION_COMMIT){conn.commit}
30
+ end
31
+
32
+ # Use JDBC connection's setAutoCommit to true to enable non-transactional behavior
33
+ def remove_transaction(conn)
34
+ conn.setAutoCommit(true) if conn
35
+ @transactions.delete(Thread.current)
36
+ end
37
+
38
+ # Use JDBC connection's rollback method to rollback transactions
39
+ def rollback_transaction(conn)
40
+ log_yield(TRANSACTION_ROLLBACK){conn.rollback}
41
+ end
42
+ end
43
+
44
+ # Dataset class for Oracle datasets accessed via JDBC.
45
+ class Dataset < JDBC::Dataset
46
+ include Sequel::Oracle::DatasetMethods
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,108 @@
1
+ Sequel.require 'adapters/shared/postgres'
2
+
3
+ module Sequel
4
+ Postgres::CONVERTED_EXCEPTIONS << NativeException
5
+
6
+ module JDBC
7
+ # Adapter, Database, and Dataset support for accessing a PostgreSQL
8
+ # database via JDBC.
9
+ module Postgres
10
+ # Methods to add to the JDBC adapter/connection to allow it to work
11
+ # with the shared PostgreSQL code.
12
+ module AdapterMethods
13
+ include Sequel::Postgres::AdapterMethods
14
+
15
+ # Give the JDBC adapter a direct execute method, which creates
16
+ # a statement with the given sql and executes it.
17
+ def execute(sql, args=nil)
18
+ method = block_given? ? :executeQuery : :execute
19
+ stmt = createStatement
20
+ begin
21
+ rows = @db.log_yield(sql){stmt.send(method, sql)}
22
+ yield(rows) if block_given?
23
+ rescue NativeException => e
24
+ raise_error(e)
25
+ ensure
26
+ stmt.close
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # JDBC specific method of getting specific values from a result set.
33
+ def single_value(r)
34
+ unless r.nil?
35
+ r.next
36
+ r.getString(1) unless r.getRow == 0
37
+ end
38
+ end
39
+ end
40
+
41
+ # Methods to add to Database instances that access PostgreSQL via
42
+ # JDBC.
43
+ module DatabaseMethods
44
+ include Sequel::Postgres::DatabaseMethods
45
+
46
+ # Add the primary_keys and primary_key_sequences instance variables,
47
+ # so we can get the correct return values for inserted rows.
48
+ def self.extended(db)
49
+ db.instance_eval do
50
+ @primary_keys = {}
51
+ @primary_key_sequences = {}
52
+ end
53
+ end
54
+
55
+ # Return instance of Sequel::JDBC::Postgres::Dataset with the given opts.
56
+ def dataset(opts=nil)
57
+ Sequel::JDBC::Postgres::Dataset.new(self, opts)
58
+ end
59
+
60
+ # Run the INSERT sql on the database and return the primary key
61
+ # for the record.
62
+ def execute_insert(sql, opts={})
63
+ super(sql, {:type=>:insert}.merge(opts))
64
+ end
65
+
66
+ private
67
+
68
+ # Extend the adapter with the JDBC PostgreSQL AdapterMethods
69
+ def setup_connection(conn)
70
+ conn = super(conn)
71
+ conn.extend(Sequel::JDBC::Postgres::AdapterMethods)
72
+ conn.db = self
73
+ conn.apply_connection_settings
74
+ conn
75
+ end
76
+
77
+ # Call insert_result with the table and values specified in the opts.
78
+ def last_insert_id(conn, opts)
79
+ insert_result(conn, opts[:table], opts[:values])
80
+ end
81
+
82
+ # Override shared postgresql adapter method to actually log,
83
+ # since on JDBC the first argument is a statement and not a
84
+ # connection, so it wouldn't be logged otherwise.
85
+ def log_connection_execute(stmt, sql)
86
+ log_yield(sql){stmt.execute(sql)}
87
+ end
88
+ end
89
+
90
+ # Dataset subclass used for datasets that connect to PostgreSQL via JDBC.
91
+ class Dataset < JDBC::Dataset
92
+ include Sequel::Postgres::DatasetMethods
93
+
94
+ # Add the shared PostgreSQL prepared statement methods
95
+ def prepare(*args)
96
+ ps = super
97
+ ps.extend(::Sequel::Postgres::DatasetMethods::PreparedStatementMethods)
98
+ ps
99
+ end
100
+
101
+ # Literalize strings similar to the native postgres adapter
102
+ def literal_string(v)
103
+ db.synchronize{|c| "'#{c.escape_string(v)}'"}
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end