activerecord-jdbc-adapter 1.0.3-java → 50.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.travis.yml +79 -0
- data/.yardopts +4 -0
- data/CONTRIBUTING.md +50 -0
- data/Gemfile +91 -0
- data/History.md +1191 -0
- data/LICENSE.txt +22 -17
- data/README.md +169 -0
- data/RUNNING_TESTS.md +127 -0
- data/Rakefile +294 -5
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +55 -0
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +0 -5
- data/lib/arel/visitors/compat.rb +60 -0
- data/lib/arel/visitors/db2.rb +128 -6
- data/lib/arel/visitors/derby.rb +103 -10
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +18 -10
- data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
- data/lib/arel/visitors/sql_server.rb +225 -0
- data/lib/arel/visitors/sql_server/ng42.rb +293 -0
- data/lib/arjdbc.rb +11 -21
- data/lib/arjdbc/abstract/connection_management.rb +35 -0
- data/lib/arjdbc/abstract/core.rb +64 -0
- data/lib/arjdbc/abstract/database_statements.rb +64 -0
- data/lib/arjdbc/abstract/statement_cache.rb +58 -0
- data/lib/arjdbc/abstract/transaction_support.rb +86 -0
- data/lib/arjdbc/db2.rb +3 -1
- data/lib/arjdbc/db2/adapter.rb +630 -250
- data/lib/arjdbc/db2/as400.rb +130 -0
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +44 -0
- data/lib/arjdbc/derby.rb +1 -5
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +409 -217
- data/lib/arjdbc/derby/connection_methods.rb +16 -14
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +62 -50
- data/lib/arjdbc/firebird.rb +3 -1
- data/lib/arjdbc/firebird/adapter.rb +365 -62
- data/lib/arjdbc/firebird/connection_methods.rb +23 -0
- data/lib/arjdbc/h2.rb +2 -3
- data/lib/arjdbc/h2/adapter.rb +273 -6
- data/lib/arjdbc/h2/connection_methods.rb +23 -8
- data/lib/arjdbc/hsqldb.rb +2 -3
- data/lib/arjdbc/hsqldb/adapter.rb +204 -77
- data/lib/arjdbc/hsqldb/connection_methods.rb +24 -10
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +4 -2
- data/lib/arjdbc/informix/adapter.rb +78 -54
- data/lib/arjdbc/informix/connection_methods.rb +8 -9
- data/lib/arjdbc/jdbc.rb +59 -2
- data/lib/arjdbc/jdbc/adapter.rb +356 -166
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/base_ext.rb +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +27 -18
- data/lib/arjdbc/jdbc/column.rb +79 -20
- data/lib/arjdbc/jdbc/connection.rb +5 -119
- data/lib/arjdbc/jdbc/connection_methods.rb +32 -4
- data/lib/arjdbc/jdbc/error.rb +65 -0
- data/lib/arjdbc/jdbc/extension.rb +41 -29
- data/lib/arjdbc/jdbc/java.rb +5 -6
- data/lib/arjdbc/jdbc/jdbc.rake +3 -126
- data/lib/arjdbc/jdbc/railtie.rb +2 -9
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -10
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -0
- data/lib/arjdbc/jdbc/type_cast.rb +166 -0
- data/lib/arjdbc/jdbc/type_converter.rb +35 -19
- data/lib/arjdbc/mssql.rb +6 -3
- data/lib/arjdbc/mssql/adapter.rb +630 -298
- data/lib/arjdbc/mssql/column.rb +200 -0
- data/lib/arjdbc/mssql/connection_methods.rb +66 -17
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +189 -50
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/types.rb +343 -0
- data/lib/arjdbc/mssql/utils.rb +82 -0
- data/lib/arjdbc/mysql.rb +2 -3
- data/lib/arjdbc/mysql/adapter.rb +86 -356
- data/lib/arjdbc/mysql/connection_methods.rb +159 -23
- data/lib/arjdbc/oracle/adapter.rb +714 -263
- data/lib/arjdbc/postgresql.rb +2 -3
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +24 -0
- data/lib/arjdbc/postgresql/adapter.rb +570 -400
- data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +11 -0
- data/lib/arjdbc/postgresql/column.rb +51 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +57 -18
- data/lib/arjdbc/postgresql/name.rb +24 -0
- data/lib/arjdbc/postgresql/oid_types.rb +192 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +2 -3
- data/lib/arjdbc/sqlite3/adapter.rb +518 -198
- data/lib/arjdbc/sqlite3/connection_methods.rb +49 -24
- data/lib/arjdbc/sybase.rb +2 -2
- data/lib/arjdbc/sybase/adapter.rb +7 -6
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +52 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +215 -0
- data/lib/arjdbc/tasks/databases4.rake +39 -0
- data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
- data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
- data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/serialized_attributes.rb +98 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +1 -6
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +8 -0
- data/lib/jdbc_adapter.rb +1 -1
- data/lib/jdbc_adapter/rake_tasks.rb +3 -2
- data/lib/jdbc_adapter/version.rb +2 -1
- data/pom.xml +114 -0
- data/rails_generators/jdbc_generator.rb +1 -1
- data/rails_generators/templates/config/initializers/jdbc.rb +8 -5
- data/rails_generators/templates/lib/tasks/jdbc.rake +7 -4
- data/rakelib/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +132 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +67 -22
- data/rakelib/db.rake +61 -0
- data/rakelib/rails.rake +204 -29
- data/src/java/arjdbc/ArJdbcModule.java +286 -0
- data/src/java/arjdbc/db2/DB2Module.java +76 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +126 -0
- data/src/java/arjdbc/derby/DerbyModule.java +99 -243
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +152 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +174 -0
- data/src/java/arjdbc/{jdbc/JdbcConnectionFactory.java → h2/H2Module.java} +20 -6
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +27 -12
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +73 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +7 -29
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +132 -0
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +157 -0
- data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
- data/src/java/arjdbc/jdbc/DriverWrapper.java +119 -0
- data/src/java/arjdbc/jdbc/JdbcResult.java +130 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +3622 -948
- data/src/java/arjdbc/mssql/MSSQLModule.java +90 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +181 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +99 -81
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +294 -0
- data/src/java/arjdbc/oracle/OracleModule.java +80 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +387 -17
- data/src/java/arjdbc/postgresql/ByteaUtils.java +157 -0
- data/src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java +23 -0
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +77 -0
- data/src/java/arjdbc/postgresql/PostgreSQLResult.java +184 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +952 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +73 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +525 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/DateTimeUtils.java +580 -0
- data/src/java/arjdbc/util/ObjectSupport.java +65 -0
- data/src/java/arjdbc/util/QuotingUtils.java +138 -0
- data/src/java/arjdbc/util/StringCache.java +63 -0
- data/src/java/arjdbc/util/StringHelper.java +159 -0
- metadata +245 -268
- data/History.txt +0 -369
- data/Manifest.txt +0 -180
- data/README.txt +0 -181
- data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arel/visitors/mssql.rb +0 -44
- data/lib/arjdbc/jdbc/compatibility.rb +0 -51
- data/lib/arjdbc/jdbc/core_ext.rb +0 -24
- data/lib/arjdbc/jdbc/discover.rb +0 -18
- data/lib/arjdbc/jdbc/driver.rb +0 -44
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -87
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +0 -28
- data/lib/arjdbc/jdbc/require_driver.rb +0 -16
- data/lib/arjdbc/mimer.rb +0 -2
- data/lib/arjdbc/mimer/adapter.rb +0 -142
- data/lib/arjdbc/mssql/tsql_helper.rb +0 -61
- data/lib/arjdbc/oracle.rb +0 -3
- data/lib/arjdbc/oracle/connection_methods.rb +0 -11
- data/lib/pg.rb +0 -4
- data/rakelib/package.rake +0 -92
- data/rakelib/test.rake +0 -81
- data/src/java/arjdbc/jdbc/SQLBlock.java +0 -48
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +0 -127
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +0 -57
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +0 -64
- data/test/abstract_db_create.rb +0 -117
- data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -31
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/db/db2.rb +0 -11
- data/test/db/derby.rb +0 -12
- data/test/db/h2.rb +0 -11
- data/test/db/hsqldb.rb +0 -13
- data/test/db/informix.rb +0 -11
- data/test/db/jdbc.rb +0 -11
- data/test/db/jndi_config.rb +0 -40
- data/test/db/logger.rb +0 -3
- data/test/db/mssql.rb +0 -9
- data/test/db/mysql.rb +0 -10
- data/test/db/oracle.rb +0 -34
- data/test/db/postgres.rb +0 -9
- data/test/db/sqlite3.rb +0 -11
- data/test/db2_simple_test.rb +0 -66
- data/test/derby_migration_test.rb +0 -68
- data/test/derby_multibyte_test.rb +0 -12
- data/test/derby_simple_test.rb +0 -99
- data/test/generic_jdbc_connection_test.rb +0 -29
- data/test/h2_simple_test.rb +0 -41
- data/test/has_many_through.rb +0 -79
- data/test/helper.rb +0 -5
- data/test/hsqldb_simple_test.rb +0 -6
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc_common.rb +0 -25
- data/test/jndi_callbacks_test.rb +0 -40
- data/test/jndi_test.rb +0 -25
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -12
- data/test/models/auto_id.rb +0 -18
- data/test/models/data_types.rb +0 -28
- data/test/models/entry.rb +0 -43
- data/test/models/mixed_case.rb +0 -25
- data/test/models/reserved_word.rb +0 -18
- data/test/models/string_id.rb +0 -18
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/mssql_db_create_test.rb +0 -26
- data/test/mssql_identity_insert_test.rb +0 -19
- data/test/mssql_legacy_types_test.rb +0 -58
- data/test/mssql_limit_offset_test.rb +0 -136
- data/test/mssql_multibyte_test.rb +0 -18
- data/test/mssql_simple_test.rb +0 -55
- data/test/mysql_db_create_test.rb +0 -27
- data/test/mysql_info_test.rb +0 -113
- data/test/mysql_multibyte_test.rb +0 -10
- data/test/mysql_nonstandard_primary_key_test.rb +0 -42
- data/test/mysql_simple_test.rb +0 -49
- data/test/oracle_simple_test.rb +0 -18
- data/test/oracle_specific_test.rb +0 -83
- data/test/pick_rails_version.rb +0 -3
- data/test/postgres_db_create_test.rb +0 -32
- data/test/postgres_drop_db_test.rb +0 -16
- data/test/postgres_mixed_case_test.rb +0 -29
- data/test/postgres_nonseq_pkey_test.rb +0 -38
- data/test/postgres_reserved_test.rb +0 -22
- data/test/postgres_schema_search_path_test.rb +0 -44
- data/test/postgres_simple_test.rb +0 -51
- data/test/postgres_table_alias_length_test.rb +0 -15
- data/test/simple.rb +0 -546
- data/test/sqlite3_simple_test.rb +0 -233
- data/test/sybase_jtds_simple_test.rb +0 -28
@@ -0,0 +1,73 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright 2013 Karol Bucek.
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
* THE SOFTWARE.
|
23
|
+
*/
|
24
|
+
package arjdbc.sqlite3;
|
25
|
+
|
26
|
+
import static arjdbc.util.QuotingUtils.quoteCharAndDecorateWith;
|
27
|
+
import static arjdbc.util.QuotingUtils.quoteCharWith;
|
28
|
+
|
29
|
+
import org.jruby.Ruby;
|
30
|
+
import org.jruby.RubyModule;
|
31
|
+
import org.jruby.RubyString;
|
32
|
+
import org.jruby.anno.JRubyMethod;
|
33
|
+
import org.jruby.runtime.ThreadContext;
|
34
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
35
|
+
|
36
|
+
/**
|
37
|
+
* ArJdbc::SQLite3
|
38
|
+
*
|
39
|
+
* @author kares
|
40
|
+
*/
|
41
|
+
public class SQLite3Module {
|
42
|
+
|
43
|
+
public static RubyModule load(final RubyModule arJdbc) {
|
44
|
+
RubyModule sqlite3 = arJdbc.defineModuleUnder("SQLite3");
|
45
|
+
sqlite3.defineAnnotatedMethods( SQLite3Module.class );
|
46
|
+
return sqlite3;
|
47
|
+
}
|
48
|
+
|
49
|
+
public static RubyModule load(final Ruby runtime) {
|
50
|
+
return load( arjdbc.ArJdbcModule.get(runtime) );
|
51
|
+
}
|
52
|
+
|
53
|
+
@JRubyMethod(name = "quote_string", required = 1, frame = false)
|
54
|
+
public static IRubyObject quote_string(
|
55
|
+
final ThreadContext context,
|
56
|
+
final IRubyObject self,
|
57
|
+
final IRubyObject string) { // string.gsub("'", "''") :
|
58
|
+
final char single = '\'';
|
59
|
+
final RubyString quoted = quoteCharWith(
|
60
|
+
context, (RubyString) string, single, single
|
61
|
+
);
|
62
|
+
return quoted;
|
63
|
+
}
|
64
|
+
|
65
|
+
@JRubyMethod(name = "quote_column_name", required = 1)
|
66
|
+
public static IRubyObject quote_column_name(
|
67
|
+
final ThreadContext context,
|
68
|
+
final IRubyObject self,
|
69
|
+
final IRubyObject string) { // "#{name.to_s.gsub('"', '""')}"
|
70
|
+
return quoteCharAndDecorateWith(context, string.asString(), '"', '"', (byte) '"', (byte) '"');
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
@@ -0,0 +1,525 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Copyright (c) 2012-2013 Karol Bucek <self@kares.org>
|
3
|
+
* Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
|
4
|
+
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
5
|
+
* Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
* a copy of this software and associated documentation files (the
|
9
|
+
* "Software"), to deal in the Software without restriction, including
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
* the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be
|
16
|
+
* included in all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
***** END LICENSE BLOCK *****/
|
26
|
+
|
27
|
+
package arjdbc.sqlite3;
|
28
|
+
|
29
|
+
import java.io.IOException;
|
30
|
+
import java.sql.Connection;
|
31
|
+
import java.sql.ResultSet;
|
32
|
+
import java.sql.ResultSetMetaData;
|
33
|
+
import java.sql.SQLException;
|
34
|
+
import java.sql.Statement;
|
35
|
+
import java.sql.DatabaseMetaData;
|
36
|
+
import java.sql.PreparedStatement;
|
37
|
+
import java.sql.Savepoint;
|
38
|
+
import java.sql.Types;
|
39
|
+
import java.util.List;
|
40
|
+
import java.util.Locale;
|
41
|
+
|
42
|
+
import org.jruby.Ruby;
|
43
|
+
import org.jruby.RubyArray;
|
44
|
+
import org.jruby.RubyClass;
|
45
|
+
import org.jruby.RubyFixnum;
|
46
|
+
import org.jruby.RubyInteger;
|
47
|
+
import org.jruby.RubyNumeric;
|
48
|
+
import org.jruby.RubyString;
|
49
|
+
import org.jruby.RubyTime;
|
50
|
+
import org.jruby.anno.JRubyMethod;
|
51
|
+
import org.jruby.ext.bigdecimal.RubyBigDecimal;
|
52
|
+
import org.jruby.runtime.Block;
|
53
|
+
import org.jruby.runtime.ObjectAllocator;
|
54
|
+
import org.jruby.runtime.ThreadContext;
|
55
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
56
|
+
import org.jruby.util.SafePropertyAccessor;
|
57
|
+
|
58
|
+
import arjdbc.jdbc.Callable;
|
59
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
60
|
+
|
61
|
+
import static arjdbc.util.StringHelper.newDefaultInternalString;
|
62
|
+
import static arjdbc.util.StringHelper.newString;
|
63
|
+
|
64
|
+
/**
|
65
|
+
*
|
66
|
+
* @author enebo
|
67
|
+
*/
|
68
|
+
public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
69
|
+
private static final long serialVersionUID = -5783855018818472773L;
|
70
|
+
|
71
|
+
private final RubyString TIMESTAMP_FORMAT;
|
72
|
+
private IRubyObject encoding;
|
73
|
+
|
74
|
+
public SQLite3RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
75
|
+
super(runtime, metaClass);
|
76
|
+
|
77
|
+
TIMESTAMP_FORMAT = runtime.newString("%F %T.%6N");
|
78
|
+
}
|
79
|
+
|
80
|
+
public static RubyClass createSQLite3JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
81
|
+
final RubyClass clazz = getConnectionAdapters(runtime). // ActiveRecord::ConnectionAdapters
|
82
|
+
defineClassUnder("SQLite3JdbcConnection", jdbcConnection, ALLOCATOR);
|
83
|
+
clazz.defineAnnotatedMethods( SQLite3RubyJdbcConnection.class );
|
84
|
+
getConnectionAdapters(runtime).setConstant("Sqlite3JdbcConnection", clazz); // backwards-compat
|
85
|
+
return clazz;
|
86
|
+
}
|
87
|
+
|
88
|
+
public static RubyClass load(final Ruby runtime) {
|
89
|
+
RubyClass jdbcConnection = getJdbcConnection(runtime);
|
90
|
+
return createSQLite3JdbcConnectionClass(runtime, jdbcConnection);
|
91
|
+
}
|
92
|
+
|
93
|
+
protected static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
94
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
95
|
+
return new SQLite3RubyJdbcConnection(runtime, klass);
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
99
|
+
@JRubyMethod
|
100
|
+
public IRubyObject encoding(final ThreadContext context) throws SQLException {
|
101
|
+
if (encoding != null) return encoding;
|
102
|
+
|
103
|
+
return withConnection(context, new Callable<IRubyObject>() {
|
104
|
+
// FIXME: How many single result queries do we have in Java?
|
105
|
+
public IRubyObject call(final Connection connection) throws SQLException {
|
106
|
+
String query = "PRAGMA encoding";
|
107
|
+
Statement statement = null;
|
108
|
+
ResultSet resultSet = null;
|
109
|
+
try {
|
110
|
+
statement = createStatement(context, connection);
|
111
|
+
if (statement.execute(query)) {
|
112
|
+
// Enebo: I do not think we need to worry about failure here?
|
113
|
+
String encodingString = statement.getResultSet().getString(1);
|
114
|
+
|
115
|
+
encoding = cachedString(context, encodingString);
|
116
|
+
|
117
|
+
return encoding;
|
118
|
+
}
|
119
|
+
} catch (final SQLException e) {
|
120
|
+
debugErrorSQL(context, query);
|
121
|
+
throw e;
|
122
|
+
} finally {
|
123
|
+
close(resultSet);
|
124
|
+
close(statement);
|
125
|
+
}
|
126
|
+
|
127
|
+
return context.nil;
|
128
|
+
}
|
129
|
+
});
|
130
|
+
}
|
131
|
+
|
132
|
+
@JRubyMethod(name = {"last_insert_rowid", "last_insert_id"}, alias = "last_insert_row_id")
|
133
|
+
public IRubyObject last_insert_rowid(final ThreadContext context)
|
134
|
+
throws SQLException {
|
135
|
+
return withConnection(context, new Callable<IRubyObject>() {
|
136
|
+
public IRubyObject call(final Connection connection) throws SQLException {
|
137
|
+
Statement statement = null; ResultSet genKeys = null;
|
138
|
+
try {
|
139
|
+
statement = connection.createStatement();
|
140
|
+
// NOTE: strangely this will work and has been used for quite some time :
|
141
|
+
//return mapGeneratedKeys(context.getRuntime(), connection, statement, true);
|
142
|
+
// but we should assume SQLite JDBC will prefer sane API usage eventually :
|
143
|
+
genKeys = statement.executeQuery("SELECT last_insert_rowid()");
|
144
|
+
return doMapGeneratedKeys(context.runtime, genKeys, true);
|
145
|
+
}
|
146
|
+
catch (final SQLException e) {
|
147
|
+
debugMessage(context.runtime, "failed to get generated keys: ", e);
|
148
|
+
throw e;
|
149
|
+
}
|
150
|
+
finally { close(genKeys); close(statement); }
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}
|
154
|
+
|
155
|
+
// NOTE: interestingly it supports getGeneratedKeys but not executeUpdate
|
156
|
+
// + the driver does not report it supports it via the meta-data yet does
|
157
|
+
@Override
|
158
|
+
protected boolean supportsGeneratedKeys(final Connection connection) throws SQLException {
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
@Override
|
163
|
+
protected Statement createStatement(final ThreadContext context, final Connection connection)
|
164
|
+
throws SQLException {
|
165
|
+
final Statement statement = connection.createStatement();
|
166
|
+
IRubyObject escapeProcessing = getConfigValue(context, "statement_escape_processing");
|
167
|
+
if ( escapeProcessing != null && ! escapeProcessing.isNil() ) {
|
168
|
+
statement.setEscapeProcessing( escapeProcessing.isTrue() );
|
169
|
+
}
|
170
|
+
// else leave as is by default
|
171
|
+
return statement;
|
172
|
+
}
|
173
|
+
|
174
|
+
@Override
|
175
|
+
protected IRubyObject indexes(final ThreadContext context, String table, final String name, String schema) {
|
176
|
+
if ( table != null ) {
|
177
|
+
final int i = table.indexOf('.');
|
178
|
+
if ( i > 0 && schema == null ) {
|
179
|
+
schema = table.substring(0, i);
|
180
|
+
table = table.substring(i + 1);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
final String tableName = table;
|
184
|
+
final String schemaName = schema;
|
185
|
+
// return super.indexes(context, tableName, name, schemaName);
|
186
|
+
return withConnection(context, new Callable<IRubyObject>() {
|
187
|
+
public RubyArray call(final Connection connection) throws SQLException {
|
188
|
+
final Ruby runtime = context.runtime;
|
189
|
+
final RubyClass IndexDefinition = getIndexDefinition(runtime);
|
190
|
+
|
191
|
+
final TableName table = extractTableName(connection, null, schemaName, tableName);
|
192
|
+
|
193
|
+
final List<RubyString> primaryKeys = primaryKeys(context, connection, table);
|
194
|
+
|
195
|
+
final DatabaseMetaData metaData = connection.getMetaData();
|
196
|
+
ResultSet indexInfoSet;
|
197
|
+
try {
|
198
|
+
indexInfoSet = metaData.getIndexInfo(table.catalog, table.schema, table.name, false, true);
|
199
|
+
}
|
200
|
+
catch (SQLException e) {
|
201
|
+
final String msg = e.getMessage();
|
202
|
+
if ( msg != null && msg.startsWith("[SQLITE_ERROR] SQL error or missing database") ) {
|
203
|
+
return RubyArray.newEmptyArray(runtime); // on 3.8.7 getIndexInfo fails if table has no indexes
|
204
|
+
}
|
205
|
+
throw e;
|
206
|
+
}
|
207
|
+
final RubyArray indexes = RubyArray.newArray(runtime, 8);
|
208
|
+
try {
|
209
|
+
String currentIndex = null;
|
210
|
+
|
211
|
+
while ( indexInfoSet.next() ) {
|
212
|
+
String indexName = indexInfoSet.getString(INDEX_INFO_NAME);
|
213
|
+
if ( indexName == null ) continue;
|
214
|
+
RubyArray currentColumns = null;
|
215
|
+
|
216
|
+
final String columnName = indexInfoSet.getString(INDEX_INFO_COLUMN_NAME);
|
217
|
+
final RubyString rubyColumnName = cachedString(context, columnName);
|
218
|
+
if ( primaryKeys.contains(rubyColumnName) ) continue;
|
219
|
+
|
220
|
+
// We are working on a new index
|
221
|
+
if ( ! indexName.equals(currentIndex) ) {
|
222
|
+
currentIndex = indexName;
|
223
|
+
|
224
|
+
String indexTableName = indexInfoSet.getString(INDEX_INFO_TABLE_NAME);
|
225
|
+
|
226
|
+
final boolean nonUnique = indexInfoSet.getBoolean(INDEX_INFO_NON_UNIQUE);
|
227
|
+
|
228
|
+
IRubyObject[] args = new IRubyObject[] {
|
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
|
+
};
|
234
|
+
|
235
|
+
indexes.append( IndexDefinition.newInstance(context, args, Block.NULL_BLOCK) ); // IndexDefinition.new
|
236
|
+
}
|
237
|
+
|
238
|
+
// one or more columns can be associated with an index
|
239
|
+
if ( currentColumns != null ) currentColumns.append(rubyColumnName);
|
240
|
+
}
|
241
|
+
|
242
|
+
return indexes;
|
243
|
+
|
244
|
+
} finally { close(indexInfoSet); }
|
245
|
+
}
|
246
|
+
});
|
247
|
+
}
|
248
|
+
|
249
|
+
@Override
|
250
|
+
protected TableName extractTableName(
|
251
|
+
final Connection connection, String catalog, String schema,
|
252
|
+
final String tableName) throws IllegalArgumentException, SQLException {
|
253
|
+
|
254
|
+
final List<String> nameParts = split(tableName, '.');
|
255
|
+
final int len = nameParts.size();
|
256
|
+
if ( len > 3 ) {
|
257
|
+
throw new IllegalArgumentException("table name: " + tableName + " should not contain more than 2 '.'");
|
258
|
+
}
|
259
|
+
|
260
|
+
String name = tableName;
|
261
|
+
|
262
|
+
if ( len == 2 ) {
|
263
|
+
schema = nameParts.get(0);
|
264
|
+
name = nameParts.get(1);
|
265
|
+
}
|
266
|
+
else if ( len == 3 ) {
|
267
|
+
catalog = nameParts.get(0);
|
268
|
+
schema = nameParts.get(1);
|
269
|
+
name = nameParts.get(2);
|
270
|
+
}
|
271
|
+
|
272
|
+
if ( schema != null ) {
|
273
|
+
// NOTE: hack to work-around SQLite JDBC ignoring schema :
|
274
|
+
return new TableName(catalog, null, schema + '.' + name);
|
275
|
+
}
|
276
|
+
return new TableName(catalog, schema, name);
|
277
|
+
}
|
278
|
+
|
279
|
+
@Override
|
280
|
+
protected IRubyObject jdbcToRuby(final ThreadContext context,
|
281
|
+
final Ruby runtime, final int column, int type, final ResultSet resultSet)
|
282
|
+
throws SQLException {
|
283
|
+
// This is rather gross, and only needed because the resultset metadata for SQLite tries to be overly
|
284
|
+
// clever, and returns a type for the column of the "current" row, so an integer value stored in a
|
285
|
+
// decimal column is returned as Types.INTEGER. Therefore, if the first row of a resultset was an
|
286
|
+
// integer value, all rows of that result set would get truncated.
|
287
|
+
if ( resultSet instanceof ResultSetMetaData ) {
|
288
|
+
type = ((ResultSetMetaData) resultSet).getColumnType(column);
|
289
|
+
}
|
290
|
+
// since JDBC 3.8 there seems to be more cleverness built-in that
|
291
|
+
// causes (<= 3.8.7) to get things wrong ... reports DATE SQL type
|
292
|
+
// for "datetime" columns :
|
293
|
+
if ( type == Types.DATE ) {
|
294
|
+
// return timestampToRuby(context, runtime, resultSet, column);
|
295
|
+
return stringToRuby(context, runtime, resultSet, column);
|
296
|
+
}
|
297
|
+
return super.jdbcToRuby(context, runtime, column, type, resultSet);
|
298
|
+
}
|
299
|
+
|
300
|
+
@Override
|
301
|
+
protected IRubyObject stringToRuby(final ThreadContext context,
|
302
|
+
final Ruby runtime, final ResultSet resultSet, final int column) throws SQLException {
|
303
|
+
final byte[] value = resultSet.getBytes(column);
|
304
|
+
if ( value == null ) return context.nil; // resultSet.wasNull()
|
305
|
+
return newDefaultInternalString(runtime, value);
|
306
|
+
}
|
307
|
+
|
308
|
+
@Override
|
309
|
+
protected IRubyObject streamToRuby(final ThreadContext context,
|
310
|
+
final Ruby runtime, final ResultSet resultSet, final int column)
|
311
|
+
throws SQLException, IOException {
|
312
|
+
final byte[] bytes = resultSet.getBytes(column);
|
313
|
+
if ( bytes == null ) return context.nil; // resultSet.wasNull()
|
314
|
+
return newString(runtime, bytes);
|
315
|
+
}
|
316
|
+
|
317
|
+
@Override
|
318
|
+
protected RubyArray mapTables(final ThreadContext context, final Connection connection,
|
319
|
+
final String catalog, final String schemaPattern, final String tablePattern,
|
320
|
+
final ResultSet tablesSet) throws SQLException {
|
321
|
+
final RubyArray tables = context.runtime.newArray(24);
|
322
|
+
while ( tablesSet.next() ) {
|
323
|
+
String name = tablesSet.getString(TABLES_TABLE_NAME);
|
324
|
+
name = name.toLowerCase(Locale.ENGLISH); // simply lower-case for SQLite3
|
325
|
+
tables.append( RubyString.newUnicodeString(context.runtime, name) );
|
326
|
+
}
|
327
|
+
return tables;
|
328
|
+
}
|
329
|
+
|
330
|
+
@Override
|
331
|
+
protected String caseConvertIdentifierForRails(final Connection connection, final String value) {
|
332
|
+
return value;
|
333
|
+
}
|
334
|
+
|
335
|
+
@Override
|
336
|
+
protected String caseConvertIdentifierForJdbc(final Connection connection, final String value) {
|
337
|
+
return value;
|
338
|
+
}
|
339
|
+
|
340
|
+
private static class SavepointStub implements Savepoint {
|
341
|
+
|
342
|
+
static final SavepointStub INSTANCE = new SavepointStub();
|
343
|
+
|
344
|
+
@Override
|
345
|
+
public int getSavepointId() throws SQLException {
|
346
|
+
throw new UnsupportedOperationException();
|
347
|
+
}
|
348
|
+
|
349
|
+
@Override
|
350
|
+
public String getSavepointName() throws SQLException {
|
351
|
+
throw new UnsupportedOperationException();
|
352
|
+
}
|
353
|
+
|
354
|
+
}
|
355
|
+
|
356
|
+
private static Boolean useSavepointAPI;
|
357
|
+
static {
|
358
|
+
final String savepoints = SafePropertyAccessor.getProperty("arjdbc.sqlite.savepoints");
|
359
|
+
if ( savepoints != null ) useSavepointAPI = Boolean.parseBoolean(savepoints);
|
360
|
+
}
|
361
|
+
|
362
|
+
private static boolean useSavepointAPI(final ThreadContext context) {
|
363
|
+
final Boolean working = useSavepointAPI;
|
364
|
+
if ( working == null ) {
|
365
|
+
try { // available since JDBC-SQLite 3.8.9
|
366
|
+
context.runtime.getJavaSupport().loadJavaClass("org.sqlite.jdbc3.JDBC3Savepoint");
|
367
|
+
return useSavepointAPI = Boolean.TRUE;
|
368
|
+
}
|
369
|
+
catch (ClassNotFoundException ex) { /* < 3.8.9 */ }
|
370
|
+
// catch (RuntimeException ex) { }
|
371
|
+
return useSavepointAPI = Boolean.FALSE;
|
372
|
+
}
|
373
|
+
return working;
|
374
|
+
}
|
375
|
+
|
376
|
+
@Override
|
377
|
+
public IRubyObject begin(ThreadContext context, IRubyObject level) {
|
378
|
+
throw context.runtime.newRaiseException(getTransactionIsolationError(context.runtime),
|
379
|
+
"SQLite3 does not support isolation levels"
|
380
|
+
);
|
381
|
+
}
|
382
|
+
|
383
|
+
@Override
|
384
|
+
@JRubyMethod(name = "create_savepoint", required = 1)
|
385
|
+
public IRubyObject create_savepoint(final ThreadContext context, final IRubyObject name) {
|
386
|
+
if ( useSavepointAPI(context) ) return super.create_savepoint(context, name);
|
387
|
+
|
388
|
+
if ( name == context.nil ) {
|
389
|
+
throw context.runtime.newRaiseException(context.runtime.getNotImplementedError(),
|
390
|
+
"create_savepoint (without name) not implemented!"
|
391
|
+
);
|
392
|
+
}
|
393
|
+
final Connection connection = getConnection(true); Statement statement = null;
|
394
|
+
try {
|
395
|
+
connection.setAutoCommit(false);
|
396
|
+
// NOTE: JDBC driver does not support setSavepoint(String) :
|
397
|
+
( statement = connection.createStatement() ).execute("SAVEPOINT " + name.toString());
|
398
|
+
|
399
|
+
getSavepoints(context).put(name, SavepointStub.INSTANCE);
|
400
|
+
|
401
|
+
return name;
|
402
|
+
}
|
403
|
+
catch (SQLException e) {
|
404
|
+
return handleException(context, e);
|
405
|
+
}
|
406
|
+
finally { close(statement); }
|
407
|
+
}
|
408
|
+
|
409
|
+
@Override
|
410
|
+
@JRubyMethod(name = "rollback_savepoint", required = 1)
|
411
|
+
public IRubyObject rollback_savepoint(final ThreadContext context, final IRubyObject name) {
|
412
|
+
if ( useSavepointAPI(context) ) return super.rollback_savepoint(context, name);
|
413
|
+
|
414
|
+
final Connection connection = getConnection(true); Statement statement = null;
|
415
|
+
try {
|
416
|
+
if ( getSavepoints(context).get(name) == null ) {
|
417
|
+
throw newSavepointNotSetError(context, name, "rollback");
|
418
|
+
}
|
419
|
+
// NOTE: JDBC driver does not implement rollback(Savepoint) :
|
420
|
+
( statement = connection.createStatement() ).execute("ROLLBACK TO SAVEPOINT " + name.toString());
|
421
|
+
|
422
|
+
return context.nil;
|
423
|
+
}
|
424
|
+
catch (SQLException e) {
|
425
|
+
return handleException(context, e);
|
426
|
+
}
|
427
|
+
finally { close(statement); }
|
428
|
+
}
|
429
|
+
|
430
|
+
// FIXME: Update our JDBC adapter to later version which basically performs this SQL in
|
431
|
+
// this method. Then we can use base RubyJdbcConnection version.
|
432
|
+
@Override
|
433
|
+
@JRubyMethod(name = "release_savepoint", required = 1)
|
434
|
+
public IRubyObject release_savepoint(final ThreadContext context, final IRubyObject name) {
|
435
|
+
if ( useSavepointAPI(context) ) return super.release_savepoint(context, name);
|
436
|
+
|
437
|
+
final Connection connection = getConnection(true); Statement statement = null;
|
438
|
+
try {
|
439
|
+
if ( getSavepoints(context).remove(name) == null ) {
|
440
|
+
throw newSavepointNotSetError(context, name, "release");
|
441
|
+
}
|
442
|
+
// NOTE: JDBC driver does not implement release(Savepoint) :
|
443
|
+
( statement = connection.createStatement() ).execute("RELEASE SAVEPOINT " + name.toString());
|
444
|
+
return context.nil;
|
445
|
+
} catch (SQLException e) {
|
446
|
+
return handleException(context, e);
|
447
|
+
}
|
448
|
+
finally { close(statement); }
|
449
|
+
}
|
450
|
+
|
451
|
+
// Note: transaction_support.rb overrides sqlite3 adapters version which just returns true.
|
452
|
+
// Rather than re-define it in SQLite3Adapter I will just define it here so we appear to have
|
453
|
+
// a consistent JDBC layer.
|
454
|
+
@JRubyMethod(name = "supports_savepoints?")
|
455
|
+
public IRubyObject supports_savepoints_p(final ThreadContext context) throws SQLException {
|
456
|
+
return context.runtime.getTrue();
|
457
|
+
}
|
458
|
+
|
459
|
+
@Override
|
460
|
+
protected void setBooleanParameter(final ThreadContext context,
|
461
|
+
final Connection connection, final PreparedStatement statement,
|
462
|
+
final int index, final IRubyObject value,
|
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");
|
466
|
+
}
|
467
|
+
|
468
|
+
|
469
|
+
@Override
|
470
|
+
protected void setDecimalParameter(final ThreadContext context,
|
471
|
+
final Connection connection, final PreparedStatement statement,
|
472
|
+
final int index, final IRubyObject value,
|
473
|
+
final IRubyObject attribute, final int type) throws SQLException {
|
474
|
+
if (value instanceof RubyBigDecimal) {
|
475
|
+
statement.setString(index, ((RubyBigDecimal) value).getValue().toString());
|
476
|
+
}
|
477
|
+
else if ( value instanceof RubyFixnum) {
|
478
|
+
statement.setLong(index, ((RubyFixnum) value).getLongValue());
|
479
|
+
}
|
480
|
+
else if ( value instanceof RubyInteger) { // Bignum
|
481
|
+
statement.setString(index, ((RubyInteger) value).getBigIntegerValue().toString());
|
482
|
+
}
|
483
|
+
else if ( value instanceof RubyNumeric ) {
|
484
|
+
statement.setDouble(index, ((RubyNumeric) value).getDoubleValue());
|
485
|
+
}
|
486
|
+
else { // e.g. `BigDecimal '42.00000000000000000001'`
|
487
|
+
RubyBigDecimal val = RubyBigDecimal.newInstance(context, context.runtime.getModule("BigDecimal"), value);
|
488
|
+
statement.setString(index, val.getValue().toString());
|
489
|
+
}
|
490
|
+
}
|
491
|
+
|
492
|
+
// Treat dates as strings, this can potentially be removed if we update
|
493
|
+
// the driver to the latest and tell it to store dates/times as text
|
494
|
+
@Override
|
495
|
+
protected void setDateParameter(final ThreadContext context,
|
496
|
+
final Connection connection, final PreparedStatement statement,
|
497
|
+
final int index, IRubyObject value,
|
498
|
+
final IRubyObject attribute, final int type) throws SQLException {
|
499
|
+
|
500
|
+
setStringParameter(context, connection, statement, index, value, attribute, type);
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
// Treat times as strings
|
505
|
+
@Override
|
506
|
+
protected void setTimeParameter(final ThreadContext context,
|
507
|
+
final Connection connection, final PreparedStatement statement,
|
508
|
+
final int index, IRubyObject value,
|
509
|
+
final IRubyObject attribute, final int type) throws SQLException {
|
510
|
+
|
511
|
+
setTimestampParameter(context, connection, statement, index, timeInDefaultTimeZone(context, value), attribute, type);
|
512
|
+
}
|
513
|
+
|
514
|
+
// Treat timestamps as strings
|
515
|
+
@Override
|
516
|
+
protected void setTimestampParameter(final ThreadContext context,
|
517
|
+
final Connection connection, final PreparedStatement statement,
|
518
|
+
final int index, IRubyObject value,
|
519
|
+
final IRubyObject attribute, final int type) throws SQLException {
|
520
|
+
|
521
|
+
if (value instanceof RubyTime) value = ((RubyTime) value).strftime(TIMESTAMP_FORMAT);
|
522
|
+
|
523
|
+
setStringParameter(context, connection, statement, index, value, attribute, type);
|
524
|
+
}
|
525
|
+
}
|