activerecord-jdbc-adapter 5.0.pre1 → 50.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord-jdbc-adapter might be problematic. Click here for more details.

Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.travis.yml +15 -416
  4. data/Gemfile +35 -37
  5. data/README.md +23 -118
  6. data/RUNNING_TESTS.md +31 -26
  7. data/Rakefile +2 -3
  8. data/lib/arjdbc/abstract/connection_management.rb +21 -0
  9. data/lib/arjdbc/abstract/core.rb +62 -0
  10. data/lib/arjdbc/abstract/database_statements.rb +46 -0
  11. data/lib/arjdbc/abstract/statement_cache.rb +58 -0
  12. data/lib/arjdbc/abstract/transaction_support.rb +86 -0
  13. data/lib/arjdbc/derby/adapter.rb +6 -1
  14. data/lib/arjdbc/discover.rb +0 -7
  15. data/lib/arjdbc/firebird/adapter.rb +2 -2
  16. data/lib/arjdbc/jdbc.rb +2 -2
  17. data/lib/arjdbc/jdbc/adapter.rb +10 -252
  18. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  19. data/lib/arjdbc/jdbc/connection.rb +6 -0
  20. data/lib/arjdbc/mysql/adapter.rb +82 -946
  21. data/lib/arjdbc/mysql/connection_methods.rb +4 -2
  22. data/lib/arjdbc/postgresql/adapter.rb +270 -970
  23. data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
  24. data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
  25. data/lib/arjdbc/postgresql/base/pgconn.rb +8 -5
  26. data/lib/arjdbc/postgresql/column.rb +10 -599
  27. data/lib/arjdbc/postgresql/connection_methods.rb +9 -0
  28. data/lib/arjdbc/postgresql/name.rb +24 -0
  29. data/lib/arjdbc/postgresql/oid_types.rb +28 -109
  30. data/lib/arjdbc/sqlite3/adapter.rb +18 -42
  31. data/lib/arjdbc/tasks/database_tasks.rb +1 -3
  32. data/lib/arjdbc/tasks/db2_database_tasks.rb +2 -2
  33. data/lib/arjdbc/version.rb +1 -1
  34. data/pom.xml +3 -3
  35. data/rakelib/02-test.rake +0 -12
  36. data/rakelib/compile.rake +1 -1
  37. data/rakelib/db.rake +7 -5
  38. data/rakelib/rails.rake +67 -64
  39. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +1 -17
  40. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +518 -1260
  41. data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
  42. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +53 -134
  43. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -240
  44. data/src/java/arjdbc/sqlite3/SQLite3Module.java +0 -20
  45. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +85 -10
  46. metadata +16 -29
  47. data/Appraisals +0 -41
  48. data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
  49. data/lib/arjdbc/common_jdbc_methods.rb +0 -89
  50. data/lib/arjdbc/mysql/bulk_change_table.rb +0 -150
  51. data/lib/arjdbc/mysql/column.rb +0 -162
  52. data/lib/arjdbc/mysql/explain_support.rb +0 -82
  53. data/lib/arjdbc/mysql/schema_creation.rb +0 -58
  54. data/lib/arjdbc/oracle.rb +0 -4
  55. data/lib/arjdbc/oracle/adapter.rb +0 -952
  56. data/lib/arjdbc/oracle/column.rb +0 -126
  57. data/lib/arjdbc/oracle/connection_methods.rb +0 -21
  58. data/lib/arjdbc/postgresql/base/oid.rb +0 -412
  59. data/lib/arjdbc/postgresql/base/schema_definitions.rb +0 -131
  60. data/lib/arjdbc/postgresql/explain_support.rb +0 -53
  61. data/lib/arjdbc/postgresql/oid/bytea.rb +0 -2
  62. data/lib/arjdbc/postgresql/schema_creation.rb +0 -60
  63. data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +0 -297
  64. data/lib/arjdbc/tasks/oracle_database_tasks.rb +0 -65
  65. data/src/java/arjdbc/oracle/OracleModule.java +0 -75
  66. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +0 -465
