activerecord-jdbc-alt-adapter 52.2.3-java → 60.1.0-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/.gitignore +3 -0
- data/.travis.yml +80 -52
- data/Gemfile +10 -3
- data/README.md +55 -37
- data/Rakefile +31 -5
- data/Rakefile.jdbc +8 -1
- data/activerecord-jdbc-adapter.gemspec +6 -9
- data/activerecord-jdbc-alt-adapter.gemspec +6 -9
- data/lib/arel/visitors/sqlserver.rb +33 -23
- data/lib/arjdbc/abstract/connection_management.rb +7 -0
- data/lib/arjdbc/abstract/core.rb +17 -24
- data/lib/arjdbc/abstract/database_statements.rb +31 -20
- data/lib/arjdbc/abstract/statement_cache.rb +2 -5
- data/lib/arjdbc/abstract/transaction_support.rb +5 -3
- data/lib/arjdbc/db2/column.rb +0 -39
- data/lib/arjdbc/derby/adapter.rb +1 -20
- data/lib/arjdbc/firebird/adapter.rb +0 -21
- data/lib/arjdbc/h2/adapter.rb +0 -15
- data/lib/arjdbc/hsqldb/adapter.rb +0 -14
- data/lib/arjdbc/informix/adapter.rb +0 -23
- data/lib/arjdbc/jdbc.rb +0 -4
- data/lib/arjdbc/jdbc/adapter.rb +3 -1
- data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
- data/lib/arjdbc/jdbc/base_ext.rb +3 -1
- data/lib/arjdbc/jdbc/callbacks.rb +2 -0
- data/lib/arjdbc/jdbc/column.rb +3 -5
- data/lib/arjdbc/jdbc/connection.rb +2 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
- data/lib/arjdbc/jdbc/error.rb +2 -0
- data/lib/arjdbc/jdbc/extension.rb +2 -0
- data/lib/arjdbc/jdbc/java.rb +3 -1
- data/lib/arjdbc/jdbc/railtie.rb +3 -1
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
- data/lib/arjdbc/jdbc/type_cast.rb +2 -0
- data/lib/arjdbc/jdbc/type_converter.rb +2 -0
- data/lib/arjdbc/mssql.rb +3 -1
- data/lib/arjdbc/mssql/adapter.rb +112 -46
- data/lib/arjdbc/mssql/column.rb +5 -1
- data/lib/arjdbc/mssql/connection_methods.rb +13 -2
- data/lib/arjdbc/mssql/database_limits.rb +2 -0
- data/lib/arjdbc/mssql/database_statements.rb +44 -6
- data/lib/arjdbc/mssql/errors.rb +2 -0
- data/lib/arjdbc/mssql/explain_support.rb +3 -1
- data/lib/arjdbc/mssql/extensions/attribute_methods.rb +5 -1
- data/lib/arjdbc/mssql/extensions/calculations.rb +2 -0
- data/lib/arjdbc/mssql/quoting.rb +38 -0
- data/lib/arjdbc/mssql/schema_creation.rb +24 -2
- data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
- data/lib/arjdbc/mssql/schema_dumper.rb +2 -0
- data/lib/arjdbc/mssql/schema_statements.rb +63 -21
- data/lib/arjdbc/mssql/transaction.rb +2 -0
- data/lib/arjdbc/mssql/types.rb +2 -0
- data/lib/arjdbc/mssql/types/binary_types.rb +2 -0
- data/lib/arjdbc/mssql/types/date_and_time_types.rb +2 -0
- data/lib/arjdbc/mssql/types/deprecated_types.rb +2 -0
- data/lib/arjdbc/mssql/types/numeric_types.rb +2 -0
- data/lib/arjdbc/mssql/types/string_types.rb +2 -0
- data/lib/arjdbc/mssql/utils.rb +2 -0
- data/lib/arjdbc/mysql/adapter.rb +47 -18
- data/lib/arjdbc/mysql/connection_methods.rb +13 -7
- data/lib/arjdbc/postgresql/adapter.rb +240 -214
- data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
- data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
- data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
- data/lib/arjdbc/postgresql/column.rb +11 -6
- data/lib/arjdbc/postgresql/connection_methods.rb +3 -1
- data/lib/arjdbc/postgresql/name.rb +2 -0
- data/lib/arjdbc/postgresql/oid_types.rb +3 -1
- data/lib/arjdbc/sqlite3/adapter.rb +188 -180
- data/lib/arjdbc/sqlite3/connection_methods.rb +16 -4
- data/lib/arjdbc/tasks/databases.rake +13 -10
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +49 -5
- data/lib/arjdbc/util/quoted_cache.rb +3 -1
- data/lib/arjdbc/util/serialized_attributes.rb +3 -1
- data/lib/arjdbc/util/table_copier.rb +3 -1
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +4 -4
- data/rakelib/01-tomcat.rake +2 -2
- data/rakelib/02-test.rake +0 -2
- data/rakelib/rails.rake +1 -1
- data/src/java/arjdbc/ArJdbcModule.java +5 -5
- data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +468 -637
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +319 -38
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +44 -31
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
- data/src/java/arjdbc/util/DateTimeUtils.java +34 -12
- metadata +7 -17
@@ -35,27 +35,19 @@ import arjdbc.util.StringHelper;
|
|
35
35
|
import java.io.ByteArrayInputStream;
|
36
36
|
import java.lang.StringBuilder;
|
37
37
|
import java.lang.reflect.InvocationTargetException;
|
38
|
-
import java.
|
39
|
-
import java.sql
|
38
|
+
import java.math.BigDecimal;
|
39
|
+
import java.sql.*;
|
40
40
|
import java.sql.Date;
|
41
|
-
import java.
|
42
|
-
import java.sql.ResultSet;
|
43
|
-
import java.sql.ResultSetMetaData;
|
44
|
-
import java.sql.SQLException;
|
45
|
-
import java.sql.Timestamp;
|
46
|
-
import java.sql.Types;
|
47
|
-
import java.util.ArrayList;
|
48
|
-
import java.util.Collections;
|
49
|
-
import java.util.HashMap;
|
50
|
-
import java.util.Map;
|
51
|
-
import java.util.UUID;
|
41
|
+
import java.util.*;
|
52
42
|
import java.util.regex.Pattern;
|
53
43
|
import java.util.regex.Matcher;
|
54
44
|
|
45
|
+
import org.joda.time.DateTime;
|
55
46
|
import org.jruby.*;
|
56
47
|
import org.jruby.anno.JRubyMethod;
|
57
48
|
import org.jruby.exceptions.RaiseException;
|
58
49
|
import org.jruby.ext.bigdecimal.RubyBigDecimal;
|
50
|
+
import org.jruby.ext.date.RubyDate;
|
59
51
|
import org.jruby.javasupport.JavaUtil;
|
60
52
|
import org.jruby.runtime.ObjectAllocator;
|
61
53
|
import org.jruby.runtime.ThreadContext;
|
@@ -115,6 +107,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
115
107
|
|
116
108
|
// Used to wipe trailing 0's from points (3.0, 5.6) -> (3, 5.6)
|
117
109
|
private static final Pattern pointCleanerPattern = Pattern.compile("\\.0\\b");
|
110
|
+
private static final TimeZone TZ_DEFAULT = TimeZone.getDefault();
|
118
111
|
|
119
112
|
private RubyClass resultClass;
|
120
113
|
private RubyHash typeMap = null;
|
@@ -163,15 +156,12 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
163
156
|
try { // public static String getVersion()
|
164
157
|
final String version = (String) // "PostgreSQL 9.2 JDBC4 (build 1002)"
|
165
158
|
jdbcDriver.getClass().getMethod("getVersion").invoke(null);
|
166
|
-
if ( version != null && version.
|
159
|
+
if ( version != null && version.contains("JDBC3")) {
|
167
160
|
// config[:connection_alive_sql] ||= 'SELECT 1'
|
168
161
|
setConfigValueIfNotSet(context, "connection_alive_sql", context.runtime.newString("SELECT 1"));
|
169
162
|
}
|
170
163
|
}
|
171
|
-
catch (NoSuchMethodException
|
172
|
-
catch (SecurityException e) { }
|
173
|
-
catch (IllegalAccessException e) { }
|
174
|
-
catch (InvocationTargetException e) { }
|
164
|
+
catch (NoSuchMethodException | SecurityException | InvocationTargetException | IllegalAccessException ignored) { }
|
175
165
|
}
|
176
166
|
|
177
167
|
return driverWrapper;
|
@@ -218,11 +208,9 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
218
208
|
|
219
209
|
@JRubyMethod(name = "database_product")
|
220
210
|
public IRubyObject database_product(final ThreadContext context) {
|
221
|
-
return withConnection(context,
|
222
|
-
|
223
|
-
|
224
|
-
return RubyString.newString(context.runtime, metaData.getDatabaseProductName() + ' ' + metaData.getDatabaseProductVersion());
|
225
|
-
}
|
211
|
+
return withConnection(context, (Callable<IRubyObject>) connection -> {
|
212
|
+
final DatabaseMetaData metaData = connection.getMetaData();
|
213
|
+
return RubyString.newString(context.runtime, metaData.getDatabaseProductName() + ' ' + metaData.getDatabaseProductVersion());
|
226
214
|
});
|
227
215
|
}
|
228
216
|
|
@@ -308,6 +296,24 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
308
296
|
statement.setArray(index, connection.createArrayOf(typeName, values));
|
309
297
|
}
|
310
298
|
|
299
|
+
protected void setDecimalParameter(final ThreadContext context,
|
300
|
+
final Connection connection, final PreparedStatement statement,
|
301
|
+
final int index, final IRubyObject value,
|
302
|
+
final IRubyObject attribute, final int type) throws SQLException {
|
303
|
+
if (value instanceof RubyBigDecimal) {
|
304
|
+
RubyBigDecimal bigDecimal = (RubyBigDecimal) value;
|
305
|
+
|
306
|
+
// too bad RubyBigDecimal.isNaN() isn't public
|
307
|
+
if (bigDecimal.nan_p(context) == context.tru) {
|
308
|
+
statement.setDouble(index, Double.NaN);
|
309
|
+
} else {
|
310
|
+
statement.setBigDecimal(index, bigDecimal.getValue());
|
311
|
+
}
|
312
|
+
} else {
|
313
|
+
super.setDecimalParameter(context, connection, statement, index, value, attribute, type);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
311
317
|
@Override
|
312
318
|
protected void setBlobParameter(final ThreadContext context,
|
313
319
|
final Connection connection, final PreparedStatement statement,
|
@@ -377,14 +383,16 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
377
383
|
value = value.callMethod(context, "to_date");
|
378
384
|
}
|
379
385
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
+
if (value instanceof RubyDate) {
|
387
|
+
RubyDate rubyDate = (RubyDate) value;
|
388
|
+
DateTime dt = rubyDate.getDateTime();
|
389
|
+
// pgjdbc needs adjustment for default JVM timezone
|
390
|
+
statement.setDate(index, new Date(dt.getMillis() - TZ_DEFAULT.getOffset(dt.getMillis())));
|
391
|
+
return;
|
392
|
+
}
|
386
393
|
|
387
|
-
|
394
|
+
// NOTE: assuming Date#to_s does right ...
|
395
|
+
statement.setDate(index, Date.valueOf(value.toString()));
|
388
396
|
}
|
389
397
|
|
390
398
|
@Override
|
@@ -514,7 +522,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
514
522
|
|
515
523
|
private static Double[] parseDoubles(IRubyObject value) {
|
516
524
|
Matcher matches = doubleValuePattern.matcher(value.toString());
|
517
|
-
ArrayList<Double> doubles = new ArrayList
|
525
|
+
ArrayList<Double> doubles = new ArrayList<>(4); // Paths and polygons may be larger but this covers points/circles/boxes/line segments
|
518
526
|
|
519
527
|
while ( matches.find() ) {
|
520
528
|
doubles.add(Double.parseDouble(matches.group()));
|
@@ -729,6 +737,11 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
729
737
|
return DateTimeUtils.parseDate(context, value, getDefaultTimeZone(context));
|
730
738
|
}
|
731
739
|
|
740
|
+
protected IRubyObject decimalToRuby(final ThreadContext context,
|
741
|
+
final Ruby runtime, final ResultSet resultSet, final int column) throws SQLException {
|
742
|
+
if ("NaN".equals(resultSet.getString(column))) return new RubyBigDecimal(runtime, BigDecimal.ZERO, true);
|
743
|
+
return super.decimalToRuby(context, runtime, resultSet, column);
|
744
|
+
}
|
732
745
|
|
733
746
|
/**
|
734
747
|
* Detects PG specific types and converts them to their Ruby equivalents
|
@@ -100,55 +100,53 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
100
100
|
public IRubyObject encoding(final ThreadContext context) throws SQLException {
|
101
101
|
if (encoding != null) return encoding;
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
} catch (final SQLException e) {
|
120
|
-
debugErrorSQL(context, query);
|
121
|
-
throw e;
|
122
|
-
} finally {
|
123
|
-
close(resultSet);
|
124
|
-
close(statement);
|
103
|
+
// FIXME: How many single result queries do we have in Java?
|
104
|
+
return withConnection(context, connection -> {
|
105
|
+
String query = "PRAGMA encoding";
|
106
|
+
Statement statement = null;
|
107
|
+
ResultSet resultSet = null;
|
108
|
+
try {
|
109
|
+
statement = createStatement(context, connection);
|
110
|
+
if (statement.execute(query)) {
|
111
|
+
// Enebo: I do not think we need to worry about failure here?
|
112
|
+
resultSet = statement.getResultSet();
|
113
|
+
if (!resultSet.next()) return context.nil;
|
114
|
+
String encodingString = resultSet.getString(1);
|
115
|
+
|
116
|
+
encoding = cachedString(context, encodingString);
|
117
|
+
|
118
|
+
return encoding;
|
125
119
|
}
|
126
|
-
|
127
|
-
|
120
|
+
} catch (final SQLException e) {
|
121
|
+
debugErrorSQL(context, query);
|
122
|
+
throw e;
|
123
|
+
} finally {
|
124
|
+
close(resultSet);
|
125
|
+
close(statement);
|
128
126
|
}
|
127
|
+
|
128
|
+
return context.nil;
|
129
129
|
});
|
130
130
|
}
|
131
131
|
|
132
132
|
@JRubyMethod(name = {"last_insert_rowid", "last_insert_id"}, alias = "last_insert_row_id")
|
133
133
|
public IRubyObject last_insert_rowid(final ThreadContext context)
|
134
134
|
throws SQLException {
|
135
|
-
return withConnection(context,
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
throw e;
|
149
|
-
}
|
150
|
-
finally { close(genKeys); close(statement); }
|
135
|
+
return withConnection(context, connection -> {
|
136
|
+
Statement statement = null; ResultSet genKeys = null;
|
137
|
+
try {
|
138
|
+
statement = connection.createStatement();
|
139
|
+
// NOTE: strangely this will work and has been used for quite some time :
|
140
|
+
//return mapGeneratedKeys(context.getRuntime(), connection, statement, true);
|
141
|
+
// but we should assume SQLite JDBC will prefer sane API usage eventually :
|
142
|
+
genKeys = statement.executeQuery("SELECT last_insert_rowid()");
|
143
|
+
return doMapGeneratedKeys(context.runtime, genKeys, true);
|
144
|
+
}
|
145
|
+
catch (final SQLException e) {
|
146
|
+
debugMessage(context.runtime, "failed to get generated keys: ", e);
|
147
|
+
throw e;
|
151
148
|
}
|
149
|
+
finally { close(genKeys); close(statement); }
|
152
150
|
});
|
153
151
|
}
|
154
152
|
|
@@ -183,66 +181,64 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
183
181
|
final String tableName = table;
|
184
182
|
final String schemaName = schema;
|
185
183
|
// return super.indexes(context, tableName, name, schemaName);
|
186
|
-
return withConnection(context,
|
187
|
-
|
188
|
-
|
189
|
-
final RubyClass IndexDefinition = getIndexDefinition(runtime);
|
184
|
+
return withConnection(context, (Callable<IRubyObject>) connection -> {
|
185
|
+
final Ruby runtime = context.runtime;
|
186
|
+
final RubyClass IndexDefinition = getIndexDefinition(runtime);
|
190
187
|
|
191
|
-
|
188
|
+
final TableName table1 = extractTableName(connection, null, schemaName, tableName);
|
192
189
|
|
193
|
-
|
190
|
+
final List<RubyString> primaryKeys = primaryKeys(context, connection, table1);
|
194
191
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
}
|
205
|
-
throw e;
|
192
|
+
final DatabaseMetaData metaData = connection.getMetaData();
|
193
|
+
ResultSet indexInfoSet;
|
194
|
+
try {
|
195
|
+
indexInfoSet = metaData.getIndexInfo(table1.catalog, table1.schema, table1.name, false, true);
|
196
|
+
}
|
197
|
+
catch (SQLException e) {
|
198
|
+
final String msg = e.getMessage();
|
199
|
+
if ( msg != null && msg.startsWith("[SQLITE_ERROR] SQL error or missing database") ) {
|
200
|
+
return RubyArray.newEmptyArray(runtime); // on 3.8.7 getIndexInfo fails if table has no indexes
|
206
201
|
}
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
String indexName = indexInfoSet.getString(INDEX_INFO_NAME);
|
213
|
-
if ( indexName == null ) continue;
|
214
|
-
RubyArray currentColumns = null;
|
202
|
+
throw e;
|
203
|
+
}
|
204
|
+
final RubyArray indexes = RubyArray.newArray(runtime, 8);
|
205
|
+
try {
|
206
|
+
String currentIndex = null;
|
215
207
|
|
216
|
-
|
217
|
-
|
218
|
-
|
208
|
+
while ( indexInfoSet.next() ) {
|
209
|
+
String indexName = indexInfoSet.getString(INDEX_INFO_NAME);
|
210
|
+
if ( indexName == null ) continue;
|
211
|
+
RubyArray currentColumns = null;
|
219
212
|
|
220
|
-
|
221
|
-
|
222
|
-
|
213
|
+
final String columnName = indexInfoSet.getString(INDEX_INFO_COLUMN_NAME);
|
214
|
+
final RubyString rubyColumnName = cachedString(context, columnName);
|
215
|
+
if ( primaryKeys.contains(rubyColumnName) ) continue;
|
223
216
|
|
224
|
-
|
217
|
+
// We are working on a new index
|
218
|
+
if ( ! indexName.equals(currentIndex) ) {
|
219
|
+
currentIndex = indexName;
|
225
220
|
|
226
|
-
|
221
|
+
String indexTableName = indexInfoSet.getString(INDEX_INFO_TABLE_NAME);
|
227
222
|
|
228
|
-
|
229
|
-
cachedString(context, indexTableName), // table_name
|
230
|
-
cachedString(context, indexName), // index_name
|
231
|
-
nonUnique ? runtime.getFalse() : runtime.getTrue(), // unique
|
232
|
-
currentColumns = RubyArray.newArray(runtime, 4) // [] column names
|
233
|
-
};
|
223
|
+
final boolean nonUnique = indexInfoSet.getBoolean(INDEX_INFO_NON_UNIQUE);
|
234
224
|
|
235
|
-
|
236
|
-
|
225
|
+
IRubyObject[] args = new IRubyObject[] {
|
226
|
+
cachedString(context, indexTableName), // table_name
|
227
|
+
cachedString(context, indexName), // index_name
|
228
|
+
nonUnique ? context.fals : context.tru, // unique
|
229
|
+
currentColumns = RubyArray.newArray(runtime, 4) // [] column names
|
230
|
+
};
|
237
231
|
|
238
|
-
|
239
|
-
if ( currentColumns != null ) currentColumns.append(rubyColumnName);
|
232
|
+
indexes.append( IndexDefinition.newInstance(context, args, Block.NULL_BLOCK) ); // IndexDefinition.new
|
240
233
|
}
|
241
234
|
|
242
|
-
|
235
|
+
// one or more columns can be associated with an index
|
236
|
+
if ( currentColumns != null ) currentColumns.append(rubyColumnName);
|
237
|
+
}
|
243
238
|
|
244
|
-
|
245
|
-
|
239
|
+
return indexes;
|
240
|
+
|
241
|
+
} finally { close(indexInfoSet); }
|
246
242
|
});
|
247
243
|
}
|
248
244
|
|
@@ -390,8 +386,9 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
390
386
|
"create_savepoint (without name) not implemented!"
|
391
387
|
);
|
392
388
|
}
|
393
|
-
|
389
|
+
Statement statement = null;
|
394
390
|
try {
|
391
|
+
final Connection connection = getConnectionInternal(true);
|
395
392
|
connection.setAutoCommit(false);
|
396
393
|
// NOTE: JDBC driver does not support setSavepoint(String) :
|
397
394
|
( statement = connection.createStatement() ).execute("SAVEPOINT " + name.toString());
|
@@ -411,12 +408,13 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
411
408
|
public IRubyObject rollback_savepoint(final ThreadContext context, final IRubyObject name) {
|
412
409
|
if ( useSavepointAPI(context) ) return super.rollback_savepoint(context, name);
|
413
410
|
|
414
|
-
|
411
|
+
Statement statement = null;
|
415
412
|
try {
|
416
413
|
if ( getSavepoints(context).get(name) == null ) {
|
417
414
|
throw newSavepointNotSetError(context, name, "rollback");
|
418
415
|
}
|
419
416
|
// NOTE: JDBC driver does not implement rollback(Savepoint) :
|
417
|
+
final Connection connection = getConnectionInternal(true);
|
420
418
|
( statement = connection.createStatement() ).execute("ROLLBACK TO SAVEPOINT " + name.toString());
|
421
419
|
|
422
420
|
return context.nil;
|
@@ -434,12 +432,13 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
434
432
|
public IRubyObject release_savepoint(final ThreadContext context, final IRubyObject name) {
|
435
433
|
if ( useSavepointAPI(context) ) return super.release_savepoint(context, name);
|
436
434
|
|
437
|
-
|
435
|
+
Statement statement = null;
|
438
436
|
try {
|
439
437
|
if ( getSavepoints(context).remove(name) == null ) {
|
440
438
|
throw newSavepointNotSetError(context, name, "release");
|
441
439
|
}
|
442
440
|
// NOTE: JDBC driver does not implement release(Savepoint) :
|
441
|
+
final Connection connection = getConnectionInternal(true);
|
443
442
|
( statement = connection.createStatement() ).execute("RELEASE SAVEPOINT " + name.toString());
|
444
443
|
return context.nil;
|
445
444
|
} catch (SQLException e) {
|
@@ -453,19 +452,15 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
453
452
|
// a consistent JDBC layer.
|
454
453
|
@JRubyMethod(name = "supports_savepoints?")
|
455
454
|
public IRubyObject supports_savepoints_p(final ThreadContext context) throws SQLException {
|
456
|
-
return context.
|
455
|
+
return context.tru;
|
457
456
|
}
|
458
457
|
|
459
|
-
@
|
460
|
-
|
461
|
-
final Connection connection
|
462
|
-
|
463
|
-
final IRubyObject attribute, final int type) throws SQLException {
|
464
|
-
// Apparently active record stores booleans in sqlite as 't' and 'f' instead of the built in 1/0
|
465
|
-
statement.setString(index, value.isTrue() ? "t" : "f");
|
458
|
+
@JRubyMethod(name = "readonly?")
|
459
|
+
public IRubyObject readonly_p(final ThreadContext context) throws SQLException {
|
460
|
+
final Connection connection = getConnection(true);
|
461
|
+
return context.runtime.newBoolean(connection.isReadOnly());
|
466
462
|
}
|
467
463
|
|
468
|
-
|
469
464
|
@Override
|
470
465
|
protected void setDecimalParameter(final ThreadContext context,
|
471
466
|
final Connection connection, final PreparedStatement statement,
|
@@ -518,7 +513,7 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
518
513
|
final int index, IRubyObject value,
|
519
514
|
final IRubyObject attribute, final int type) throws SQLException {
|
520
515
|
|
521
|
-
if (value instanceof RubyTime) value = ((RubyTime) value).strftime(TIMESTAMP_FORMAT);
|
516
|
+
if (value instanceof RubyTime) value = ((RubyTime) value).strftime(context, TIMESTAMP_FORMAT);
|
522
517
|
|
523
518
|
setStringParameter(context, connection, statement, index, value, attribute, type);
|
524
519
|
}
|
@@ -37,6 +37,7 @@ import org.jruby.Ruby;
|
|
37
37
|
import org.jruby.RubyFloat;
|
38
38
|
import org.jruby.RubyString;
|
39
39
|
import org.jruby.RubyTime;
|
40
|
+
import org.jruby.ext.date.RubyDateTime;
|
40
41
|
import org.jruby.javasupport.Java;
|
41
42
|
import org.jruby.runtime.Block;
|
42
43
|
import org.jruby.runtime.ThreadContext;
|
@@ -51,6 +52,9 @@ import static arjdbc.util.StringHelper.decByte;
|
|
51
52
|
* @author kares
|
52
53
|
*/
|
53
54
|
public abstract class DateTimeUtils {
|
55
|
+
|
56
|
+
private static final GJChronology CHRONO_ITALY_UTC = GJChronology.getInstance(DateTimeZone.UTC);
|
57
|
+
|
54
58
|
public static RubyTime toTime(final ThreadContext context, final IRubyObject value) {
|
55
59
|
if (!(value instanceof RubyTime)) { // unlikely
|
56
60
|
return (RubyTime) TypeConverter.convertToTypeWithCheck(value, context.runtime.getTime(), "to_time");
|
@@ -218,9 +222,11 @@ public abstract class DateTimeUtils {
|
|
218
222
|
final int hours = time.getHours();
|
219
223
|
final int minutes = time.getMinutes();
|
220
224
|
final int seconds = time.getSeconds();
|
221
|
-
|
225
|
+
int nanos = time.getNanos(); // max 999-999-999
|
226
|
+
final int millis = nanos / 1000000;
|
227
|
+
nanos = nanos % 1000000;
|
222
228
|
|
223
|
-
DateTime dateTime = new DateTime(2000, 1, 1, hours, minutes, seconds, defaultZone);
|
229
|
+
DateTime dateTime = new DateTime(2000, 1, 1, hours, minutes, seconds, millis, defaultZone);
|
224
230
|
return RubyTime.newTime(context.runtime, dateTime, nanos);
|
225
231
|
}
|
226
232
|
|
@@ -233,9 +239,11 @@ public abstract class DateTimeUtils {
|
|
233
239
|
final int hours = timestamp.getHours();
|
234
240
|
final int minutes = timestamp.getMinutes();
|
235
241
|
final int seconds = timestamp.getSeconds();
|
236
|
-
|
242
|
+
int nanos = timestamp.getNanos(); // max 999-999-999
|
243
|
+
final int millis = nanos / 1000000;
|
244
|
+
nanos = nanos % 1000000;
|
237
245
|
|
238
|
-
DateTime dateTime = new DateTime(year, month, day, hours, minutes, seconds,
|
246
|
+
DateTime dateTime = new DateTime(year, month, day, hours, minutes, seconds, millis, defaultZone);
|
239
247
|
return RubyTime.newTime(context.runtime, dateTime, nanos);
|
240
248
|
}
|
241
249
|
|
@@ -260,6 +268,15 @@ public abstract class DateTimeUtils {
|
|
260
268
|
return newDate(context, year, month, day, ISOChronology.getInstance(zone));
|
261
269
|
}
|
262
270
|
|
271
|
+
@SuppressWarnings("deprecation")
|
272
|
+
public static IRubyObject newDate(final ThreadContext context, final Date date) {
|
273
|
+
final int year = date.getYear() + 1900;
|
274
|
+
final int month = date.getMonth() + 1;
|
275
|
+
final int day = date.getDate();
|
276
|
+
|
277
|
+
return newDate(context, year, month, day, CHRONO_ITALY_UTC);
|
278
|
+
}
|
279
|
+
|
263
280
|
// @Deprecated
|
264
281
|
public static Timestamp convertToTimestamp(final RubyFloat value) {
|
265
282
|
final Timestamp timestamp = new Timestamp(value.getLongValue() * 1000); // millis
|
@@ -332,9 +349,7 @@ public abstract class DateTimeUtils {
|
|
332
349
|
|
333
350
|
if ( bcEra ) year = -1 * year; // no + 1 since we use GJChronology
|
334
351
|
|
335
|
-
|
336
|
-
final Ruby runtime = context.runtime;
|
337
|
-
return runtime.getClass("Date").newInstance(context, Java.getInstance(runtime, dateTime), Block.NULL_BLOCK);
|
352
|
+
return newDate(context, year, month, day, GJChronology.getInstance(defaultZone));
|
338
353
|
}
|
339
354
|
|
340
355
|
public static IRubyObject parseTime(final ThreadContext context, final CharSequence str, final DateTimeZone defaultZone)
|
@@ -559,7 +574,7 @@ public abstract class DateTimeUtils {
|
|
559
574
|
}
|
560
575
|
|
561
576
|
private static IRubyObject newDate(final ThreadContext context, final int year, final int month, final int day,
|
562
|
-
final
|
577
|
+
final Chronology chronology) {
|
563
578
|
// NOTE: JRuby really needs a native date.rb until than its a bit costly going from ...
|
564
579
|
// java.sql.Date -> allocating a DateTime proxy, help a bit by shooting at the internals
|
565
580
|
//
|
@@ -618,14 +633,21 @@ public abstract class DateTimeUtils {
|
|
618
633
|
*/
|
619
634
|
public static String timestampTimeToString(final ThreadContext context,
|
620
635
|
final IRubyObject value, DateTimeZone zone, boolean withZone) {
|
621
|
-
|
622
|
-
|
636
|
+
DateTime dt;
|
637
|
+
int usec = 0;
|
638
|
+
if (value instanceof RubyDateTime) {
|
639
|
+
dt = ((RubyDateTime) value).getDateTime();
|
640
|
+
} else {
|
641
|
+
RubyTime timeValue = toTime(context, value);
|
642
|
+
dt = timeValue.getDateTime();
|
643
|
+
usec = (int) timeValue.getUSec();
|
644
|
+
}
|
623
645
|
|
624
646
|
StringBuilder sb = new StringBuilder(36);
|
625
647
|
|
626
648
|
int year = dt.getYear();
|
627
649
|
if (year <= 0) {
|
628
|
-
year--;
|
650
|
+
if (!(value instanceof RubyDateTime)) year--;
|
629
651
|
} else if (zone != null) {
|
630
652
|
dt = dateTimeInZone(dt, zone);
|
631
653
|
year = dt.getYear();
|
@@ -645,7 +667,7 @@ public abstract class DateTimeUtils {
|
|
645
667
|
if (year < 0) sb.append(" BC");
|
646
668
|
sb.append(' ');
|
647
669
|
|
648
|
-
appendTime(sb, chrono, millis,
|
670
|
+
appendTime(sb, chrono, millis, usec, withZone);
|
649
671
|
|
650
672
|
return sb.toString();
|
651
673
|
}
|