activerecord-jdbc-adapter 72.0-java → 80.0.pre1-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/ruby.yml +129 -24
- data/.mise.toml +3 -0
- data/Gemfile +42 -47
- data/README.md +3 -2
- data/Rakefile +62 -14
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/lib/arjdbc/abstract/core.rb +1 -1
- data/lib/arjdbc/abstract/database_statements.rb +11 -7
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/postgresql/adapter.rb +4 -1
- data/lib/arjdbc/sqlite3/adapter.rb +48 -7
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +3 -3
- 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 +30 -24
- 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 +6 -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) {
|
|
@@ -60,6 +60,8 @@ import org.jruby.runtime.ThreadContext;
|
|
|
60
60
|
import org.jruby.runtime.builtin.IRubyObject;
|
|
61
61
|
import org.jruby.util.ByteList;
|
|
62
62
|
|
|
63
|
+
import static org.jruby.api.Create.newArray;
|
|
64
|
+
|
|
63
65
|
/**
|
|
64
66
|
*
|
|
65
67
|
* @author nicksieger
|
|
@@ -118,17 +120,19 @@ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
118
120
|
super(runtime, metaClass);
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
public static RubyClass createMSSQLJdbcConnectionClass(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
getConnectionAdapters(
|
|
123
|
+
public static RubyClass createMSSQLJdbcConnectionClass(ThreadContext context, RubyClass jdbcConnection) {
|
|
124
|
+
RubyClass clazz = getConnectionAdapters(context). // ActiveRecord::ConnectionAdapters
|
|
125
|
+
defineClassUnder(context, "MSSQLJdbcConnection", jdbcConnection, ALLOCATOR).
|
|
126
|
+
defineMethods(context, MSSQLRubyJdbcConnection.class);
|
|
127
|
+
getConnectionAdapters(context).setConstant(context, "MssqlJdbcConnection", clazz);
|
|
128
|
+
|
|
126
129
|
return clazz;
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
public static RubyClass load(final Ruby runtime) {
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
var context = runtime.getCurrentContext();
|
|
134
|
+
RubyClass jdbcConnection = getJdbcConnection(context);
|
|
135
|
+
return createMSSQLJdbcConnectionClass(context, jdbcConnection);
|
|
132
136
|
}
|
|
133
137
|
|
|
134
138
|
protected static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
|
@@ -187,7 +191,7 @@ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
187
191
|
} else if (results.size() == 1) {
|
|
188
192
|
return results.get(0);
|
|
189
193
|
} else {
|
|
190
|
-
return
|
|
194
|
+
return newArray(context, results);
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
} catch (final SQLException e) {
|
|
@@ -331,7 +335,7 @@ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
331
335
|
final String catalog, final String schemaPattern, final String tablePattern,
|
|
332
336
|
final ResultSet tablesSet) throws SQLException, IllegalStateException {
|
|
333
337
|
|
|
334
|
-
final RubyArray tables =
|
|
338
|
+
final RubyArray tables = newArray(context);
|
|
335
339
|
|
|
336
340
|
while ( tablesSet.next() ) {
|
|
337
341
|
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,19 +64,23 @@ 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
|
-
protected static final ObjectAllocator ALLOCATOR =
|
|
79
|
+
protected static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
|
80
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
|
81
|
+
return new MySQLRubyJdbcConnection(runtime, klass);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
78
84
|
|
|
79
85
|
@JRubyMethod
|
|
80
86
|
public IRubyObject query(final ThreadContext context, final IRubyObject sql) throws SQLException {
|
|
@@ -85,7 +91,7 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
85
91
|
public IRubyObject db_version(final ThreadContext context) {
|
|
86
92
|
return withConnection(context, (Callable<IRubyObject>) connection -> {
|
|
87
93
|
final DatabaseMetaData metaData = connection.getMetaData();
|
|
88
|
-
return
|
|
94
|
+
return newString(context, metaData.getDatabaseProductVersion());
|
|
89
95
|
});
|
|
90
96
|
}
|
|
91
97
|
|
|
@@ -98,13 +104,13 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
98
104
|
final int major = jdbcDriver.getMajorVersion();
|
|
99
105
|
final int minor = jdbcDriver.getMinorVersion();
|
|
100
106
|
if ( major < 5 ) {
|
|
101
|
-
final RubyClass errorClass = getConnectionNotEstablished(context
|
|
107
|
+
final RubyClass errorClass = getConnectionNotEstablished(context);
|
|
102
108
|
throw context.runtime.newRaiseException(errorClass,
|
|
103
109
|
"MySQL adapter requires driver >= 5.0 got: " + major + "." + minor);
|
|
104
110
|
}
|
|
105
111
|
if ( major == 5 && minor < 1 ) { // need 5.1 for JDBC 4.0
|
|
106
112
|
// lightweight validation query: "/* ping */ SELECT 1"
|
|
107
|
-
setConfigValueIfNotSet(context, "connection_alive_sql",
|
|
113
|
+
setConfigValueIfNotSet(context, "connection_alive_sql", newString(context, "/* ping */ SELECT 1"));
|
|
108
114
|
}
|
|
109
115
|
driverAdapter = new MySQLDriverAdapter(); // short-circuit
|
|
110
116
|
}
|
|
@@ -203,11 +209,11 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
203
209
|
|
|
204
210
|
final Timestamp value = resultSet.getTimestamp(column);
|
|
205
211
|
if ( value == null ) {
|
|
206
|
-
return resultSet.wasNull() ? context.nil :
|
|
212
|
+
return resultSet.wasNull() ? context.nil : newEmptyString(context);
|
|
207
213
|
}
|
|
208
214
|
|
|
209
215
|
if ( rawDateTime != null && rawDateTime) {
|
|
210
|
-
return
|
|
216
|
+
return newString(context, DateTimeUtils.dummyTimeToString(value));
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
return DateTimeUtils.newDummyTime(context, value, getDefaultTimeZone(context));
|
|
@@ -219,7 +225,7 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
|
219
225
|
throws SQLException {
|
|
220
226
|
final byte[] bytes = resultSet.getBytes(column);
|
|
221
227
|
if ( bytes == null /* || resultSet.wasNull() */ ) return context.nil;
|
|
222
|
-
return newString(
|
|
228
|
+
return newString(context, bytes);
|
|
223
229
|
}
|
|
224
230
|
|
|
225
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) {
|