activerecord-jdbc-adapter 5.0.pre1 → 51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -2
- data/.travis.yml +15 -416
- data/Gemfile +35 -37
- data/README.md +23 -118
- data/RUNNING_TESTS.md +31 -26
- data/Rakefile +2 -3
- data/activerecord-jdbc-adapter.gemspec +1 -2
- data/lib/arjdbc/abstract/connection_management.rb +21 -0
- data/lib/arjdbc/abstract/core.rb +62 -0
- data/lib/arjdbc/abstract/database_statements.rb +46 -0
- data/lib/arjdbc/abstract/statement_cache.rb +58 -0
- data/lib/arjdbc/abstract/transaction_support.rb +86 -0
- data/lib/arjdbc/derby/adapter.rb +6 -1
- data/lib/arjdbc/discover.rb +0 -7
- data/lib/arjdbc/firebird/adapter.rb +2 -2
- data/lib/arjdbc/jdbc/adapter.rb +10 -252
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/connection.rb +6 -0
- data/lib/arjdbc/jdbc.rb +2 -2
- data/lib/arjdbc/mysql/adapter.rb +87 -944
- data/lib/arjdbc/mysql/connection_methods.rb +4 -2
- data/lib/arjdbc/postgresql/adapter.rb +288 -1023
- data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +8 -5
- data/lib/arjdbc/postgresql/column.rb +10 -599
- data/lib/arjdbc/postgresql/connection_methods.rb +9 -0
- data/lib/arjdbc/postgresql/name.rb +24 -0
- data/lib/arjdbc/postgresql/oid_types.rb +25 -110
- data/lib/arjdbc/sqlite3/adapter.rb +171 -170
- data/lib/arjdbc/tasks/database_tasks.rb +1 -3
- data/lib/arjdbc/tasks/db2_database_tasks.rb +2 -2
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +3 -3
- data/rakelib/02-test.rake +0 -12
- data/rakelib/compile.rake +1 -1
- data/rakelib/db.rake +7 -5
- data/rakelib/rails.rake +63 -64
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +1 -17
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +518 -1260
- data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +53 -134
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -240
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +0 -20
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +85 -10
- metadata +20 -34
- data/Appraisals +0 -41
- data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
- data/lib/arjdbc/common_jdbc_methods.rb +0 -89
- data/lib/arjdbc/mysql/bulk_change_table.rb +0 -150
- data/lib/arjdbc/mysql/column.rb +0 -162
- data/lib/arjdbc/mysql/explain_support.rb +0 -82
- data/lib/arjdbc/mysql/schema_creation.rb +0 -58
- data/lib/arjdbc/oracle/adapter.rb +0 -952
- data/lib/arjdbc/oracle/column.rb +0 -126
- data/lib/arjdbc/oracle/connection_methods.rb +0 -21
- data/lib/arjdbc/oracle.rb +0 -4
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +0 -21
- data/lib/arjdbc/postgresql/base/oid.rb +0 -412
- data/lib/arjdbc/postgresql/base/schema_definitions.rb +0 -131
- data/lib/arjdbc/postgresql/explain_support.rb +0 -53
- data/lib/arjdbc/postgresql/oid/bytea.rb +0 -2
- data/lib/arjdbc/postgresql/schema_creation.rb +0 -60
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +0 -297
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +0 -65
- data/src/java/arjdbc/oracle/OracleModule.java +0 -75
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +0 -465
@@ -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
|
-
|
342
|
+
Ruby runtime = context.runtime;
|
343
|
+
|
329
344
|
try {
|
330
|
-
if (
|
331
|
-
|
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
|
-
|
350
|
+
getConnection(context, true).createStatement().execute("RELEASE SAVEPOINT " + name.toString());
|
335
351
|
|
336
|
-
return
|
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:
|
4
|
+
version: '51.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:
|
11
|
+
date: 2017-11-16 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
|
-
version:
|
18
|
+
version: 5.1.0
|
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
|
-
version:
|
25
|
-
prerelease: false
|
26
|
-
type: :runtime
|
26
|
+
version: 5.1.0
|
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/
|
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,17 @@ 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
|
-
- lib/arjdbc/postgresql/_bc_time_cast_patch.rb
|
151
144
|
- lib/arjdbc/postgresql/adapter.rb
|
145
|
+
- lib/arjdbc/postgresql/base/array_decoder.rb
|
146
|
+
- lib/arjdbc/postgresql/base/array_encoder.rb
|
152
147
|
- lib/arjdbc/postgresql/base/array_parser.rb
|
153
|
-
- lib/arjdbc/postgresql/base/oid.rb
|
154
148
|
- lib/arjdbc/postgresql/base/pgconn.rb
|
155
|
-
- lib/arjdbc/postgresql/base/schema_definitions.rb
|
156
149
|
- lib/arjdbc/postgresql/column.rb
|
157
150
|
- lib/arjdbc/postgresql/connection_methods.rb
|
158
|
-
- lib/arjdbc/postgresql/
|
159
|
-
- lib/arjdbc/postgresql/oid/bytea.rb
|
151
|
+
- lib/arjdbc/postgresql/name.rb
|
160
152
|
- lib/arjdbc/postgresql/oid_types.rb
|
161
|
-
- lib/arjdbc/postgresql/schema_creation.rb
|
162
153
|
- lib/arjdbc/railtie.rb
|
163
154
|
- lib/arjdbc/sqlite3.rb
|
164
155
|
- lib/arjdbc/sqlite3/adapter.rb
|
@@ -176,8 +167,6 @@ files:
|
|
176
167
|
- lib/arjdbc/tasks/hsqldb_database_tasks.rb
|
177
168
|
- lib/arjdbc/tasks/jdbc_database_tasks.rb
|
178
169
|
- 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
170
|
- lib/arjdbc/util/quoted_cache.rb
|
182
171
|
- lib/arjdbc/util/serialized_attributes.rb
|
183
172
|
- lib/arjdbc/util/table_copier.rb
|
@@ -216,8 +205,6 @@ files:
|
|
216
205
|
- src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java
|
217
206
|
- src/java/arjdbc/mysql/MySQLModule.java
|
218
207
|
- src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java
|
219
|
-
- src/java/arjdbc/oracle/OracleModule.java
|
220
|
-
- src/java/arjdbc/oracle/OracleRubyJdbcConnection.java
|
221
208
|
- src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java
|
222
209
|
- src/java/arjdbc/sqlite3/SQLite3Module.java
|
223
210
|
- src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java
|
@@ -243,14 +230,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
243
230
|
version: '0'
|
244
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
245
232
|
requirements:
|
246
|
-
- - "
|
233
|
+
- - ">="
|
247
234
|
- !ruby/object:Gem::Version
|
248
|
-
version:
|
235
|
+
version: '0'
|
249
236
|
requirements: []
|
250
237
|
rubyforge_project: jruby-extras
|
251
|
-
rubygems_version: 2.6.
|
238
|
+
rubygems_version: 2.6.13
|
252
239
|
signing_key:
|
253
240
|
specification_version: 4
|
254
241
|
summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
|
255
242
|
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
|
@@ -1,150 +0,0 @@
|
|
1
|
-
module ArJdbc
|
2
|
-
module MySQL
|
3
|
-
module BulkChangeTable
|
4
|
-
|
5
|
-
# @private
|
6
|
-
AR41 = ::ActiveRecord::VERSION::STRING >= '4.1'
|
7
|
-
|
8
|
-
# @private
|
9
|
-
#ActiveRecordError = ActiveRecord::ActiveRecordError
|
10
|
-
|
11
|
-
# @private
|
12
|
-
ChangeColumnDefinition = ::ActiveRecord::ConnectionAdapters::ChangeColumnDefinition if AR41
|
13
|
-
|
14
|
-
# @override
|
15
|
-
def supports_bulk_alter?; true end
|
16
|
-
|
17
|
-
def bulk_change_table(table_name, operations)
|
18
|
-
sqls = operations.map do |command, args|
|
19
|
-
table, arguments = args.shift, args
|
20
|
-
method = :"#{command}_sql"
|
21
|
-
|
22
|
-
if respond_to?(method, true)
|
23
|
-
send(method, table, *arguments)
|
24
|
-
else
|
25
|
-
raise "Unknown method called : #{method}(#{arguments.inspect})"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
sqls.flatten!
|
29
|
-
|
30
|
-
execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls.join(", ")}")
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
|
35
|
-
def add_column_sql(table_name, column_name, type, options = {})
|
36
|
-
add_column_sql = "ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
|
37
|
-
add_column_options!(add_column_sql, options)
|
38
|
-
add_column_position!(add_column_sql, options)
|
39
|
-
add_column_sql
|
40
|
-
end unless AR41
|
41
|
-
|
42
|
-
def add_column_sql(table_name, column_name, type, options = {})
|
43
|
-
td = create_table_definition table_name, options[:temporary], options[:options]
|
44
|
-
cd = td.new_column_definition(column_name, type, options)
|
45
|
-
schema_creation.visit_AddColumn cd
|
46
|
-
end if AR41
|
47
|
-
|
48
|
-
def change_column_sql(table_name, column_name, type, options = {})
|
49
|
-
column = column_for(table_name, column_name)
|
50
|
-
|
51
|
-
unless options_include_default?(options)
|
52
|
-
options[:default] = column.default
|
53
|
-
end
|
54
|
-
|
55
|
-
unless options.has_key?(:null)
|
56
|
-
options[:null] = column.null
|
57
|
-
end
|
58
|
-
|
59
|
-
change_column_sql = "CHANGE #{quote_column_name(column_name)} #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
|
60
|
-
add_column_options!(change_column_sql, options)
|
61
|
-
add_column_position!(change_column_sql, options)
|
62
|
-
change_column_sql
|
63
|
-
end unless AR41
|
64
|
-
|
65
|
-
def change_column_sql(table_name, column_name, type, options = {})
|
66
|
-
column = column_for(table_name, column_name)
|
67
|
-
|
68
|
-
unless options_include_default?(options)
|
69
|
-
options[:default] = column.default
|
70
|
-
end
|
71
|
-
|
72
|
-
unless options.has_key?(:null)
|
73
|
-
options[:null] = column.null
|
74
|
-
end
|
75
|
-
|
76
|
-
options[:name] = column.name
|
77
|
-
schema_creation.accept ChangeColumnDefinition.new column, type, options
|
78
|
-
end if AR41
|
79
|
-
|
80
|
-
def rename_column_sql(table_name, column_name, new_column_name)
|
81
|
-
options = {}
|
82
|
-
|
83
|
-
if column = columns(table_name).find { |c| c.name == column_name.to_s }
|
84
|
-
options[:default] = column.default
|
85
|
-
options[:null] = column.null
|
86
|
-
options[:auto_increment] = (column.extra == "auto_increment")
|
87
|
-
else
|
88
|
-
raise ActiveRecordError, "No such column: #{table_name}.#{column_name}"
|
89
|
-
end
|
90
|
-
|
91
|
-
current_type = select_one("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE '#{column_name}'", 'SCHEMA')["Type"]
|
92
|
-
rename_column_sql = "CHANGE #{quote_column_name(column_name)} #{quote_column_name(new_column_name)} #{current_type}"
|
93
|
-
add_column_options!(rename_column_sql, options)
|
94
|
-
rename_column_sql
|
95
|
-
end unless AR41
|
96
|
-
|
97
|
-
def rename_column_sql(table_name, column_name, new_column_name)
|
98
|
-
options = { :name => new_column_name }
|
99
|
-
|
100
|
-
if column = columns(table_name).find { |c| c.name == column_name.to_s }
|
101
|
-
options[:default] = column.default
|
102
|
-
options[:null] = column.null
|
103
|
-
options[:auto_increment] = (column.extra == "auto_increment")
|
104
|
-
else
|
105
|
-
raise ActiveRecordError, "No such column: #{table_name}.#{column_name}"
|
106
|
-
end
|
107
|
-
|
108
|
-
current_type = select_one("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE '#{column_name}'", 'SCHEMA')["Type"]
|
109
|
-
schema_creation.accept ChangeColumnDefinition.new column, current_type, options
|
110
|
-
end if AR41
|
111
|
-
|
112
|
-
def remove_column_sql(table_name, column_name, type = nil, options = nil)
|
113
|
-
"DROP #{quote_column_name(column_name)}"
|
114
|
-
end
|
115
|
-
|
116
|
-
def remove_columns_sql(table_name, *column_names)
|
117
|
-
column_names.map { |column_name| remove_column_sql(table_name, column_name) }
|
118
|
-
end
|
119
|
-
|
120
|
-
def add_index_sql(table_name, column_name, options = {})
|
121
|
-
index_name, index_type, index_columns = add_index_options(table_name, column_name, options)
|
122
|
-
"ADD #{index_type} INDEX #{index_name} (#{index_columns})"
|
123
|
-
end
|
124
|
-
|
125
|
-
def remove_index_sql(table_name, options = {})
|
126
|
-
index_name = index_name_for_remove(table_name, options)
|
127
|
-
"DROP INDEX #{index_name}"
|
128
|
-
end
|
129
|
-
|
130
|
-
def add_timestamps_sql(table_name, options = {})
|
131
|
-
[add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)]
|
132
|
-
end
|
133
|
-
|
134
|
-
def remove_timestamps_sql(table_name, options = nil)
|
135
|
-
[remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)]
|
136
|
-
end
|
137
|
-
|
138
|
-
private
|
139
|
-
|
140
|
-
def add_column_position!(sql, options)
|
141
|
-
if options[:first]
|
142
|
-
sql << " FIRST"
|
143
|
-
elsif options[:after]
|
144
|
-
sql << " AFTER #{quote_column_name(options[:after])}"
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|