@@ -30,7 +30,6 @@ import org.jruby.RubyString;
30
30
  import org.jruby.anno.JRubyMethod;
31
31
  import org.jruby.runtime.ThreadContext;
32
32
  import org.jruby.runtime.builtin.IRubyObject;
33
- import org.jruby.util.ByteList;
34
33
 
35
34
  /**
36
35
  * ArJdbc::SQLite3
@@ -56,23 +55,4 @@ public class SQLite3Module {
56
55
  );
57
56
  return quoted;
58
57
  }
59
-
60
- private static final ByteList Q_TRUE = new ByteList(new byte[] { '\'', 't', '\'' }, false);
61
-
62
- @JRubyMethod(name = "quoted_true", required = 0, frame = false)
63
- public static IRubyObject quoted_true(
64
- final ThreadContext context,
65
- final IRubyObject self) {
66
- return RubyString.newString(context.getRuntime(), Q_TRUE);
67
- }
68
-
69
- private static final ByteList Q_FALSE = new ByteList(new byte[] { '\'', 'f', '\'' }, false);
70
-
71
- @JRubyMethod(name = "quoted_false", required = 0, frame = false)
72
- public static IRubyObject quoted_false(
73
- final ThreadContext context,
74
- final IRubyObject self) {
75
- return RubyString.newString(context.getRuntime(), Q_FALSE);
76
- }
77
-
78
58
  }
@@ -36,6 +36,7 @@ import java.sql.ResultSetMetaData;
36
36
  import java.sql.SQLException;
37
37
  import java.sql.Statement;
38
38
  import java.sql.DatabaseMetaData;
39
+ import java.sql.PreparedStatement;
39
40
  import java.sql.Savepoint;
40
41
  import java.sql.Types;
41
42
  import java.util.ArrayList;
@@ -45,6 +46,7 @@ import org.jruby.Ruby;
45
46
  import org.jruby.RubyArray;
46
47
  import org.jruby.RubyClass;
47
48
  import org.jruby.RubyString;
49
+ import org.jruby.RubyTime;
48
50
  import org.jruby.anno.JRubyMethod;
49
51
  import org.jruby.runtime.ObjectAllocator;
50
52
  import org.jruby.runtime.ThreadContext;
@@ -58,8 +60,12 @@ import org.jruby.util.ByteList;
58
60
  public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
59
61
  private static final long serialVersionUID = -5783855018818472773L;
60
62
 
63
+ private final RubyString TIMESTAMP_FORMAT;
64
+
61
65
  protected SQLite3RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
62
66
  super(runtime, metaClass);
67
+
68
+ TIMESTAMP_FORMAT = runtime.newString("%F %T.%6N");
63
69
  }
64
70
 
65
71
  public static RubyClass createSQLite3JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
@@ -135,7 +141,7 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
135
141
  final Ruby runtime = context.runtime;
136
142
  final RubyClass indexDefinition = getIndexDefinition(runtime);
137
143
 
138
- final TableName table = extractTableName(connection, schemaName, tableName);
144
+ final TableName table = extractTableName(connection, null, schemaName, tableName);
139
145
 
140
146
  final List<RubyString> primaryKeys = primaryKeys(context, connection, table);
141
147
 
@@ -282,6 +288,12 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
282
288
 
283
289
  }
284
290
 
291
+ @Override
292
+ public IRubyObject begin(ThreadContext context, IRubyObject level) {
293
+ throw context.runtime.newRaiseException(ActiveRecord(context).getClass("TransactionIsolationError"),
294
+ "SQLite3 does not support isolation levels");
295
+ }
296
+
285
297
  @Override
286
298
  @JRubyMethod(name = "create_savepoint", optional = 1)
287
299
  public IRubyObject create_savepoint(final ThreadContext context, final IRubyObject[] args) {
@@ -289,7 +301,7 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
289
301
  if ( name == null || name.isNil() ) {
290
302
  throw new IllegalArgumentException("create_savepoint (without name) not implemented!");
291
303
  }
292
- final Connection connection = getConnection(true);
304
+ final Connection connection = getConnection(context, true);
293
305
  try {
294
306
  connection.setAutoCommit(false);
295
307
  // NOTE: JDBC driver does not support setSavepoint(String) :
@@ -307,7 +319,7 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
307
319
  @Override
308
320
  @JRubyMethod(name = "rollback_savepoint", required = 1)
309
321
  public IRubyObject rollback_savepoint(final ThreadContext context, final IRubyObject name) {
310
- final Connection connection = getConnection(true);
322
+ final Connection connection = getConnection(context, true);
311
323
  try {
312
324
  if ( getSavepoints(context).get(name) == null ) {
313
325
  throw context.getRuntime().newRuntimeError("could not rollback savepoint: '" + name + "' (not set)");
@@ -322,22 +334,85 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
322
334
  }
323
335
  }
324
336
 
337
+ // FIXME: Update our JDBC adapter to later version which basically performs this SQL in
338
+ // this method. Then we can use base RubyJdbcConnection version.
325
339
  @Override
326
340
  @JRubyMethod(name = "release_savepoint", required = 1)
327
341
  public IRubyObject release_savepoint(final ThreadContext context, final IRubyObject name) {
328
- final Connection connection = getConnection(true);
342
+ Ruby runtime = context.runtime;
343
+
329
344
  try {
330
- if ( getSavepoints(context).remove(name) == null ) {
331
- throw context.getRuntime().newRuntimeError("could not release savepoint: '" + name + "' (not set)");
345
+ if (getSavepoints(context).remove(name) == null) {
346
+ RubyClass invalidStatement = ActiveRecord(context).getClass("StatementInvalid");
347
+ throw runtime.newRaiseException(invalidStatement, "could not release savepoint: '" + name + "' (not set)");
332
348
  }
333
349
  // NOTE: JDBC driver does not implement release(Savepoint) :
334
- connection.createStatement().execute("RELEASE SAVEPOINT " + name.toString());
350
+ getConnection(context, true).createStatement().execute("RELEASE SAVEPOINT " + name.toString());
335
351
 
336
- return context.getRuntime().getNil();
337
- }
338
- catch (SQLException e) {
352
+ return runtime.getNil();
353
+ } catch (SQLException e) {
339
354
  return handleException(context, e);
340
355
  }
341
356
  }
342
357
 
358
+ // Note: transaction_support.rb overrides sqlite3 adapters version which just returns true.
359
+ // Rather than re-define it in SQLite3Adapter I will just define it here so we appear to have
360
+ // a consistent JDBC layer.
361
+ @JRubyMethod(name = "supports_savepoints?")
362
+ public IRubyObject supports_savepoints_p(final ThreadContext context) throws SQLException {
363
+ return context.getRuntime().getTrue();
364
+ }
365
+
366
+ @Override
367
+ protected void setBooleanParameter(final ThreadContext context,
368
+ final Connection connection, final PreparedStatement statement,
369
+ final int index, final IRubyObject value,
370
+ final IRubyObject attribute, final int type) throws SQLException {
371
+ // Apparently active record stores booleans in sqlite as 't' and 'f' instead of the built in 1/0
372
+ statement.setString(index, value.isTrue() ? "t" : "f");
373
+ }
374
+
375
+ // Treat dates as strings, this can potentially be removed if we update
376
+ // the driver to the latest and tell it to store dates/times as text
377
+ @Override
378
+ protected void setDateParameter(final ThreadContext context,
379
+ final Connection connection, final PreparedStatement statement,
380
+ final int index, IRubyObject value,
381
+ final IRubyObject attribute, final int type) throws SQLException {
382
+
383
+ setStringParameter(context, connection, statement, index, value, attribute, type);
384
+ }
385
+
386
+ // The current driver doesn't support dealing with BigDecimal values, so force everything to doubles
387
+ @Override
388
+ protected void setDecimalParameter(final ThreadContext context,
389
+ final Connection connection, final PreparedStatement statement,
390
+ final int index, final IRubyObject value,
391
+ final IRubyObject attribute, final int type) throws SQLException {
392
+
393
+ setDoubleParameter(context, connection, statement, index, value, attribute, type);
394
+ }
395
+
396
+ // Treat times as strings
397
+ @Override
398
+ protected void setTimeParameter(final ThreadContext context,
399
+ final Connection connection, final PreparedStatement statement,
400
+ final int index, IRubyObject value,
401
+ final IRubyObject attribute, final int type) throws SQLException {
402
+
403
+ setTimestampParameter(context, connection, statement, index,
404
+ callMethod(context, "time_in_default_timezone", value), attribute, type);
405
+ }
406
+
407
+ // Treat timestamps as strings
408
+ @Override
409
+ protected void setTimestampParameter(final ThreadContext context,
410
+ final Connection connection, final PreparedStatement statement,
411
+ final int index, IRubyObject value,
412
+ final IRubyObject attribute, final int type) throws SQLException {
413
+
414
+ if (value instanceof RubyTime) value = ((RubyTime) value).strftime(TIMESTAMP_FORMAT);
415
+
416
+ setStringParameter(context, connection, statement, index, value, attribute, type);
417
+ }
343
418
  }
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-jdbc-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.pre1
4
+ version: '50.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sieger, Ola Bini, Karol Bucek and JRuby contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-10 00:00:00.000000000 Z
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activerecord
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '2.2'
19
+ name: activerecord
20
+ prerelease: false
21
+ type: :runtime
20
22
  version_requirements: !ruby/object:Gem::Requirement
21
23
  requirements:
22
24
  - - ">="
23
25
  - !ruby/object:Gem::Version
24
26
  version: '2.2'
25
- prerelease: false
26
- type: :runtime
27
27
  description: 'AR-JDBC is a database adapter for Rails'' ActiveRecord component designed
28
28
  to be used with JRuby built upon Java''s JDBC API for database access. Provides
29
29
  (ActiveRecord) built-in adapters: MySQL, PostgreSQL and SQLite3 as well as adapters
@@ -41,7 +41,6 @@ files:
41
41
  - ".gitignore"
42
42
  - ".travis.yml"
43
43
  - ".yardopts"
44
- - Appraisals
45
44
  - CONTRIBUTING.md
46
45
  - Gemfile
47
46
  - History.md
@@ -64,7 +63,6 @@ files:
64
63
  - lib/active_record/connection_adapters/mssql_adapter.rb
65
64
  - lib/active_record/connection_adapters/mysql2_adapter.rb
66
65
  - lib/active_record/connection_adapters/mysql_adapter.rb
67
- - lib/active_record/connection_adapters/oracle_adapter.rb
68
66
  - lib/active_record/connection_adapters/postgresql_adapter.rb
69
67
  - lib/active_record/connection_adapters/sqlite3_adapter.rb
70
68
  - lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -79,7 +77,11 @@ files:
79
77
  - lib/arel/visitors/sql_server.rb
80
78
  - lib/arel/visitors/sql_server/ng42.rb
81
79
  - lib/arjdbc.rb
82
- - lib/arjdbc/common_jdbc_methods.rb
80
+ - lib/arjdbc/abstract/connection_management.rb
81
+ - lib/arjdbc/abstract/core.rb
82
+ - lib/arjdbc/abstract/database_statements.rb
83
+ - lib/arjdbc/abstract/statement_cache.rb
84
+ - lib/arjdbc/abstract/transaction_support.rb
83
85
  - lib/arjdbc/db2.rb
84
86
  - lib/arjdbc/db2/adapter.rb
85
87
  - lib/arjdbc/db2/as400.rb
@@ -137,28 +139,18 @@ files:
137
139
  - lib/arjdbc/mssql/utils.rb
138
140
  - lib/arjdbc/mysql.rb
139
141
  - lib/arjdbc/mysql/adapter.rb
140
- - lib/arjdbc/mysql/bulk_change_table.rb
141
- - lib/arjdbc/mysql/column.rb
142
142
  - lib/arjdbc/mysql/connection_methods.rb
143
- - lib/arjdbc/mysql/explain_support.rb
144
- - lib/arjdbc/mysql/schema_creation.rb
145
- - lib/arjdbc/oracle.rb
146
- - lib/arjdbc/oracle/adapter.rb
147
- - lib/arjdbc/oracle/column.rb
148
- - lib/arjdbc/oracle/connection_methods.rb
149
143
  - lib/arjdbc/postgresql.rb
150
144
  - lib/arjdbc/postgresql/_bc_time_cast_patch.rb
151
145
  - lib/arjdbc/postgresql/adapter.rb
146
+ - lib/arjdbc/postgresql/base/array_decoder.rb
147
+ - lib/arjdbc/postgresql/base/array_encoder.rb
152
148
  - lib/arjdbc/postgresql/base/array_parser.rb
153
- - lib/arjdbc/postgresql/base/oid.rb
154
149
  - lib/arjdbc/postgresql/base/pgconn.rb
155
- - lib/arjdbc/postgresql/base/schema_definitions.rb
156
150
  - lib/arjdbc/postgresql/column.rb
157
151
  - lib/arjdbc/postgresql/connection_methods.rb
158
- - lib/arjdbc/postgresql/explain_support.rb
159
- - lib/arjdbc/postgresql/oid/bytea.rb
152
+ - lib/arjdbc/postgresql/name.rb
160
153
  - lib/arjdbc/postgresql/oid_types.rb
161
- - lib/arjdbc/postgresql/schema_creation.rb
162
154
  - lib/arjdbc/railtie.rb
163
155
  - lib/arjdbc/sqlite3.rb
164
156
  - lib/arjdbc/sqlite3/adapter.rb
@@ -176,8 +168,6 @@ files:
176
168
  - lib/arjdbc/tasks/hsqldb_database_tasks.rb
177
169
  - lib/arjdbc/tasks/jdbc_database_tasks.rb
178
170
  - lib/arjdbc/tasks/mssql_database_tasks.rb
179
- - lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb
180
- - lib/arjdbc/tasks/oracle_database_tasks.rb
181
171
  - lib/arjdbc/util/quoted_cache.rb
182
172
  - lib/arjdbc/util/serialized_attributes.rb
183
173
  - lib/arjdbc/util/table_copier.rb
@@ -216,8 +206,6 @@ files:
216
206
  - src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java
217
207
  - src/java/arjdbc/mysql/MySQLModule.java
218
208
  - src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java
219
- - src/java/arjdbc/oracle/OracleModule.java
220
- - src/java/arjdbc/oracle/OracleRubyJdbcConnection.java
221
209
  - src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java
222
210
  - src/java/arjdbc/sqlite3/SQLite3Module.java
223
211
  - src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java
@@ -243,14 +231,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
231
  version: '0'
244
232
  required_rubygems_version: !ruby/object:Gem::Requirement
245
233
  requirements:
246
- - - ">"
234
+ - - ">="
247
235
  - !ruby/object:Gem::Version
248
- version: 1.3.1
236
+ version: '0'
249
237
  requirements: []
250
238
  rubyforge_project: jruby-extras
251
- rubygems_version: 2.6.8
239
+ rubygems_version: 2.6.13
252
240
  signing_key:
253
241
  specification_version: 4
254
242
  summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
255
243
  test_files: []
256
- has_rdoc:
data/Appraisals DELETED
@@ -1,41 +0,0 @@
1
- appraise "rails23" do
2
- gem "activerecord", "~> 2.3.18", :require => false
3
- gem "rails", "~> 2.3.18"
4
- end
5
-
6
- appraise "rails30" do
7
- gem "activerecord", "~> 3.0.20", :require => false
8
- end
9
-
10
- appraise "rails31" do
11
- gem "activerecord", "~> 3.1.12", :require => false
12
- end
13
-
14
- appraise "rails32" do
15
- gem 'i18n', '< 0.7'
16
- gem "activerecord", "~> 3.2.19", :require => false
17
- end
18
-
19
- appraise "rails40" do
20
- gem "activerecord", "~> 4.0.12", :require => false
21
- end
22
-
23
- appraise "rails41" do
24
- gem "activerecord", "~> 4.1.8", :require => false
25
- end
26
-
27
- appraise "rails42" do
28
- gem "activerecord", "~> 4.2.0", :require => false
29
- end
30
-
31
- appraise "rails50" do
32
- gem "activerecord", "~> 5.0.0.beta4", :require => false
33
- end
34
-
35
-
36
- appraise "railsNG" do
37
- branch = ( ENV['rails_branch'] || 'master' )
38
- gem "activerecord", :github => 'rails/rails', :branch => branch, :require => false
39
- gem 'rails', :github => 'rails/rails', :branch => branch
40
- gem 'arel', :github => 'rails/arel', :branch => 'master'
41
- end
@@ -1 +0,0 @@
1
- require 'arjdbc/oracle'
@@ -1,89 +0,0 @@
1
- module ArJdbc
2
- # This is minimum amount of code neede from base JDBC Adapter class to make common adapters
3
- # work. This replaces using jdbc/adapter as a base class for all adapters.
4
- module CommonJdbcMethods
5
- def initialize(connection, logger = nil, config = {})
6
- config[:adapter_spec] = adapter_spec(config) unless config.key?(:adapter_spec)
7
-
8
- connection ||= jdbc_connection_class(config[:adapter_spec]).new(config, self)
9
-
10
- super(connection, logger, config)
11
- end
12
-
13
- # Starts a database transaction.
14
- # @override
15
- def begin_db_transaction
16
- @connection.begin
17
- end
18
-
19
- # Starts a database transaction.
20
- # @param isolation the transaction isolation to use
21
- def begin_isolated_db_transaction(isolation)
22
- @connection.begin(isolation)
23
- end
24
-
25
- # Commits the current database transaction.
26
- # @override
27
- def commit_db_transaction
28
- @connection.commit
29
- end
30
-
31
- # Rolls back the current database transaction.
32
- # @override
33
- def exec_rollback_db_transaction
34
- @connection.rollback
35
- end
36
-
37
-
38
- def execute(sql, name = nil)
39
- # FIXME: Can we kill :skip_logging?
40
- if name == :skip_logging
41
- @connection.execute(sql)
42
- else
43
- log(sql, name) { @connection.execute(sql) }
44
- end
45
- end
46
-
47
- # Take an id from the result of an INSERT query.
48
- # @return [Integer, NilClass]
49
- def last_inserted_id(result)
50
- if result.is_a?(Hash) || result.is_a?(ActiveRecord::Result)
51
- result.first.first[1] # .first = { "id"=>1 } .first = [ "id", 1 ]
52
- else
53
- result
54
- end
55
- end
56
-
57
- # Creates a (transactional) save-point one can rollback to.
58
- # Unlike 'plain' `ActiveRecord` it is allowed to pass a save-point name.
59
- # @param name the save-point name
60
- # @return save-point name (even if nil passed will be generated)
61
- # @since 1.3.0
62
- # @extension added optional name parameter
63
- def create_savepoint(name = current_savepoint_name(true))
64
- @connection.create_savepoint(name)
65
- end
66
-
67
- # Transaction rollback to a given (previously created) save-point.
68
- # If no save-point name given rollback to the last created one.
69
- # @param name the save-point name
70
- # @extension added optional name parameter
71
- def rollback_to_savepoint(name = current_savepoint_name(true))
72
- @connection.rollback_savepoint(name)
73
- end
74
-
75
- # Release a previously created save-point.
76
- # @note Save-points are auto-released with the transaction they're created
77
- # in (on transaction commit or roll-back).
78
- # @param name the save-point name
79
- # @extension added optional name parameter
80
- def release_savepoint(name = current_savepoint_name(false))
81
- @connection.release_savepoint(name)
82
- end
83
-
84
- # @private
85
- def current_savepoint_name(compat = nil)
86
- current_transaction.savepoint_name # unlike AR 3.2-4.1 might be nil
87
- end
88
- end
89
- end