activerecord-jdbc-alt-adapter 72.1.0-java → 80.0.0.rc1-java
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 +4 -4
- data/.github/workflows/main.yml +23 -16
- data/.github/workflows/ruby.yml +123 -18
- data/.mise.toml +3 -0
- data/Gemfile +43 -48
- data/README.md +3 -2
- data/RUNNING_TESTS.md +9 -1
- data/Rakefile +63 -15
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/activerecord-jdbc-alt-adapter.gemspec +1 -1
- data/lib/arjdbc/abstract/core.rb +0 -17
- data/lib/arjdbc/abstract/database_statements.rb +21 -18
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/mssql/adapter.rb +11 -11
- data/lib/arjdbc/mssql/database_statements.rb +30 -28
- data/lib/arjdbc/mssql/explain_support.rb +6 -1
- data/lib/arjdbc/mssql.rb +1 -1
- data/lib/arjdbc/postgresql/adapter.rb +4 -1
- data/lib/arjdbc/postgresql/database_statements.rb +45 -0
- data/lib/arjdbc/postgresql/schema_statements.rb +17 -0
- data/lib/arjdbc/sqlite3/adapter.rb +51 -7
- data/lib/arjdbc/sqlite3/database_statements.rb +26 -0
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +3 -3
- data/rakelib/02-test.rake +1 -1
- data/rakelib/db.rake +5 -3
- data/rakelib/rails.rake +0 -1
- data/src/java/arjdbc/ArJdbcModule.java +13 -10
- data/src/java/arjdbc/db2/DB2Module.java +4 -4
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +8 -9
- data/src/java/arjdbc/h2/H2Module.java +2 -1
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +8 -7
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +5 -6
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +4 -3
- data/src/java/arjdbc/jdbc/DriverWrapper.java +13 -8
- data/src/java/arjdbc/jdbc/JdbcResult.java +10 -7
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +168 -154
- data/src/java/arjdbc/mssql/MSSQLModule.java +3 -3
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +13 -9
- data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +25 -23
- data/src/java/arjdbc/oracle/OracleModule.java +2 -3
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +22 -18
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +2 -3
- data/src/java/arjdbc/postgresql/PostgreSQLResult.java +24 -12
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +16 -12
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +2 -3
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +78 -29
- data/src/java/arjdbc/util/DateTimeUtils.java +7 -5
- data/src/java/arjdbc/util/ObjectSupport.java +2 -2
- data/src/java/arjdbc/util/StringHelper.java +1 -1
- metadata +7 -6
- data/.travis.yml +0 -128
|
@@ -31,6 +31,7 @@ import java.io.InputStreamReader;
|
|
|
31
31
|
import java.io.PrintStream;
|
|
32
32
|
import java.io.Reader;
|
|
33
33
|
import java.io.StringReader;
|
|
34
|
+
import java.lang.reflect.InvocationTargetException;
|
|
34
35
|
import java.math.BigDecimal;
|
|
35
36
|
import java.math.BigInteger;
|
|
36
37
|
import java.sql.Array;
|
|
@@ -109,6 +110,14 @@ import arjdbc.util.StringCache;
|
|
|
109
110
|
import static arjdbc.jdbc.DataSourceConnectionFactory.*;
|
|
110
111
|
import static arjdbc.util.StringHelper.*;
|
|
111
112
|
import static org.jruby.RubyTime.getLocalTimeZone;
|
|
113
|
+
import static org.jruby.api.Access.getModule;
|
|
114
|
+
import static org.jruby.api.Access.objectClass;
|
|
115
|
+
import static org.jruby.api.Convert.asFixnum;
|
|
116
|
+
import static org.jruby.api.Convert.toInt;
|
|
117
|
+
import static org.jruby.api.Create.allocArray;
|
|
118
|
+
import static org.jruby.api.Create.newArray;
|
|
119
|
+
import static org.jruby.api.Create.newArrayNoCopy;
|
|
120
|
+
import static org.jruby.api.Create.newEmptyArray;
|
|
112
121
|
|
|
113
122
|
|
|
114
123
|
/**
|
|
@@ -135,8 +144,9 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
135
144
|
|
|
136
145
|
protected RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
|
137
146
|
super(runtime, metaClass);
|
|
138
|
-
|
|
139
|
-
|
|
147
|
+
var context = runtime.getCurrentContext();
|
|
148
|
+
attributeClass = getModule(context, "ActiveModel").getClass(context, "Attribute");
|
|
149
|
+
timeZoneClass = getModule(context, "ActiveSupport").getClass(context, "TimeWithZone");
|
|
140
150
|
}
|
|
141
151
|
|
|
142
152
|
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
|
@@ -146,87 +156,92 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
146
156
|
};
|
|
147
157
|
|
|
148
158
|
public static RubyClass createJdbcConnectionClass(final Ruby runtime) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
var context = runtime.getCurrentContext();
|
|
160
|
+
return getConnectionAdapters(context).
|
|
161
|
+
defineClassUnder(context, "JdbcConnection", runtime.getObject(), ALLOCATOR).
|
|
162
|
+
defineMethods(context, RubyJdbcConnection.class);
|
|
153
163
|
}
|
|
154
164
|
|
|
155
|
-
public static RubyClass getJdbcConnection(
|
|
156
|
-
return
|
|
165
|
+
public static RubyClass getJdbcConnection(ThreadContext context) {
|
|
166
|
+
return getConnectionAdapters(context).getClass(context, "JdbcConnection");
|
|
157
167
|
}
|
|
158
168
|
|
|
159
169
|
protected static RubyModule ActiveRecord(ThreadContext context) {
|
|
160
|
-
return
|
|
170
|
+
return getModule(context, "ActiveRecord");
|
|
161
171
|
}
|
|
162
172
|
|
|
163
|
-
|
|
164
|
-
|
|
173
|
+
@Deprecated
|
|
174
|
+
public static RubyClass getBase(ThreadContext context) {
|
|
175
|
+
return getModule(context, "ActiveRecord").getClass("Base");
|
|
165
176
|
}
|
|
166
177
|
|
|
167
178
|
/**
|
|
168
|
-
* @param
|
|
179
|
+
* @param context the thread context
|
|
169
180
|
* @return <code>ActiveRecord::Result</code>
|
|
170
181
|
*/
|
|
171
|
-
public static RubyClass getResult(
|
|
172
|
-
return (
|
|
182
|
+
public static RubyClass getResult(ThreadContext context) {
|
|
183
|
+
return getModule(context, "ActiveRecord").getClass(context, "Result");
|
|
173
184
|
}
|
|
174
185
|
|
|
175
186
|
/**
|
|
176
|
-
* @param
|
|
187
|
+
* @param context the thread context
|
|
177
188
|
* @return <code>ActiveRecord::ConnectionAdapters</code>
|
|
178
189
|
*/
|
|
179
|
-
public static RubyModule getConnectionAdapters(
|
|
180
|
-
return (
|
|
190
|
+
public static RubyModule getConnectionAdapters(ThreadContext context) {
|
|
191
|
+
return getModule(context, "ActiveRecord").getModule(context, "ConnectionAdapters");
|
|
181
192
|
}
|
|
182
193
|
|
|
183
194
|
/**
|
|
184
|
-
*
|
|
195
|
+
* resolve <code>ActiveRecord::ConnectionAdapters::IndexDefinition</code>.
|
|
196
|
+
*
|
|
197
|
+
* @param context the thread context
|
|
185
198
|
* @return <code>ActiveRecord::ConnectionAdapters::IndexDefinition</code>
|
|
186
199
|
*/
|
|
187
|
-
protected static RubyClass
|
|
188
|
-
return getConnectionAdapters(
|
|
200
|
+
protected static RubyClass indexDefinition(ThreadContext context) {
|
|
201
|
+
return getConnectionAdapters(context).getClass(context, "IndexDefinition");
|
|
189
202
|
}
|
|
190
203
|
|
|
191
204
|
/**
|
|
192
|
-
*
|
|
205
|
+
* resolve <code>ActiveRecord::ConnectionAdapters::ForeignKeyDefinition</code>.
|
|
206
|
+
*
|
|
207
|
+
* @param context the thread context.
|
|
193
208
|
* @return <code>ActiveRecord::ConnectionAdapters::ForeignKeyDefinition</code>
|
|
194
209
|
* @note only since AR 4.2
|
|
195
210
|
*/
|
|
196
|
-
protected static RubyClass
|
|
197
|
-
return getConnectionAdapters(
|
|
211
|
+
protected static RubyClass foreignKeyDefinition(ThreadContext context) {
|
|
212
|
+
return getConnectionAdapters(context).getClass(context, "ForeignKeyDefinition");
|
|
198
213
|
}
|
|
199
214
|
|
|
200
215
|
/**
|
|
201
|
-
* @param
|
|
216
|
+
* @param context the thread context
|
|
202
217
|
* @return <code>ActiveRecord::JDBCError</code>
|
|
203
218
|
*/
|
|
204
|
-
protected static RubyClass getJDBCError(
|
|
205
|
-
return
|
|
219
|
+
protected static RubyClass getJDBCError(ThreadContext context) {
|
|
220
|
+
return getModule(context, "ActiveRecord").getClass(context, "JDBCError");
|
|
206
221
|
}
|
|
207
222
|
|
|
208
223
|
/**
|
|
209
|
-
* @param
|
|
224
|
+
* @param context the thread context
|
|
210
225
|
* @return <code>ActiveRecord::ConnectionNotEstablished</code>
|
|
211
226
|
*/
|
|
212
|
-
protected static RubyClass getConnectionNotEstablished(
|
|
213
|
-
return
|
|
227
|
+
protected static RubyClass getConnectionNotEstablished(ThreadContext context) {
|
|
228
|
+
return getModule(context, "ActiveRecord").getClass(context, "ConnectionNotEstablished");
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
/**
|
|
217
|
-
* @param
|
|
232
|
+
* @param context the thread context
|
|
218
233
|
* @return <code>ActiveRecord::NoDatabaseError</code>
|
|
219
234
|
*/
|
|
220
|
-
protected static RubyClass getNoDatabaseError(
|
|
221
|
-
return
|
|
235
|
+
protected static RubyClass getNoDatabaseError(ThreadContext context) {
|
|
236
|
+
return getModule(context, "ActiveRecord").getClass(context, "NoDatabaseError");
|
|
222
237
|
}
|
|
223
238
|
|
|
224
239
|
/**
|
|
225
|
-
* @param
|
|
240
|
+
* @param context the thread context
|
|
226
241
|
* @return <code>ActiveRecord::TransactionIsolationError</code>
|
|
227
242
|
*/
|
|
228
|
-
protected static RubyClass getTransactionIsolationError(
|
|
229
|
-
return (
|
|
243
|
+
protected static RubyClass getTransactionIsolationError(ThreadContext context) {
|
|
244
|
+
return getModule(context, "ActiveRecord").getClass(context, "TransactionIsolationError");
|
|
230
245
|
}
|
|
231
246
|
|
|
232
247
|
@JRubyMethod(name = "transaction_isolation", alias = "get_transaction_isolation")
|
|
@@ -351,7 +366,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
351
366
|
connection.setTransactionIsolation(level);
|
|
352
367
|
}
|
|
353
368
|
catch (SQLException e) {
|
|
354
|
-
RubyClass txError = ActiveRecord(context).getClass("TransactionIsolationError");
|
|
369
|
+
RubyClass txError = ActiveRecord(context).getClass(context, "TransactionIsolationError");
|
|
355
370
|
if ( txError != null ) throw wrapException(context, txError, e);
|
|
356
371
|
throw e; // let it roll - will be wrapped into a JDBCError (non 4.0)
|
|
357
372
|
}
|
|
@@ -485,7 +500,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
485
500
|
}
|
|
486
501
|
|
|
487
502
|
protected static RuntimeException newSavepointNotSetError(final ThreadContext context, final IRubyObject name, final String op) {
|
|
488
|
-
RubyClass StatementInvalid = ActiveRecord(context).getClass("StatementInvalid");
|
|
503
|
+
RubyClass StatementInvalid = ActiveRecord(context).getClass(context, "StatementInvalid");
|
|
489
504
|
return context.runtime.newRaiseException(StatementInvalid, "could not " + op + " savepoint: '" + name + "' (not set)");
|
|
490
505
|
}
|
|
491
506
|
|
|
@@ -495,13 +510,13 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
495
510
|
@SuppressWarnings("unchecked")
|
|
496
511
|
final Map<IRubyObject, Savepoint> savepoints = getSavepoints(false);
|
|
497
512
|
if ( savepoints != null ) {
|
|
498
|
-
final RubyArray names = context
|
|
513
|
+
final RubyArray names = allocArray(context, savepoints.size());
|
|
499
514
|
for ( Map.Entry<IRubyObject, ?> entry : savepoints.entrySet() ) {
|
|
500
|
-
names.append( entry.getKey()
|
|
515
|
+
names.append(context, entry.getKey()); // keys are RubyString instances
|
|
501
516
|
}
|
|
502
517
|
return names;
|
|
503
518
|
}
|
|
504
|
-
return
|
|
519
|
+
return newEmptyArray(context);
|
|
505
520
|
}
|
|
506
521
|
|
|
507
522
|
protected Map<IRubyObject, Savepoint> getSavepoints(final ThreadContext context) {
|
|
@@ -562,7 +577,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
562
577
|
|
|
563
578
|
IRubyObject jdbcFetchSize = getConfigValue(context, "jdbc_fetch_size");
|
|
564
579
|
if (jdbcFetchSize != context.nil) {
|
|
565
|
-
this.fetchSize =
|
|
580
|
+
this.fetchSize = toInt(context, jdbcFetchSize);
|
|
566
581
|
}
|
|
567
582
|
}
|
|
568
583
|
|
|
@@ -1021,7 +1036,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1021
1036
|
switch (args.length) {
|
|
1022
1037
|
case 2:
|
|
1023
1038
|
if (args[1] instanceof RubyNumeric) { // (sql, max_rows)
|
|
1024
|
-
maxRows =
|
|
1039
|
+
maxRows = toInt(context, args[1]);
|
|
1025
1040
|
binds = null;
|
|
1026
1041
|
} else { // (sql, binds)
|
|
1027
1042
|
maxRows = 0;
|
|
@@ -1029,7 +1044,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1029
1044
|
}
|
|
1030
1045
|
break;
|
|
1031
1046
|
case 3: // (sql, max_rows, binds)
|
|
1032
|
-
maxRows =
|
|
1047
|
+
maxRows = toInt(context, args[1]);
|
|
1033
1048
|
binds = (RubyArray) TypeConverter.checkArrayType(context, args[2]);
|
|
1034
1049
|
break;
|
|
1035
1050
|
default: // (sql) 1-arg
|
|
@@ -1071,7 +1086,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1071
1086
|
if (hasResult) {
|
|
1072
1087
|
return mapToRawResult(context, connection, statement.getResultSet(), false);
|
|
1073
1088
|
}
|
|
1074
|
-
return
|
|
1089
|
+
return newEmptyArray(context);
|
|
1075
1090
|
}
|
|
1076
1091
|
catch (final SQLException e) {
|
|
1077
1092
|
debugErrorSQL(context, query);
|
|
@@ -1238,7 +1253,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1238
1253
|
public IRubyObject primary_keys(ThreadContext context, IRubyObject tableName) throws SQLException {
|
|
1239
1254
|
@SuppressWarnings("unchecked")
|
|
1240
1255
|
List<IRubyObject> primaryKeys = (List) primaryKeys(context, tableName.toString());
|
|
1241
|
-
return
|
|
1256
|
+
return newArray(context, primaryKeys);
|
|
1242
1257
|
}
|
|
1243
1258
|
|
|
1244
1259
|
protected static final int PRIMARY_KEYS_COLUMN_NAME = 4;
|
|
@@ -1386,7 +1401,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1386
1401
|
final List<RubyString> primaryKeys = primaryKeys(context, connection, table);
|
|
1387
1402
|
|
|
1388
1403
|
ResultSet indexInfoSet = null;
|
|
1389
|
-
final RubyArray indexes =
|
|
1404
|
+
final RubyArray indexes = allocArray(context, 8);
|
|
1390
1405
|
try {
|
|
1391
1406
|
final DatabaseMetaData metaData = connection.getMetaData();
|
|
1392
1407
|
indexInfoSet = metaData.getIndexInfo(table.catalog, table.schema, table.name, false, true);
|
|
@@ -1418,15 +1433,15 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1418
1433
|
cachedString(context, indexTableName), // table_name
|
|
1419
1434
|
cachedString(context, indexName), // index_name
|
|
1420
1435
|
nonUnique ? context.fals : context.tru, // unique
|
|
1421
|
-
currentColumns =
|
|
1436
|
+
currentColumns = allocArray(context, 4) // [] column names
|
|
1422
1437
|
// orders, (since AR 3.2) where, type, using (AR 4.0)
|
|
1423
1438
|
};
|
|
1424
1439
|
|
|
1425
|
-
indexes.append( IndexDefinition.newInstance(context, args, Block.NULL_BLOCK)
|
|
1440
|
+
indexes.append(context, IndexDefinition.newInstance(context, args, Block.NULL_BLOCK)); // IndexDefinition.new
|
|
1426
1441
|
}
|
|
1427
1442
|
|
|
1428
1443
|
// one or more columns can be associated with an index
|
|
1429
|
-
if ( currentColumns != null ) currentColumns.append(rubyColumnName);
|
|
1444
|
+
if ( currentColumns != null ) currentColumns.append(context, rubyColumnName);
|
|
1430
1445
|
}
|
|
1431
1446
|
|
|
1432
1447
|
return indexes;
|
|
@@ -1436,9 +1451,8 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1436
1451
|
}
|
|
1437
1452
|
|
|
1438
1453
|
protected RubyClass getIndexDefinition(final ThreadContext context) {
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
return IDef != null ? (RubyClass) IDef : getIndexDefinition(context.runtime);
|
|
1454
|
+
var IDef = adapter.getMetaClass().getClass(context, "IndexDefinition");
|
|
1455
|
+
return IDef != null ? IDef : indexDefinition(context);
|
|
1442
1456
|
}
|
|
1443
1457
|
|
|
1444
1458
|
@JRubyMethod
|
|
@@ -1493,7 +1507,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1493
1507
|
fKeys.add( FKDefinition.newInstance(context, from_table, to_table, options, Block.NULL_BLOCK) ); // ForeignKeyDefinition.new
|
|
1494
1508
|
}
|
|
1495
1509
|
|
|
1496
|
-
return
|
|
1510
|
+
return newArray(context, fKeys);
|
|
1497
1511
|
|
|
1498
1512
|
} finally { close(fkInfoSet); }
|
|
1499
1513
|
});
|
|
@@ -1511,8 +1525,8 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1511
1525
|
|
|
1512
1526
|
protected RubyClass getForeignKeyDefinition(final ThreadContext context) {
|
|
1513
1527
|
final RubyClass adapterClass = adapter.getMetaClass();
|
|
1514
|
-
|
|
1515
|
-
return FKDef != null ?
|
|
1528
|
+
var FKDef = adapterClass.getClass(context, "ForeignKeyDefinition");
|
|
1529
|
+
return FKDef != null ? FKDef : foreignKeyDefinition(context);
|
|
1516
1530
|
}
|
|
1517
1531
|
|
|
1518
1532
|
|
|
@@ -1619,7 +1633,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1619
1633
|
}
|
|
1620
1634
|
setStatementParameter(context, context.runtime, connection, statement, 2, idValue, idColumn);
|
|
1621
1635
|
*/
|
|
1622
|
-
return statement.executeUpdate();
|
|
1636
|
+
return (Integer) statement.executeUpdate();
|
|
1623
1637
|
}
|
|
1624
1638
|
finally { close(statement); }
|
|
1625
1639
|
});
|
|
@@ -1700,7 +1714,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1700
1714
|
return block.call(context, JavaUtil.convertJavaToRuby(context.runtime, metaData));
|
|
1701
1715
|
}
|
|
1702
1716
|
catch (SQLException e) {
|
|
1703
|
-
throw wrapSQLException(context, getJDBCError(context
|
|
1717
|
+
throw wrapSQLException(context, getJDBCError(context), e, null);
|
|
1704
1718
|
}
|
|
1705
1719
|
finally { close(connection); }
|
|
1706
1720
|
}
|
|
@@ -1766,9 +1780,8 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1766
1780
|
final IRubyObject driver_instance = getConfigValue(context, "driver_instance");
|
|
1767
1781
|
|
|
1768
1782
|
if ( url.isNil() || ( driver.isNil() && driver_instance.isNil() ) ) {
|
|
1769
|
-
final
|
|
1770
|
-
|
|
1771
|
-
throw runtime.newRaiseException(errorClass, "adapter requires :driver class and jdbc :url");
|
|
1783
|
+
final RubyClass errorClass = getConnectionNotEstablished(context);
|
|
1784
|
+
throw context.runtime.newRaiseException(errorClass, "adapter requires :driver class and jdbc :url");
|
|
1772
1785
|
}
|
|
1773
1786
|
|
|
1774
1787
|
final String jdbcURL = buildURL(context, url);
|
|
@@ -1824,6 +1837,10 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
1824
1837
|
}
|
|
1825
1838
|
catch (SecurityException e) {
|
|
1826
1839
|
throw wrapException(context, context.runtime.getSecurityError(), e);
|
|
1840
|
+
} catch (InvocationTargetException e) {
|
|
1841
|
+
throw wrapException(context, context.runtime.getNameError(), e, "invalid invocation target for " + driver);
|
|
1842
|
+
} catch (NoSuchMethodException e) {
|
|
1843
|
+
throw wrapException(context, context.runtime.getNameError(), e, "cannot find constructor for " + driver);
|
|
1827
1844
|
}
|
|
1828
1845
|
}
|
|
1829
1846
|
|
|
@@ -2008,10 +2025,10 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2008
2025
|
final ResultSet resultSet, final ColumnData[] columns) throws SQLException {
|
|
2009
2026
|
final Ruby runtime = context.runtime;
|
|
2010
2027
|
|
|
2011
|
-
final RubyArray resultRows =
|
|
2028
|
+
final RubyArray resultRows = newArray(context);
|
|
2012
2029
|
|
|
2013
2030
|
while (resultSet.next()) {
|
|
2014
|
-
resultRows.append(mapRow(context, runtime, columns, resultSet, this));
|
|
2031
|
+
resultRows.append(context, mapRow(context, runtime, columns, resultSet, this));
|
|
2015
2032
|
}
|
|
2016
2033
|
|
|
2017
2034
|
return newResult(context, columns, resultRows);
|
|
@@ -2163,7 +2180,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2163
2180
|
static {
|
|
2164
2181
|
final String dateTimeRaw = SafePropertyAccessor.getProperty("arjdbc.datetime.raw");
|
|
2165
2182
|
if ( dateTimeRaw != null ) {
|
|
2166
|
-
rawDateTime = Boolean.parseBoolean(dateTimeRaw);
|
|
2183
|
+
rawDateTime = (Boolean) Boolean.parseBoolean(dateTimeRaw);
|
|
2167
2184
|
}
|
|
2168
2185
|
// NOTE: we do this since it will have a different value depending on
|
|
2169
2186
|
// AR version - since 4.0 false by default otherwise will be true ...
|
|
@@ -2178,7 +2195,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2178
2195
|
@JRubyMethod(name = "raw_date_time=", meta = true)
|
|
2179
2196
|
public static IRubyObject setRawDateTime(final IRubyObject self, final IRubyObject value) {
|
|
2180
2197
|
if ( value instanceof RubyBoolean ) {
|
|
2181
|
-
rawDateTime = (
|
|
2198
|
+
rawDateTime = (Boolean) value.isTrue();
|
|
2182
2199
|
}
|
|
2183
2200
|
else {
|
|
2184
2201
|
rawDateTime = value.isNil() ? null : Boolean.TRUE;
|
|
@@ -2244,7 +2261,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2244
2261
|
static {
|
|
2245
2262
|
final String booleanRaw = SafePropertyAccessor.getProperty("arjdbc.boolean.raw");
|
|
2246
2263
|
if ( booleanRaw != null ) {
|
|
2247
|
-
rawBoolean = Boolean.parseBoolean(booleanRaw);
|
|
2264
|
+
rawBoolean = (Boolean) Boolean.parseBoolean(booleanRaw);
|
|
2248
2265
|
}
|
|
2249
2266
|
}
|
|
2250
2267
|
|
|
@@ -2257,7 +2274,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2257
2274
|
@JRubyMethod(name = "raw_boolean=", meta = true)
|
|
2258
2275
|
public static IRubyObject setRawBoolean(final IRubyObject self, final IRubyObject value) {
|
|
2259
2276
|
if ( value instanceof RubyBoolean ) {
|
|
2260
|
-
rawBoolean = (
|
|
2277
|
+
rawBoolean = (Boolean) value.isTrue();
|
|
2261
2278
|
}
|
|
2262
2279
|
else {
|
|
2263
2280
|
rawBoolean = value.isNil() ? null : Boolean.TRUE;
|
|
@@ -2372,7 +2389,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2372
2389
|
try {
|
|
2373
2390
|
if ( value == null ) return context.nil;
|
|
2374
2391
|
|
|
2375
|
-
final RubyArray array =
|
|
2392
|
+
final RubyArray array = newArray(context);
|
|
2376
2393
|
|
|
2377
2394
|
final ResultSet arrayResult = value.getResultSet(); // 1: index, 2: value
|
|
2378
2395
|
final int baseType = value.getBaseType();
|
|
@@ -2393,7 +2410,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2393
2410
|
}
|
|
2394
2411
|
|
|
2395
2412
|
while ( arrayResult.next() ) {
|
|
2396
|
-
array.append( jdbcToRuby(context, runtime, 2, baseType, arrayResult)
|
|
2413
|
+
array.append(context, jdbcToRuby(context, runtime, 2, baseType, arrayResult));
|
|
2397
2414
|
}
|
|
2398
2415
|
arrayResult.close();
|
|
2399
2416
|
|
|
@@ -2526,38 +2543,38 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2526
2543
|
|
|
2527
2544
|
protected static final Map<String, Integer> JDBC_TYPE_FOR = new HashMap<>(32, 1);
|
|
2528
2545
|
static {
|
|
2529
|
-
JDBC_TYPE_FOR.put("string", Types.VARCHAR);
|
|
2530
|
-
JDBC_TYPE_FOR.put("text", Types.CLOB);
|
|
2531
|
-
JDBC_TYPE_FOR.put("integer", Types.INTEGER);
|
|
2532
|
-
JDBC_TYPE_FOR.put("float", Types.FLOAT);
|
|
2533
|
-
JDBC_TYPE_FOR.put("real", Types.REAL);
|
|
2534
|
-
JDBC_TYPE_FOR.put("decimal", Types.DECIMAL);
|
|
2535
|
-
JDBC_TYPE_FOR.put("date", Types.DATE);
|
|
2536
|
-
JDBC_TYPE_FOR.put("time", Types.TIME);
|
|
2537
|
-
JDBC_TYPE_FOR.put("datetime", Types.TIMESTAMP);
|
|
2538
|
-
JDBC_TYPE_FOR.put("timestamp", Types.TIMESTAMP);
|
|
2539
|
-
JDBC_TYPE_FOR.put("boolean", Types.BOOLEAN);
|
|
2540
|
-
JDBC_TYPE_FOR.put("array", Types.ARRAY);
|
|
2541
|
-
JDBC_TYPE_FOR.put("xml", Types.SQLXML);
|
|
2546
|
+
JDBC_TYPE_FOR.put("string", Integer.valueOf(Types.VARCHAR));
|
|
2547
|
+
JDBC_TYPE_FOR.put("text", Integer.valueOf(Types.CLOB));
|
|
2548
|
+
JDBC_TYPE_FOR.put("integer", Integer.valueOf(Types.INTEGER));
|
|
2549
|
+
JDBC_TYPE_FOR.put("float", Integer.valueOf(Types.FLOAT));
|
|
2550
|
+
JDBC_TYPE_FOR.put("real", Integer.valueOf(Types.REAL));
|
|
2551
|
+
JDBC_TYPE_FOR.put("decimal", Integer.valueOf(Types.DECIMAL));
|
|
2552
|
+
JDBC_TYPE_FOR.put("date", Integer.valueOf(Types.DATE));
|
|
2553
|
+
JDBC_TYPE_FOR.put("time", Integer.valueOf(Types.TIME));
|
|
2554
|
+
JDBC_TYPE_FOR.put("datetime", Integer.valueOf(Types.TIMESTAMP));
|
|
2555
|
+
JDBC_TYPE_FOR.put("timestamp", Integer.valueOf(Types.TIMESTAMP));
|
|
2556
|
+
JDBC_TYPE_FOR.put("boolean", Integer.valueOf(Types.BOOLEAN));
|
|
2557
|
+
JDBC_TYPE_FOR.put("array", Integer.valueOf(Types.ARRAY));
|
|
2558
|
+
JDBC_TYPE_FOR.put("xml", Integer.valueOf(Types.SQLXML));
|
|
2542
2559
|
|
|
2543
2560
|
// also mapping standard SQL names :
|
|
2544
|
-
JDBC_TYPE_FOR.put("bit", Types.BIT);
|
|
2545
|
-
JDBC_TYPE_FOR.put("tinyint", Types.TINYINT);
|
|
2546
|
-
JDBC_TYPE_FOR.put("smallint", Types.SMALLINT);
|
|
2547
|
-
JDBC_TYPE_FOR.put("bigint", Types.BIGINT);
|
|
2548
|
-
JDBC_TYPE_FOR.put("int", Types.INTEGER);
|
|
2549
|
-
JDBC_TYPE_FOR.put("double", Types.DOUBLE);
|
|
2550
|
-
JDBC_TYPE_FOR.put("numeric", Types.NUMERIC);
|
|
2551
|
-
JDBC_TYPE_FOR.put("char", Types.CHAR);
|
|
2552
|
-
JDBC_TYPE_FOR.put("varchar", Types.VARCHAR);
|
|
2553
|
-
JDBC_TYPE_FOR.put("binary", Types.BINARY);
|
|
2554
|
-
JDBC_TYPE_FOR.put("varbinary", Types.VARBINARY);
|
|
2561
|
+
JDBC_TYPE_FOR.put("bit", Integer.valueOf(Types.BIT));
|
|
2562
|
+
JDBC_TYPE_FOR.put("tinyint", Integer.valueOf(Types.TINYINT));
|
|
2563
|
+
JDBC_TYPE_FOR.put("smallint", Integer.valueOf(Types.SMALLINT));
|
|
2564
|
+
JDBC_TYPE_FOR.put("bigint", Integer.valueOf(Types.BIGINT));
|
|
2565
|
+
JDBC_TYPE_FOR.put("int", Integer.valueOf(Types.INTEGER));
|
|
2566
|
+
JDBC_TYPE_FOR.put("double", Integer.valueOf(Types.DOUBLE));
|
|
2567
|
+
JDBC_TYPE_FOR.put("numeric", Integer.valueOf(Types.NUMERIC));
|
|
2568
|
+
JDBC_TYPE_FOR.put("char", Integer.valueOf(Types.CHAR));
|
|
2569
|
+
JDBC_TYPE_FOR.put("varchar", Integer.valueOf(Types.VARCHAR));
|
|
2570
|
+
JDBC_TYPE_FOR.put("binary", Integer.valueOf(Types.BINARY));
|
|
2571
|
+
JDBC_TYPE_FOR.put("varbinary", Integer.valueOf(Types.VARBINARY));
|
|
2555
2572
|
//JDBC_TYPE_FOR.put("struct", Types.STRUCT);
|
|
2556
|
-
JDBC_TYPE_FOR.put("blob", Types.BLOB);
|
|
2557
|
-
JDBC_TYPE_FOR.put("clob", Types.CLOB);
|
|
2558
|
-
JDBC_TYPE_FOR.put("nchar", Types.NCHAR);
|
|
2559
|
-
JDBC_TYPE_FOR.put("nvarchar", Types.NVARCHAR);
|
|
2560
|
-
JDBC_TYPE_FOR.put("nclob", Types.NCLOB);
|
|
2573
|
+
JDBC_TYPE_FOR.put("blob", Integer.valueOf(Types.BLOB));
|
|
2574
|
+
JDBC_TYPE_FOR.put("clob", Integer.valueOf(Types.CLOB));
|
|
2575
|
+
JDBC_TYPE_FOR.put("nchar", Integer.valueOf(Types.NCHAR));
|
|
2576
|
+
JDBC_TYPE_FOR.put("nvarchar", Integer.valueOf(Types.NVARCHAR));
|
|
2577
|
+
JDBC_TYPE_FOR.put("nclob", Integer.valueOf(Types.NCLOB));
|
|
2561
2578
|
}
|
|
2562
2579
|
|
|
2563
2580
|
protected int jdbcTypeForAttribute(final ThreadContext context,
|
|
@@ -2666,7 +2683,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2666
2683
|
}
|
|
2667
2684
|
|
|
2668
2685
|
protected DateTimeZone getDefaultTimeZone(final ThreadContext context) {
|
|
2669
|
-
return isDefaultTimeZoneUTC(context) ? DateTimeZone.UTC : getLocalTimeZone(context
|
|
2686
|
+
return isDefaultTimeZoneUTC(context) ? DateTimeZone.UTC : getLocalTimeZone(context); // handles ENV['TZ']
|
|
2670
2687
|
}
|
|
2671
2688
|
|
|
2672
2689
|
private String default_timezone(final ThreadContext context) {
|
|
@@ -2683,13 +2700,13 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2683
2700
|
final IRubyObject attribute, final int type) throws SQLException {
|
|
2684
2701
|
|
|
2685
2702
|
if ( value instanceof RubyBignum ) { // e.g. HSQLDB / H2 report JDBC type 4
|
|
2686
|
-
setBigIntegerParameter(context, connection, statement, index,
|
|
2703
|
+
setBigIntegerParameter(context, connection, statement, index, value, attribute, type);
|
|
2687
2704
|
}
|
|
2688
2705
|
else if ( value instanceof RubyNumeric ) {
|
|
2689
2706
|
statement.setLong(index, RubyNumeric.num2long(value));
|
|
2690
2707
|
}
|
|
2691
2708
|
else {
|
|
2692
|
-
statement.setLong(index, value.convertToInteger("to_i").
|
|
2709
|
+
statement.setLong(index, value.convertToInteger("to_i").asLong(context));
|
|
2693
2710
|
}
|
|
2694
2711
|
}
|
|
2695
2712
|
|
|
@@ -2698,14 +2715,14 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2698
2715
|
final int index, final IRubyObject value,
|
|
2699
2716
|
final IRubyObject attribute, final int type) throws SQLException {
|
|
2700
2717
|
|
|
2701
|
-
if ( value instanceof RubyBignum ) {
|
|
2702
|
-
setLongOrDecimalParameter(statement, index,
|
|
2718
|
+
if ( value instanceof RubyBignum bignum) {
|
|
2719
|
+
setLongOrDecimalParameter(statement, index, bignum.getValue());
|
|
2703
2720
|
}
|
|
2704
|
-
else if (
|
|
2705
|
-
statement.setLong(index,
|
|
2721
|
+
else if (value instanceof RubyFixnum fixnum) {
|
|
2722
|
+
statement.setLong(index, fixnum.getValue());
|
|
2706
2723
|
}
|
|
2707
2724
|
else {
|
|
2708
|
-
setLongOrDecimalParameter(statement, index, value.convertToInteger("to_i").
|
|
2725
|
+
setLongOrDecimalParameter(statement, index, value.convertToInteger("to_i").asBigInteger(context));
|
|
2709
2726
|
}
|
|
2710
2727
|
}
|
|
2711
2728
|
|
|
@@ -2725,11 +2742,11 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2725
2742
|
final int index, final IRubyObject value,
|
|
2726
2743
|
final IRubyObject attribute, final int type) throws SQLException {
|
|
2727
2744
|
|
|
2728
|
-
if ( value instanceof RubyNumeric ) {
|
|
2729
|
-
statement.setDouble(index,
|
|
2745
|
+
if ( value instanceof RubyNumeric numeric) {
|
|
2746
|
+
statement.setDouble(index, numeric.asDouble(context));
|
|
2730
2747
|
}
|
|
2731
2748
|
else {
|
|
2732
|
-
statement.setDouble(index, value.convertToFloat().
|
|
2749
|
+
statement.setDouble(index, value.convertToFloat().asDouble(context));
|
|
2733
2750
|
}
|
|
2734
2751
|
}
|
|
2735
2752
|
|
|
@@ -2738,19 +2755,18 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2738
2755
|
final int index, final IRubyObject value,
|
|
2739
2756
|
final IRubyObject attribute, final int type) throws SQLException {
|
|
2740
2757
|
|
|
2741
|
-
if (value instanceof RubyBigDecimal) {
|
|
2742
|
-
statement.setBigDecimal(index,
|
|
2758
|
+
if (value instanceof RubyBigDecimal bigdecimal) {
|
|
2759
|
+
statement.setBigDecimal(index, bigdecimal.getValue());
|
|
2743
2760
|
}
|
|
2744
|
-
else if ( value instanceof RubyInteger ) {
|
|
2745
|
-
statement.setBigDecimal(index, new BigDecimal(
|
|
2761
|
+
else if ( value instanceof RubyInteger integer) {
|
|
2762
|
+
statement.setBigDecimal(index, new BigDecimal(integer.asBigInteger(context)));
|
|
2746
2763
|
}
|
|
2747
|
-
else if ( value instanceof RubyNumeric ) {
|
|
2748
|
-
statement.setDouble(index,
|
|
2764
|
+
else if ( value instanceof RubyNumeric numeric) {
|
|
2765
|
+
statement.setDouble(index, numeric.asDouble(context));
|
|
2749
2766
|
}
|
|
2750
2767
|
else { // e.g. `BigDecimal '42.00000000000000000001'`
|
|
2751
|
-
Ruby runtime = context.runtime;
|
|
2752
2768
|
statement.setBigDecimal(index,
|
|
2753
|
-
RubyBigDecimal.newInstance(context,
|
|
2769
|
+
RubyBigDecimal.newInstance(context, getModule(context, "BigDecimal"), value, asFixnum(context, 0)).getValue());
|
|
2754
2770
|
}
|
|
2755
2771
|
}
|
|
2756
2772
|
|
|
@@ -2809,7 +2825,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2809
2825
|
final int index, IRubyObject value,
|
|
2810
2826
|
final IRubyObject attribute, final int type) throws SQLException {
|
|
2811
2827
|
|
|
2812
|
-
if ( ! "Date".equals(value.getMetaClass().getName()) && value.respondsTo("to_date") ) {
|
|
2828
|
+
if ( ! "Date".equals(value.getMetaClass().getName(context)) && value.respondsTo("to_date") ) {
|
|
2813
2829
|
value = value.callMethod(context, "to_date");
|
|
2814
2830
|
}
|
|
2815
2831
|
|
|
@@ -2936,7 +2952,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2936
2952
|
protected Connection getConnectionInternal(final boolean required) throws SQLException {
|
|
2937
2953
|
Connection connection = getConnectionImpl();
|
|
2938
2954
|
if (connection == null && required) {
|
|
2939
|
-
if (!connected) handleNotConnected(); // raise ConnectionNotEstablished
|
|
2955
|
+
if (!connected) handleNotConnected(getRuntime().getCurrentContext()); // raise ConnectionNotEstablished
|
|
2940
2956
|
synchronized (this) {
|
|
2941
2957
|
connection = getConnectionImpl();
|
|
2942
2958
|
if ( connection == null ) {
|
|
@@ -2948,10 +2964,9 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2948
2964
|
return connection;
|
|
2949
2965
|
}
|
|
2950
2966
|
|
|
2951
|
-
private void handleNotConnected() {
|
|
2952
|
-
final
|
|
2953
|
-
|
|
2954
|
-
throw runtime.newRaiseException(errorClass, "no connection available");
|
|
2967
|
+
private void handleNotConnected(ThreadContext context) {
|
|
2968
|
+
final RubyClass errorClass = getConnectionNotEstablished(context);
|
|
2969
|
+
throw context.runtime.newRaiseException(errorClass, "no connection available");
|
|
2955
2970
|
}
|
|
2956
2971
|
|
|
2957
2972
|
/**
|
|
@@ -3017,7 +3032,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3017
3032
|
protected int getAliveTimeout(final ThreadContext context) {
|
|
3018
3033
|
if ( aliveTimeout == Integer.MIN_VALUE ) {
|
|
3019
3034
|
final IRubyObject timeout = getConfigValue(context, "connection_alive_timeout");
|
|
3020
|
-
|
|
3035
|
+
aliveTimeout = timeout == context.nil ? 0 : toInt(context, timeout);
|
|
3021
3036
|
}
|
|
3022
3037
|
return aliveTimeout;
|
|
3023
3038
|
}
|
|
@@ -3034,7 +3049,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3034
3049
|
@Override
|
|
3035
3050
|
@JRubyMethod
|
|
3036
3051
|
@SuppressWarnings("unchecked")
|
|
3037
|
-
public IRubyObject inspect() {
|
|
3052
|
+
public IRubyObject inspect(ThreadContext context) {
|
|
3038
3053
|
final ArrayList<Variable<String>> varList = new ArrayList<>(2);
|
|
3039
3054
|
final Connection connection = getConnectionImpl();
|
|
3040
3055
|
varList.add(new VariableEntry<>( "connection", connection == null ? "null" : connection.toString() ));
|
|
@@ -3090,10 +3105,10 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3090
3105
|
protected RubyArray mapTables(final ThreadContext context, final Connection connection,
|
|
3091
3106
|
final String catalog, final String schemaPattern, final String tablePattern,
|
|
3092
3107
|
final ResultSet tablesSet) throws SQLException {
|
|
3093
|
-
final RubyArray tables =
|
|
3108
|
+
final RubyArray tables = newArray(context);
|
|
3094
3109
|
while ( tablesSet.next() ) {
|
|
3095
3110
|
String name = tablesSet.getString(TABLES_TABLE_NAME);
|
|
3096
|
-
tables.append( cachedString(context, caseConvertIdentifierForRails(connection, name))
|
|
3111
|
+
tables.append(context, cachedString(context, caseConvertIdentifierForRails(connection, name)));
|
|
3097
3112
|
}
|
|
3098
3113
|
return tables;
|
|
3099
3114
|
}
|
|
@@ -3158,7 +3173,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3158
3173
|
|
|
3159
3174
|
final Ruby runtime = context.runtime;
|
|
3160
3175
|
|
|
3161
|
-
final RubyArray columns =
|
|
3176
|
+
final RubyArray columns = newArray(context);
|
|
3162
3177
|
while ( results.next() ) {
|
|
3163
3178
|
final String colName = results.getString(COLUMN_NAME);
|
|
3164
3179
|
final RubyString columnName = cachedString(context, caseConvertIdentifierForRails(metaData, colName));
|
|
@@ -3175,7 +3190,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3175
3190
|
final IRubyObject[] args = new IRubyObject[] {
|
|
3176
3191
|
columnName, defaultValue, type_metadata, nullable, tableName
|
|
3177
3192
|
};
|
|
3178
|
-
columns.append( Column.newInstance(context, args, Block.NULL_BLOCK)
|
|
3193
|
+
columns.append(context, Column.newInstance(context, args, Block.NULL_BLOCK));
|
|
3179
3194
|
}
|
|
3180
3195
|
return columns;
|
|
3181
3196
|
}
|
|
@@ -3205,7 +3220,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3205
3220
|
}
|
|
3206
3221
|
|
|
3207
3222
|
protected IRubyObject mapGeneratedKeys(
|
|
3208
|
-
|
|
3223
|
+
ThreadContext context, final Connection connection,
|
|
3209
3224
|
final Statement statement, final Boolean singleResult)
|
|
3210
3225
|
throws SQLException {
|
|
3211
3226
|
if ( supportsGeneratedKeys(connection) ) {
|
|
@@ -3214,8 +3229,8 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3214
3229
|
genKeys = statement.getGeneratedKeys();
|
|
3215
3230
|
// drivers might report a non-result statement without keys
|
|
3216
3231
|
// e.g. on derby with SQL: 'SET ISOLATION = SERIALIZABLE'
|
|
3217
|
-
if ( genKeys == null ) return
|
|
3218
|
-
return doMapGeneratedKeys(
|
|
3232
|
+
if ( genKeys == null ) return context.nil;
|
|
3233
|
+
return doMapGeneratedKeys(context, genKeys, singleResult);
|
|
3219
3234
|
}
|
|
3220
3235
|
catch (SQLFeatureNotSupportedException e) {
|
|
3221
3236
|
return null; // statement.getGeneratedKeys()
|
|
@@ -3225,7 +3240,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3225
3240
|
return null; // not supported
|
|
3226
3241
|
}
|
|
3227
3242
|
|
|
3228
|
-
protected final IRubyObject doMapGeneratedKeys(
|
|
3243
|
+
protected final IRubyObject doMapGeneratedKeys(ThreadContext context,
|
|
3229
3244
|
final ResultSet genKeys, final Boolean singleResult)
|
|
3230
3245
|
throws SQLException {
|
|
3231
3246
|
|
|
@@ -3236,28 +3251,28 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3236
3251
|
// singleResult == null - guess if only single key returned
|
|
3237
3252
|
if ( singleResult == null || singleResult) {
|
|
3238
3253
|
if ( next ) {
|
|
3239
|
-
firstKey = mapGeneratedKey(
|
|
3254
|
+
firstKey = mapGeneratedKey(context, genKeys);
|
|
3240
3255
|
if ( singleResult != null || ! genKeys.next() ) {
|
|
3241
3256
|
return firstKey;
|
|
3242
3257
|
}
|
|
3243
3258
|
next = true; // 2nd genKeys.next() returned true
|
|
3244
3259
|
}
|
|
3245
3260
|
else {
|
|
3246
|
-
/* if ( singleResult != null ) */ return
|
|
3261
|
+
/* if ( singleResult != null ) */ return context.nil;
|
|
3247
3262
|
}
|
|
3248
3263
|
}
|
|
3249
3264
|
|
|
3250
|
-
final RubyArray keys =
|
|
3251
|
-
if (
|
|
3265
|
+
final RubyArray keys = newArray(context);
|
|
3266
|
+
if (firstKey != null) keys.append(context, firstKey); // singleResult == null
|
|
3252
3267
|
while ( next ) {
|
|
3253
|
-
keys.append( mapGeneratedKey(
|
|
3268
|
+
keys.append(context, mapGeneratedKey(context, genKeys));
|
|
3254
3269
|
next = genKeys.next();
|
|
3255
3270
|
}
|
|
3256
3271
|
return keys;
|
|
3257
3272
|
}
|
|
3258
3273
|
|
|
3259
|
-
protected IRubyObject mapGeneratedKey(
|
|
3260
|
-
return
|
|
3274
|
+
protected IRubyObject mapGeneratedKey(ThreadContext context, final ResultSet genKeys) throws SQLException {
|
|
3275
|
+
return asFixnum(context, genKeys.getLong(1));
|
|
3261
3276
|
}
|
|
3262
3277
|
|
|
3263
3278
|
private transient Boolean supportsGeneratedKeys;
|
|
@@ -3265,7 +3280,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3265
3280
|
protected boolean supportsGeneratedKeys(final Connection connection) throws SQLException {
|
|
3266
3281
|
Boolean supportsGeneratedKeys = this.supportsGeneratedKeys;
|
|
3267
3282
|
if (supportsGeneratedKeys == null) {
|
|
3268
|
-
supportsGeneratedKeys = this.supportsGeneratedKeys = connection.getMetaData().supportsGetGeneratedKeys();
|
|
3283
|
+
supportsGeneratedKeys = this.supportsGeneratedKeys = (Boolean) connection.getMetaData().supportsGetGeneratedKeys();
|
|
3269
3284
|
}
|
|
3270
3285
|
return supportsGeneratedKeys;
|
|
3271
3286
|
}
|
|
@@ -3282,12 +3297,11 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3282
3297
|
|
|
3283
3298
|
final ColumnData[] columns = extractColumns(context, connection, resultSet, downCase);
|
|
3284
3299
|
|
|
3285
|
-
final
|
|
3286
|
-
final RubyArray results = runtime.newArray();
|
|
3300
|
+
final RubyArray results = newArray(context);
|
|
3287
3301
|
// [ { 'col1': 1, 'col2': 2 }, { 'col1': 3, 'col2': 4 } ]
|
|
3288
3302
|
|
|
3289
3303
|
while ( resultSet.next() ) {
|
|
3290
|
-
results.append(mapRawRow(context, runtime, columns, resultSet, this));
|
|
3304
|
+
results.append(context, mapRawRow(context, context.runtime, columns, resultSet, this));
|
|
3291
3305
|
}
|
|
3292
3306
|
return results;
|
|
3293
3307
|
}
|
|
@@ -3358,7 +3372,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3358
3372
|
|
|
3359
3373
|
final Connection connection = getConnectionInternal(false); // getConnection()
|
|
3360
3374
|
if ( connection == null ) {
|
|
3361
|
-
if ( ! connected ) handleNotConnected(); // raise ConnectionNotEstablished
|
|
3375
|
+
if ( ! connected ) handleNotConnected(context); // raise ConnectionNotEstablished
|
|
3362
3376
|
throw new NoConnectionException();
|
|
3363
3377
|
}
|
|
3364
3378
|
gotConnection = true;
|
|
@@ -3472,7 +3486,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3472
3486
|
return wrapException(context, context.runtime.getRuntimeError(), exception);
|
|
3473
3487
|
}
|
|
3474
3488
|
// NOTE: compat - maybe makes sense or maybe not (e.g. IOException) :
|
|
3475
|
-
return wrapException(context, getJDBCError(
|
|
3489
|
+
return wrapException(context, getJDBCError(context), exception);
|
|
3476
3490
|
}
|
|
3477
3491
|
|
|
3478
3492
|
public static RaiseException wrapException(final ThreadContext context,
|
|
@@ -3488,7 +3502,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3488
3502
|
}
|
|
3489
3503
|
|
|
3490
3504
|
protected RaiseException wrapException(final ThreadContext context, final SQLException exception, String message) {
|
|
3491
|
-
return wrapSQLException(context, getJDBCError(context
|
|
3505
|
+
return wrapSQLException(context, getJDBCError(context), exception, message);
|
|
3492
3506
|
}
|
|
3493
3507
|
|
|
3494
3508
|
protected RaiseException wrapException(final ThreadContext context, final RubyClass errorClass, final SQLException exception) {
|
|
@@ -3509,8 +3523,8 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3509
3523
|
}
|
|
3510
3524
|
|
|
3511
3525
|
protected final RaiseException newNoDatabaseError(final SQLException ex) {
|
|
3512
|
-
|
|
3513
|
-
return wrapException(
|
|
3526
|
+
var context = getRuntime().getCurrentContext();
|
|
3527
|
+
return wrapException(context, getNoDatabaseError(context), ex);
|
|
3514
3528
|
}
|
|
3515
3529
|
|
|
3516
3530
|
private IRubyObject convertJavaToRuby(final Object object) {
|
|
@@ -3569,14 +3583,14 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3569
3583
|
row[i] = connection.jdbcToRuby(context, runtime, column.index, column.type, resultSet);
|
|
3570
3584
|
}
|
|
3571
3585
|
|
|
3572
|
-
return
|
|
3586
|
+
return newArrayNoCopy(context, row);
|
|
3573
3587
|
}
|
|
3574
3588
|
|
|
3575
3589
|
private static IRubyObject mapRawRow(final ThreadContext context, final Ruby runtime,
|
|
3576
3590
|
final ColumnData[] columns, final ResultSet resultSet,
|
|
3577
3591
|
final RubyJdbcConnection connection) throws SQLException {
|
|
3578
3592
|
|
|
3579
|
-
final RubyHash row =
|
|
3593
|
+
final RubyHash row = RubyHash.newHash(runtime);
|
|
3580
3594
|
|
|
3581
3595
|
for ( int i = 0; i < columns.length; i++ ) {
|
|
3582
3596
|
final ColumnData column = columns[i];
|
|
@@ -3590,13 +3604,13 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3590
3604
|
}
|
|
3591
3605
|
|
|
3592
3606
|
protected static IRubyObject newResult(final ThreadContext context, ColumnData[] columns, IRubyObject rows) {
|
|
3593
|
-
final RubyClass Result = getResult(context
|
|
3607
|
+
final RubyClass Result = getResult(context);
|
|
3594
3608
|
return Result.newInstance(context, columnsToArray(context, columns), rows, Block.NULL_BLOCK); // Result.new
|
|
3595
3609
|
}
|
|
3596
3610
|
|
|
3597
3611
|
protected static IRubyObject newEmptyResult(final ThreadContext context) {
|
|
3598
|
-
final RubyClass Result = getResult(context
|
|
3599
|
-
return Result.newInstance(context,
|
|
3612
|
+
final RubyClass Result = getResult(context);
|
|
3613
|
+
return Result.newInstance(context, newEmptyArray(context), newEmptyArray(context), Block.NULL_BLOCK); // Result.new
|
|
3600
3614
|
}
|
|
3601
3615
|
|
|
3602
3616
|
private static RubyArray columnsToArray(ThreadContext context, ColumnData[] columns) {
|
|
@@ -3604,7 +3618,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3604
3618
|
|
|
3605
3619
|
for ( int i = 0; i < columns.length; i++ ) cols[i] = columns[i].getName(context);
|
|
3606
3620
|
|
|
3607
|
-
return
|
|
3621
|
+
return newArrayNoCopy(context, cols);
|
|
3608
3622
|
}
|
|
3609
3623
|
|
|
3610
3624
|
protected static final class TableName {
|