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
|
@@ -45,9 +45,9 @@ import org.jruby.util.ByteList;
|
|
|
45
45
|
public class MSSQLModule {
|
|
46
46
|
|
|
47
47
|
public static RubyModule load(final RubyModule arJdbc) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
var context = arJdbc.getRuntime().getCurrentContext();
|
|
49
|
+
return arJdbc.defineModuleUnder(context, "MSSQL").
|
|
50
|
+
defineMethods(context, MSSQLModule.class);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
public static RubyModule load(final Ruby runtime) {
|
|
@@ -63,6 +63,8 @@ import org.jruby.runtime.ThreadContext;
|
|
|
63
63
|
import org.jruby.runtime.builtin.IRubyObject;
|
|
64
64
|
import org.jruby.util.ByteList;
|
|
65
65
|
|
|
66
|
+
import static org.jruby.api.Create.newArray;
|
|
67
|
+
|
|
66
68
|
/**
|
|
67
69
|
*
|
|
68
70
|
* @author nicksieger
|
|
@@ -122,17 +124,19 @@ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
122
124
|
super(runtime, metaClass);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
public static RubyClass createMSSQLJdbcConnectionClass(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
getConnectionAdapters(
|
|
127
|
+
public static RubyClass createMSSQLJdbcConnectionClass(ThreadContext context, RubyClass jdbcConnection) {
|
|
128
|
+
RubyClass clazz = getConnectionAdapters(context). // ActiveRecord::ConnectionAdapters
|
|
129
|
+
defineClassUnder(context, "MSSQLJdbcConnection", jdbcConnection, ALLOCATOR).
|
|
130
|
+
defineMethods(context, MSSQLRubyJdbcConnection.class);
|
|
131
|
+
getConnectionAdapters(context).setConstant(context, "MssqlJdbcConnection", clazz);
|
|
132
|
+
|
|
130
133
|
return clazz;
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
public static RubyClass load(final Ruby runtime) {
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
var context = runtime.getCurrentContext();
|
|
138
|
+
RubyClass jdbcConnection = getJdbcConnection(context);
|
|
139
|
+
return createMSSQLJdbcConnectionClass(context, jdbcConnection);
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
protected static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
|
@@ -191,7 +195,7 @@ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
191
195
|
} else if (results.size() == 1) {
|
|
192
196
|
return results.get(0);
|
|
193
197
|
} else {
|
|
194
|
-
return
|
|
198
|
+
return newArray(context, results);
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
} catch (final SQLException e) {
|
|
@@ -326,7 +330,7 @@ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
326
330
|
final String catalog, final String schemaPattern, final String tablePattern,
|
|
327
331
|
final ResultSet tablesSet) throws SQLException, IllegalStateException {
|
|
328
332
|
|
|
329
|
-
final RubyArray tables =
|
|
333
|
+
final RubyArray tables = newArray(context);
|
|
330
334
|
|
|
331
335
|
while ( tablesSet.next() ) {
|
|
332
336
|
String schema = tablesSet.getString(TABLES_TABLE_SCHEM);
|
|
@@ -42,9 +42,9 @@ import static arjdbc.util.QuotingUtils.quoteCharAndDecorateWith;
|
|
|
42
42
|
public class MySQLModule {
|
|
43
43
|
|
|
44
44
|
public static RubyModule load(final RubyModule arJdbc) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
var context = arJdbc.getRuntime().getCurrentContext();
|
|
46
|
+
return arJdbc.defineModuleUnder(context, "MySQL").
|
|
47
|
+
defineMethods(context, MySQLModule.class);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
public static RubyModule load(final Ruby runtime) {
|
|
@@ -29,26 +29,28 @@ import arjdbc.jdbc.Callable;
|
|
|
29
29
|
import arjdbc.jdbc.DriverWrapper;
|
|
30
30
|
import arjdbc.jdbc.RubyJdbcConnection;
|
|
31
31
|
import arjdbc.util.DateTimeUtils;
|
|
32
|
+
import org.jruby.Ruby;
|
|
33
|
+
import org.jruby.RubyBoolean;
|
|
34
|
+
import org.jruby.RubyClass;
|
|
35
|
+
import org.jruby.anno.JRubyMethod;
|
|
36
|
+
import org.jruby.exceptions.RaiseException;
|
|
37
|
+
import org.jruby.runtime.ObjectAllocator;
|
|
38
|
+
import org.jruby.runtime.ThreadContext;
|
|
39
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
40
|
+
import org.jruby.util.SafePropertyAccessor;
|
|
32
41
|
|
|
33
42
|
import java.lang.reflect.InvocationTargetException;
|
|
34
43
|
import java.sql.Connection;
|
|
35
44
|
import java.sql.DatabaseMetaData;
|
|
36
45
|
import java.sql.PreparedStatement;
|
|
37
|
-
import java.sql.SQLException;
|
|
38
46
|
import java.sql.ResultSet;
|
|
47
|
+
import java.sql.SQLException;
|
|
39
48
|
import java.sql.Statement;
|
|
40
49
|
import java.sql.Timestamp;
|
|
41
50
|
import java.sql.Types;
|
|
42
51
|
|
|
43
|
-
import org.jruby
|
|
44
|
-
import org.jruby.
|
|
45
|
-
import org.jruby.exceptions.RaiseException;
|
|
46
|
-
import org.jruby.runtime.ObjectAllocator;
|
|
47
|
-
import org.jruby.runtime.ThreadContext;
|
|
48
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
|
49
|
-
import org.jruby.util.SafePropertyAccessor;
|
|
50
|
-
|
|
51
|
-
import static arjdbc.util.StringHelper.newString;
|
|
52
|
+
import static org.jruby.api.Create.newEmptyString;
|
|
53
|
+
import static org.jruby.api.Create.newString;
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
*
|
|
@@ -62,16 +64,16 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
62
64
|
super(runtime, metaClass);
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
public static RubyClass createMySQLJdbcConnectionClass(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return clazz;
|
|
67
|
+
public static RubyClass createMySQLJdbcConnectionClass(ThreadContext context, RubyClass jdbcConnection) {
|
|
68
|
+
return getConnectionAdapters(context).
|
|
69
|
+
defineClassUnder(context, "MySQLJdbcConnection", jdbcConnection, ALLOCATOR).
|
|
70
|
+
defineMethods(context, MySQLRubyJdbcConnection.class);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
public static RubyClass load(final Ruby runtime) {
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
var context = runtime.getCurrentContext();
|
|
75
|
+
RubyClass jdbcConnection = getJdbcConnection(context);
|
|
76
|
+
return createMySQLJdbcConnectionClass(context, jdbcConnection);
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
protected static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
|
@@ -89,7 +91,7 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
89
91
|
public IRubyObject db_version(final ThreadContext context) {
|
|
90
92
|
return withConnection(context, (Callable<IRubyObject>) connection -> {
|
|
91
93
|
final DatabaseMetaData metaData = connection.getMetaData();
|
|
92
|
-
return
|
|
94
|
+
return newString(context, metaData.getDatabaseProductVersion());
|
|
93
95
|
});
|
|
94
96
|
}
|
|
95
97
|
|
|
@@ -102,13 +104,13 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
102
104
|
final int major = jdbcDriver.getMajorVersion();
|
|
103
105
|
final int minor = jdbcDriver.getMinorVersion();
|
|
104
106
|
if ( major < 5 ) {
|
|
105
|
-
final RubyClass errorClass = getConnectionNotEstablished(context
|
|
107
|
+
final RubyClass errorClass = getConnectionNotEstablished(context);
|
|
106
108
|
throw context.runtime.newRaiseException(errorClass,
|
|
107
109
|
"MySQL adapter requires driver >= 5.0 got: " + major + "." + minor);
|
|
108
110
|
}
|
|
109
111
|
if ( major == 5 && minor < 1 ) { // need 5.1 for JDBC 4.0
|
|
110
112
|
// lightweight validation query: "/* ping */ SELECT 1"
|
|
111
|
-
setConfigValueIfNotSet(context, "connection_alive_sql",
|
|
113
|
+
setConfigValueIfNotSet(context, "connection_alive_sql", newString(context, "/* ping */ SELECT 1"));
|
|
112
114
|
}
|
|
113
115
|
driverAdapter = new MySQLDriverAdapter(); // short-circuit
|
|
114
116
|
}
|
|
@@ -207,11 +209,11 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
207
209
|
|
|
208
210
|
final Timestamp value = resultSet.getTimestamp(column);
|
|
209
211
|
if ( value == null ) {
|
|
210
|
-
return resultSet.wasNull() ? context.nil :
|
|
212
|
+
return resultSet.wasNull() ? context.nil : newEmptyString(context);
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
if ( rawDateTime != null && rawDateTime) {
|
|
214
|
-
return
|
|
216
|
+
return newString(context, DateTimeUtils.dummyTimeToString(value));
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
return DateTimeUtils.newDummyTime(context, value, getDefaultTimeZone(context));
|
|
@@ -223,7 +225,7 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
223
225
|
throws SQLException {
|
|
224
226
|
final byte[] bytes = resultSet.getBytes(column);
|
|
225
227
|
if ( bytes == null /* || resultSet.wasNull() */ ) return context.nil;
|
|
226
|
-
return newString(
|
|
228
|
+
return newString(context, bytes);
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
// MySQL does never storesUpperCaseIdentifiers() :
|
|
@@ -42,9 +42,8 @@ import org.jruby.runtime.builtin.IRubyObject;
|
|
|
42
42
|
public class OracleModule {
|
|
43
43
|
|
|
44
44
|
public static RubyModule load(final RubyModule arJdbc) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return oracle;
|
|
45
|
+
var context = arJdbc.getRuntime().getCurrentContext();
|
|
46
|
+
return arJdbc.defineModuleUnder(context, "Oracle").defineMethods(context, OracleModule.class);
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
public static RubyModule load(final Ruby runtime) {
|
|
@@ -60,6 +60,10 @@ import org.jruby.runtime.ObjectAllocator;
|
|
|
60
60
|
import org.jruby.runtime.ThreadContext;
|
|
61
61
|
import org.jruby.runtime.builtin.IRubyObject;
|
|
62
62
|
|
|
63
|
+
import static org.jruby.api.Convert.asFixnum;
|
|
64
|
+
import static org.jruby.api.Create.allocArray;
|
|
65
|
+
import static org.jruby.api.Create.newString;
|
|
66
|
+
|
|
63
67
|
/**
|
|
64
68
|
*
|
|
65
69
|
* @author nicksieger
|
|
@@ -71,16 +75,16 @@ public class OracleRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
71
75
|
super(runtime, metaClass);
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
public static RubyClass createOracleJdbcConnectionClass(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return clazz;
|
|
78
|
+
public static RubyClass createOracleJdbcConnectionClass(ThreadContext context, RubyClass jdbcConnection) {
|
|
79
|
+
return getConnectionAdapters(context).
|
|
80
|
+
defineClassUnder(context, "OracleJdbcConnection", jdbcConnection, ALLOCATOR).
|
|
81
|
+
defineMethods(context, OracleRubyJdbcConnection.class);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
public static RubyClass load(final Ruby runtime) {
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
var context = runtime.getCurrentContext();
|
|
86
|
+
RubyClass jdbcConnection = getJdbcConnection(context);
|
|
87
|
+
return createOracleJdbcConnectionClass(context, jdbcConnection);
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
protected static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
|
@@ -158,11 +162,11 @@ public class OracleRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
158
162
|
|
|
159
163
|
@Override
|
|
160
164
|
protected IRubyObject mapGeneratedKeys(
|
|
161
|
-
|
|
165
|
+
ThreadContext context, final Connection connection,
|
|
162
166
|
final Statement statement, final Boolean singleResult)
|
|
163
167
|
throws SQLException {
|
|
164
168
|
if ( generatedKeys ) {
|
|
165
|
-
return super.mapGeneratedKeys(
|
|
169
|
+
return super.mapGeneratedKeys(context, connection, statement, singleResult);
|
|
166
170
|
}
|
|
167
171
|
return null; // disabled using -Darjdbc.oracle.generated_keys=false
|
|
168
172
|
}
|
|
@@ -171,14 +175,14 @@ public class OracleRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
171
175
|
|
|
172
176
|
@Override // NOTE: Invalid column type:
|
|
173
177
|
// getLong not implemented for class oracle.jdbc.driver.T4CRowidAccessor
|
|
174
|
-
protected IRubyObject mapGeneratedKey(
|
|
178
|
+
protected IRubyObject mapGeneratedKey(ThreadContext context, final ResultSet genKeys)
|
|
175
179
|
throws SQLException {
|
|
176
180
|
// NOTE: it's likely a ROWID which we do not care about :
|
|
177
181
|
final String value = genKeys.getString(1); // "AAAsOjAAFAAABUlAAA"
|
|
178
182
|
if ( isPositiveInteger(value) ) {
|
|
179
|
-
return
|
|
183
|
+
return asFixnum(context, Long.parseLong(value));
|
|
180
184
|
}
|
|
181
|
-
return returnRowID ?
|
|
185
|
+
return returnRowID ? newString(context, value) : context.nil;
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
private static boolean isPositiveInteger(final String value) {
|
|
@@ -254,13 +258,13 @@ public class OracleRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
254
258
|
protected RubyArray mapTables(final ThreadContext context, final Connection connection,
|
|
255
259
|
final String catalog, final String schemaPattern, final String tablePattern,
|
|
256
260
|
final ResultSet tablesSet) throws SQLException {
|
|
257
|
-
final RubyArray tables = context
|
|
261
|
+
final RubyArray tables = allocArray(context, 32);
|
|
258
262
|
while ( tablesSet.next() ) {
|
|
259
263
|
String name = tablesSet.getString(TABLES_TABLE_NAME);
|
|
260
264
|
name = caseConvertIdentifierForRails(connection, name);
|
|
261
265
|
// Handle stupid Oracle 10g RecycleBin feature
|
|
262
266
|
if ( name.startsWith("bin$") ) continue;
|
|
263
|
-
tables.append(RubyString.newUnicodeString(context.runtime, name));
|
|
267
|
+
tables.append(context, RubyString.newUnicodeString(context.runtime, name));
|
|
264
268
|
}
|
|
265
269
|
return tables;
|
|
266
270
|
}
|
|
@@ -396,10 +400,10 @@ public class OracleRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
396
400
|
return describe(context, name.toString(), owner);
|
|
397
401
|
}
|
|
398
402
|
|
|
399
|
-
final RubyArray arr =
|
|
400
|
-
arr.append(
|
|
401
|
-
arr.append(
|
|
402
|
-
if ( dbLink != null ) arr.append(
|
|
403
|
+
final RubyArray arr = allocArray(context, 3);
|
|
404
|
+
arr.append(context, newString(context, owner));
|
|
405
|
+
arr.append(context, newString(context, table_name));
|
|
406
|
+
if ( dbLink != null ) arr.append(context, newString(context, dbLink));
|
|
403
407
|
return arr;
|
|
404
408
|
}
|
|
405
409
|
catch (final SQLException e) {
|
|
@@ -42,9 +42,8 @@ import org.jruby.util.ByteList;
|
|
|
42
42
|
public class PostgreSQLModule {
|
|
43
43
|
|
|
44
44
|
public static RubyModule load(final RubyModule arJdbc) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return postgreSQL;
|
|
45
|
+
var context = arJdbc.getRuntime().getCurrentContext();
|
|
46
|
+
return arJdbc.defineModuleUnder(context, "PostgreSQL").defineMethods(context, PostgreSQLModule.class);
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
public static RubyModule load(final Ruby runtime) {
|
|
@@ -23,6 +23,12 @@ import org.jruby.runtime.ObjectAllocator;
|
|
|
23
23
|
import org.jruby.runtime.ThreadContext;
|
|
24
24
|
import org.jruby.runtime.builtin.IRubyObject;
|
|
25
25
|
|
|
26
|
+
import static org.jruby.api.Access.enumerableModule;
|
|
27
|
+
import static org.jruby.api.Access.getModule;
|
|
28
|
+
import static org.jruby.api.Access.objectClass;
|
|
29
|
+
import static org.jruby.api.Convert.toInt;
|
|
30
|
+
import static org.jruby.api.Error.argumentError;
|
|
31
|
+
|
|
26
32
|
/*
|
|
27
33
|
* This class mimics the PG::Result class enough to get by. It also adorns common methods useful for
|
|
28
34
|
* gems like mini_sql to consume it similarly to PG::Result
|
|
@@ -35,10 +41,13 @@ public class PostgreSQLResult extends JdbcResult {
|
|
|
35
41
|
|
|
36
42
|
/********* JRuby compat methods ***********/
|
|
37
43
|
|
|
38
|
-
static RubyClass createPostgreSQLResultClass(
|
|
39
|
-
RubyClass rubyClass = postgreSQLConnection.
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
static RubyClass createPostgreSQLResultClass(ThreadContext context, RubyClass postgreSQLConnection) {
|
|
45
|
+
RubyClass rubyClass = postgreSQLConnection.
|
|
46
|
+
defineClassUnder(context, "Result", objectClass(context), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR).
|
|
47
|
+
defineMethods(context, PostgreSQLResult.class);
|
|
48
|
+
|
|
49
|
+
rubyClass.includeModule(context, enumerableModule(context));
|
|
50
|
+
|
|
42
51
|
return rubyClass;
|
|
43
52
|
}
|
|
44
53
|
|
|
@@ -130,7 +139,10 @@ public class PostgreSQLResult extends JdbcResult {
|
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
private RubyClass getBinaryDataClass(final ThreadContext context) {
|
|
133
|
-
return (
|
|
142
|
+
return getModule(context, "ActiveModel").
|
|
143
|
+
getModule(context, "Type").
|
|
144
|
+
getClass(context, "Binary").
|
|
145
|
+
getClass(context, "Data");
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
private boolean isBinaryType(final int type) {
|
|
@@ -145,7 +157,7 @@ public class PostgreSQLResult extends JdbcResult {
|
|
|
145
157
|
*/
|
|
146
158
|
@PG @JRubyMethod(name = {"length", "ntuples", "num_tuples"})
|
|
147
159
|
public IRubyObject length(final ThreadContext context) {
|
|
148
|
-
return values.length();
|
|
160
|
+
return values.length(context);
|
|
149
161
|
}
|
|
150
162
|
|
|
151
163
|
/**
|
|
@@ -219,21 +231,21 @@ public class PostgreSQLResult extends JdbcResult {
|
|
|
219
231
|
@PG @JRubyMethod
|
|
220
232
|
public IRubyObject getvalue(ThreadContext context, IRubyObject rowArg, IRubyObject columnArg) {
|
|
221
233
|
int rows = values.size();
|
|
222
|
-
int row =
|
|
223
|
-
int column =
|
|
234
|
+
int row = toInt(context, rowArg);
|
|
235
|
+
int column = toInt(context, columnArg);
|
|
224
236
|
|
|
225
|
-
if (row < 0 || row >= rows) throw context
|
|
226
|
-
if (column < 0 || column >= getColumnNames().length) throw context
|
|
237
|
+
if (row < 0 || row >= rows) throw argumentError(context, "invalid tuple number " + row);
|
|
238
|
+
if (column < 0 || column >= getColumnNames().length) throw argumentError(context, "invalid field number " + row);
|
|
227
239
|
|
|
228
240
|
return ((RubyArray) values.eltInternal(row)).eltInternal(column);
|
|
229
241
|
}
|
|
230
242
|
|
|
231
243
|
@PG @JRubyMethod(name = "[]")
|
|
232
244
|
public IRubyObject aref(ThreadContext context, IRubyObject rowArg) {
|
|
233
|
-
int row =
|
|
245
|
+
int row = toInt(context, rowArg);
|
|
234
246
|
int rows = values.size();
|
|
235
247
|
|
|
236
|
-
if (row < 0 || row >= rows) throw context
|
|
248
|
+
if (row < 0 || row >= rows) throw argumentError(context, "Index " + row + " is out of range");
|
|
237
249
|
|
|
238
250
|
RubyArray rowValues = (RubyArray) values.eltOk(row);
|
|
239
251
|
RubyHash resultHash = RubyHash.newSmallHash(context.runtime);
|
|
@@ -115,21 +115,22 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
|
115
115
|
public PostgreSQLRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
|
116
116
|
super(runtime, metaClass);
|
|
117
117
|
|
|
118
|
-
resultClass = getMetaClass().getClass("Result");
|
|
118
|
+
resultClass = getMetaClass().getClass(runtime.getCurrentContext(), "Result");
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
public static RubyClass createPostgreSQLJdbcConnectionClass(
|
|
122
|
-
final RubyClass clazz = getConnectionAdapters(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
getConnectionAdapters(
|
|
121
|
+
public static RubyClass createPostgreSQLJdbcConnectionClass(ThreadContext context, RubyClass jdbcConnection) {
|
|
122
|
+
final RubyClass clazz = getConnectionAdapters(context).
|
|
123
|
+
defineClassUnder(context, "PostgreSQLJdbcConnection", jdbcConnection, ALLOCATOR).
|
|
124
|
+
defineMethods(context, PostgreSQLRubyJdbcConnection.class);
|
|
125
|
+
getConnectionAdapters(context).setConstant(context, "PostgresJdbcConnection", clazz); // backwards-compat
|
|
126
126
|
return clazz;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
public static RubyClass load(final Ruby runtime) {
|
|
130
|
-
|
|
131
|
-
RubyClass
|
|
132
|
-
|
|
130
|
+
var context = runtime.getCurrentContext();
|
|
131
|
+
RubyClass jdbcConnection = getJdbcConnection(context);
|
|
132
|
+
RubyClass postgreSQLConnection = createPostgreSQLJdbcConnectionClass(context, jdbcConnection);
|
|
133
|
+
PostgreSQLResult.createPostgreSQLResultClass(context, postgreSQLConnection);
|
|
133
134
|
return postgreSQLConnection;
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -223,8 +224,11 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
|
223
224
|
|
|
224
225
|
private RubyClass oidArray(final ThreadContext context) {
|
|
225
226
|
if (oidArray != null) return oidArray;
|
|
226
|
-
|
|
227
|
-
return
|
|
227
|
+
|
|
228
|
+
return getConnectionAdapters(context).
|
|
229
|
+
getModule(context, "PostgreSQL").
|
|
230
|
+
getModule(context, "OID").
|
|
231
|
+
getClass(context, "Array");
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
|
|
@@ -384,7 +388,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
|
384
388
|
}
|
|
385
389
|
}
|
|
386
390
|
|
|
387
|
-
if ( ! "Date".equals(value.getMetaClass().getName()) && value.respondsTo("to_date") ) {
|
|
391
|
+
if ( ! "Date".equals(value.getMetaClass().getName(context)) && value.respondsTo("to_date") ) {
|
|
388
392
|
value = value.callMethod(context, "to_date");
|
|
389
393
|
}
|
|
390
394
|
|
|
@@ -41,9 +41,8 @@ import org.jruby.runtime.builtin.IRubyObject;
|
|
|
41
41
|
public class SQLite3Module {
|
|
42
42
|
|
|
43
43
|
public static RubyModule load(final RubyModule arJdbc) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return sqlite3;
|
|
44
|
+
var context = arJdbc.getRuntime().getCurrentContext();
|
|
45
|
+
return arJdbc.defineModuleUnder(context, "SQLite3").defineMethods(context, SQLite3Module.class);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
public static RubyModule load(final Ruby runtime) {
|