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,90 @@
|
|
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.mssql;
|
25
|
+
|
26
|
+
import static arjdbc.util.QuotingUtils.BYTES_0;
|
27
|
+
import static arjdbc.util.QuotingUtils.BYTES_1;
|
28
|
+
import static arjdbc.util.QuotingUtils.quoteCharAndDecorateWith;
|
29
|
+
import static arjdbc.util.QuotingUtils.quoteSingleQuotesWithFallback;
|
30
|
+
|
31
|
+
import org.jruby.Ruby;
|
32
|
+
import org.jruby.RubyModule;
|
33
|
+
import org.jruby.RubyString;
|
34
|
+
import org.jruby.anno.JRubyMethod;
|
35
|
+
import org.jruby.runtime.ThreadContext;
|
36
|
+
import org.jruby.runtime.Visibility;
|
37
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
38
|
+
import org.jruby.util.ByteList;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* ArJdbc::MSSQL
|
42
|
+
*
|
43
|
+
* @author kares
|
44
|
+
*/
|
45
|
+
public class MSSQLModule {
|
46
|
+
|
47
|
+
public static RubyModule load(final RubyModule arJdbc) {
|
48
|
+
RubyModule mssql = arJdbc.defineModuleUnder("MSSQL");
|
49
|
+
mssql.defineAnnotatedMethods( MSSQLModule.class );
|
50
|
+
return mssql;
|
51
|
+
}
|
52
|
+
|
53
|
+
public static RubyModule load(final Ruby runtime) {
|
54
|
+
return load( arjdbc.ArJdbcModule.get(runtime) );
|
55
|
+
}
|
56
|
+
|
57
|
+
@JRubyMethod(name = "quote_string", required = 1)
|
58
|
+
public static IRubyObject quote_string(final ThreadContext context,
|
59
|
+
final IRubyObject self, final IRubyObject string) {
|
60
|
+
return quoteSingleQuotesWithFallback(context, string);
|
61
|
+
}
|
62
|
+
|
63
|
+
@JRubyMethod(name = "quoted_true", required = 0)
|
64
|
+
public static IRubyObject quoted_true(final ThreadContext context,
|
65
|
+
final IRubyObject self) {
|
66
|
+
return RubyString.newString(context.runtime, BYTES_1);
|
67
|
+
}
|
68
|
+
|
69
|
+
@JRubyMethod(name = "quoted_false", required = 0)
|
70
|
+
public static IRubyObject quoted_false(final ThreadContext context,
|
71
|
+
final IRubyObject self) {
|
72
|
+
return RubyString.newString(context.runtime, BYTES_0);
|
73
|
+
}
|
74
|
+
|
75
|
+
// part =~ /^\[.*\]$/ ? part : "[#{part.gsub(']', ']]')}]"
|
76
|
+
@SuppressWarnings("deprecation")
|
77
|
+
@JRubyMethod(required = 1, visibility = Visibility.PRIVATE)
|
78
|
+
public static IRubyObject quote_name_part(final ThreadContext context,
|
79
|
+
final IRubyObject self, final IRubyObject part) {
|
80
|
+
|
81
|
+
final RubyString partString = (RubyString) part;
|
82
|
+
final ByteList str = partString.getByteList();
|
83
|
+
if ( str.charAt(0) == '[' && str.charAt(str.length() - 1) == ']' ) {
|
84
|
+
return part; // part =~ /^\[.*\]$/ ? part
|
85
|
+
}
|
86
|
+
|
87
|
+
return quoteCharAndDecorateWith(context, partString, ']', ']', (byte) '[', (byte) ']');
|
88
|
+
}
|
89
|
+
|
90
|
+
}
|
@@ -0,0 +1,181 @@
|
|
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
|
+
package arjdbc.mssql;
|
27
|
+
|
28
|
+
import arjdbc.jdbc.Callable;
|
29
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
30
|
+
|
31
|
+
import java.sql.Connection;
|
32
|
+
import java.sql.DatabaseMetaData;
|
33
|
+
import java.sql.ResultSet;
|
34
|
+
import java.sql.SQLException;
|
35
|
+
import java.sql.Types;
|
36
|
+
|
37
|
+
import org.jruby.Ruby;
|
38
|
+
import org.jruby.RubyArray;
|
39
|
+
import org.jruby.RubyBoolean;
|
40
|
+
import org.jruby.RubyClass;
|
41
|
+
import org.jruby.RubyString;
|
42
|
+
import org.jruby.anno.JRubyMethod;
|
43
|
+
import org.jruby.runtime.ObjectAllocator;
|
44
|
+
import org.jruby.runtime.ThreadContext;
|
45
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
46
|
+
import org.jruby.util.ByteList;
|
47
|
+
|
48
|
+
/**
|
49
|
+
*
|
50
|
+
* @author nicksieger
|
51
|
+
*/
|
52
|
+
public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
53
|
+
private static final long serialVersionUID = -745716565005219263L;
|
54
|
+
|
55
|
+
public MSSQLRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
56
|
+
super(runtime, metaClass);
|
57
|
+
}
|
58
|
+
|
59
|
+
public static RubyClass createMSSQLJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
60
|
+
final RubyClass clazz = getConnectionAdapters(runtime). // ActiveRecord::ConnectionAdapters
|
61
|
+
defineClassUnder("MSSQLJdbcConnection", jdbcConnection, ALLOCATOR);
|
62
|
+
clazz.defineAnnotatedMethods(MSSQLRubyJdbcConnection.class);
|
63
|
+
getConnectionAdapters(runtime).setConstant("MssqlJdbcConnection", clazz); // backwards-compat
|
64
|
+
return clazz;
|
65
|
+
}
|
66
|
+
|
67
|
+
public static RubyClass load(final Ruby runtime) {
|
68
|
+
RubyClass jdbcConnection = getJdbcConnection(runtime);
|
69
|
+
return createMSSQLJdbcConnectionClass(runtime, jdbcConnection);
|
70
|
+
}
|
71
|
+
|
72
|
+
protected static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
73
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
74
|
+
return new MSSQLRubyJdbcConnection(runtime, klass);
|
75
|
+
}
|
76
|
+
};
|
77
|
+
|
78
|
+
private static final byte[] EXEC = new byte[] { 'e', 'x', 'e', 'c' };
|
79
|
+
|
80
|
+
@JRubyMethod(name = "exec?", required = 1, meta = true, frame = false)
|
81
|
+
public static RubyBoolean exec_p(ThreadContext context, IRubyObject self, IRubyObject sql) {
|
82
|
+
final ByteList sqlBytes = sql.asString().getByteList();
|
83
|
+
return context.runtime.newBoolean( startsWithIgnoreCase(sqlBytes, EXEC) );
|
84
|
+
}
|
85
|
+
|
86
|
+
@Override
|
87
|
+
protected RubyArray mapTables(final ThreadContext context, final Connection connection,
|
88
|
+
final String catalog, final String schemaPattern, final String tablePattern,
|
89
|
+
final ResultSet tablesSet) throws SQLException, IllegalStateException {
|
90
|
+
|
91
|
+
final RubyArray tables = context.runtime.newArray();
|
92
|
+
|
93
|
+
while ( tablesSet.next() ) {
|
94
|
+
String schema = tablesSet.getString(TABLES_TABLE_SCHEM);
|
95
|
+
if ( schema != null ) schema = schema.toLowerCase();
|
96
|
+
// Under MS-SQL, don't return system tables/views unless explicitly asked for :
|
97
|
+
if ( schemaPattern == null &&
|
98
|
+
( "sys".equals(schema) || "information_schema".equals(schema) ) ) {
|
99
|
+
continue;
|
100
|
+
}
|
101
|
+
String name = tablesSet.getString(TABLES_TABLE_NAME);
|
102
|
+
if ( name == null ) {
|
103
|
+
// NOTE: seems there's a jTDS but when doing getColumns while
|
104
|
+
// EXPLAIN is on (e.g. `SET SHOWPLAN_TEXT ON`) not returning
|
105
|
+
// correct result set with table info (null NAME, invalid CAT)
|
106
|
+
throw new IllegalStateException("got null name while matching table(s): [" +
|
107
|
+
catalog + "." + schemaPattern + "." + tablePattern + "] check " +
|
108
|
+
"if this happened during EXPLAIN (SET SHOWPLAN_TEXT ON) if so please try " +
|
109
|
+
"turning it off using the system property 'arjdbc.mssql.explain_support.disabled=true' " +
|
110
|
+
"or programatically by changing: `ArJdbc::MSSQL::ExplainSupport::DISABLED`");
|
111
|
+
}
|
112
|
+
tables.add( cachedString(context, caseConvertIdentifierForRails(connection, name)) );
|
113
|
+
}
|
114
|
+
return tables;
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Microsoft SQL 2000+ support schemas
|
119
|
+
*/
|
120
|
+
@Override
|
121
|
+
protected boolean databaseSupportsSchemas() {
|
122
|
+
return true;
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Treat LONGVARCHAR as CLOB on MSSQL for purposes of converting a JDBC value to Ruby.
|
127
|
+
*/
|
128
|
+
@Override
|
129
|
+
protected IRubyObject jdbcToRuby(
|
130
|
+
final ThreadContext context, final Ruby runtime,
|
131
|
+
final int column, int type, final ResultSet resultSet)
|
132
|
+
throws SQLException {
|
133
|
+
if ( type == Types.LONGVARCHAR || type == Types.LONGNVARCHAR ) type = Types.CLOB;
|
134
|
+
return super.jdbcToRuby(context, runtime, column, type, resultSet);
|
135
|
+
}
|
136
|
+
|
137
|
+
@Override
|
138
|
+
protected ColumnData[] extractColumns(final ThreadContext context,
|
139
|
+
final Connection connection, final ResultSet resultSet,
|
140
|
+
final boolean downCase) throws SQLException {
|
141
|
+
return filterRowNumFromColumns( super.extractColumns(context, connection, resultSet, downCase) );
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Filter out the <tt>_row_num</tt> column from results.
|
146
|
+
*/
|
147
|
+
private static ColumnData[] filterRowNumFromColumns(final ColumnData[] columns) {
|
148
|
+
for ( int i = 0; i < columns.length; i++ ) {
|
149
|
+
if ( "_row_num".equals( columns[i].getName() ) ) {
|
150
|
+
final ColumnData[] filtered = new ColumnData[columns.length - 1];
|
151
|
+
|
152
|
+
if ( i > 0 ) {
|
153
|
+
System.arraycopy(columns, 0, filtered, 0, i);
|
154
|
+
}
|
155
|
+
|
156
|
+
if ( i + 1 < columns.length ) {
|
157
|
+
System.arraycopy(columns, i + 1, filtered, i, columns.length - (i + 1));
|
158
|
+
}
|
159
|
+
|
160
|
+
return filtered;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
return columns;
|
164
|
+
}
|
165
|
+
|
166
|
+
// internal helper not meant as a "public" API - used in one place thus every
|
167
|
+
@JRubyMethod(name = "jtds_driver?")
|
168
|
+
public RubyBoolean jtds_driver_p(final ThreadContext context) throws SQLException {
|
169
|
+
// "jTDS Type 4 JDBC Driver for MS SQL Server and Sybase"
|
170
|
+
// SQLJDBC: "Microsoft JDBC Driver 4.0 for SQL Server"
|
171
|
+
return withConnection(context, new Callable<RubyBoolean>() {
|
172
|
+
// NOTE: only used in one place for now (on release_savepoint) ...
|
173
|
+
// might get optimized to only happen once since driver won't change
|
174
|
+
public RubyBoolean call(final Connection connection) throws SQLException {
|
175
|
+
final String driver = connection.getMetaData().getDriverName();
|
176
|
+
return context.getRuntime().newBoolean( driver.indexOf("jTDS") >= 0 );
|
177
|
+
}
|
178
|
+
});
|
179
|
+
}
|
180
|
+
|
181
|
+
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Copyright (c) 2012-2013 Karol Bucek <self@kares.org>
|
2
3
|
* Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
|
3
4
|
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
4
5
|
*
|
@@ -24,111 +25,128 @@
|
|
24
25
|
|
25
26
|
package arjdbc.mysql;
|
26
27
|
|
27
|
-
import
|
28
|
-
|
28
|
+
import org.jcodings.specific.UTF8Encoding;
|
29
|
+
import org.jruby.Ruby;
|
30
|
+
import org.jruby.RubyFixnum;
|
29
31
|
import org.jruby.RubyModule;
|
30
32
|
import org.jruby.RubyString;
|
31
|
-
|
32
33
|
import org.jruby.anno.JRubyMethod;
|
33
34
|
import org.jruby.runtime.ThreadContext;
|
34
35
|
import org.jruby.runtime.builtin.IRubyObject;
|
35
|
-
|
36
36
|
import org.jruby.util.ByteList;
|
37
37
|
|
38
|
+
import static arjdbc.util.QuotingUtils.BYTES_0;
|
39
|
+
import static arjdbc.util.QuotingUtils.BYTES_1;
|
40
|
+
import static arjdbc.util.QuotingUtils.quoteCharAndDecorateWith;
|
41
|
+
|
38
42
|
public class MySQLModule {
|
39
|
-
|
43
|
+
|
44
|
+
public static RubyModule load(final RubyModule arJdbc) {
|
40
45
|
RubyModule mysql = arJdbc.defineModuleUnder("MySQL");
|
41
46
|
mysql.defineAnnotatedMethods(MySQLModule.class);
|
47
|
+
return mysql;
|
42
48
|
}
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
private final static byte[] ZERO = new byte[] {'\\','0'};
|
48
|
-
private final static byte[] NEWLINE = new byte[] {'\\','n'};
|
49
|
-
private final static byte[] CARRIAGE = new byte[] {'\\','r'};
|
50
|
-
private final static byte[] ZED = new byte[] {'\\','Z'};
|
51
|
-
private final static byte[] DBL = new byte[] {'\\','"'};
|
52
|
-
private final static byte[] SINGLE = new byte[] {'\\','\''};
|
53
|
-
private final static byte[] ESCAPE = new byte[] {'\\','\\'};
|
54
|
-
|
55
|
-
@JRubyMethod(name = "quote_string", required = 1, frame=false)
|
56
|
-
public static IRubyObject quote_string(ThreadContext context, IRubyObject recv, IRubyObject string) {
|
57
|
-
ByteList bytes = ((RubyString) string).getByteList();
|
58
|
-
ByteList newBytes = new ByteList();
|
59
|
-
|
60
|
-
newBytes.append(bytes);
|
61
|
-
|
62
|
-
for(int i = newBytes.begin; i < newBytes.begin + newBytes.realSize; i++) {
|
63
|
-
byte[] rep = null;
|
64
|
-
switch (newBytes.bytes[i]) {
|
65
|
-
case 0: rep = ZERO; break;
|
66
|
-
case '\n': rep = NEWLINE; break;
|
67
|
-
case '\r': rep = CARRIAGE; break;
|
68
|
-
case 26: rep = ZED; break;
|
69
|
-
case '"': rep = DBL; break;
|
70
|
-
case '\'': rep = SINGLE; break;
|
71
|
-
case '\\': rep = ESCAPE; break;
|
72
|
-
}
|
50
|
+
public static RubyModule load(final Ruby runtime) {
|
51
|
+
return load( arjdbc.ArJdbcModule.get(runtime) );
|
52
|
+
}
|
73
53
|
|
74
|
-
|
75
|
-
|
76
|
-
|
54
|
+
// ActiveRecord::ConnectionAdapters::MySQL::Quoting (almost all of)
|
55
|
+
// without the column/table name 'caches' replicated across threads
|
56
|
+
|
57
|
+
//private final static byte[] ZERO = new byte[] {'\\','0'};
|
58
|
+
//private final static byte[] NEWLINE = new byte[] {'\\','n'};
|
59
|
+
//private final static byte[] CARRIAGE = new byte[] {'\\','r'};
|
60
|
+
//private final static byte[] ZED = new byte[] {'\\','Z'};
|
61
|
+
//private final static byte[] DBL = new byte[] {'\\','"'};
|
62
|
+
//private final static byte[] SINGLE = new byte[] {'\\','\''};
|
63
|
+
//private final static byte[] ESCAPE = new byte[] {'\\','\\'};
|
64
|
+
|
65
|
+
private static final int STRING_QUOTES_OPTIMISTIC_QUESS = 24;
|
66
|
+
|
67
|
+
@JRubyMethod(name = "quote_string", required = 1)
|
68
|
+
public static IRubyObject quote_string(final ThreadContext context,
|
69
|
+
final IRubyObject recv, final IRubyObject string) {
|
70
|
+
|
71
|
+
final ByteList stringBytes = ((RubyString) string).getByteList();
|
72
|
+
final byte[] bytes = stringBytes.unsafeBytes();
|
73
|
+
final int begin = stringBytes.getBegin();
|
74
|
+
final int realSize = stringBytes.getRealSize();
|
75
|
+
|
76
|
+
ByteList quotedBytes = null; int appendFrom = begin;
|
77
|
+
for ( int i = begin; i < begin + realSize; i++ ) {
|
78
|
+
final byte byte2;
|
79
|
+
switch ( bytes[i] ) {
|
80
|
+
case 0 : byte2 = '0'; break;
|
81
|
+
case '\n' : byte2 = 'n'; break;
|
82
|
+
case '\r' : byte2 = 'r'; break;
|
83
|
+
case 26 : byte2 = 'Z'; break;
|
84
|
+
case '"' : byte2 = '"'; break;
|
85
|
+
case '\'' : byte2 = '\''; break;
|
86
|
+
case '\\' : byte2 = '\\'; break;
|
87
|
+
default : byte2 = 0;
|
77
88
|
}
|
89
|
+
if ( byte2 != 0 ) {
|
90
|
+
if ( quotedBytes == null ) {
|
91
|
+
quotedBytes = new ByteList(
|
92
|
+
new byte[realSize + STRING_QUOTES_OPTIMISTIC_QUESS],
|
93
|
+
stringBytes.getEncoding()
|
94
|
+
);
|
95
|
+
quotedBytes.setBegin(0);
|
96
|
+
quotedBytes.setRealSize(0);
|
97
|
+
} // copy string on-first quote we "optimize" for non-quoted
|
98
|
+
quotedBytes.append(bytes, appendFrom, i - appendFrom);
|
99
|
+
quotedBytes.append('\\').append(byte2);
|
100
|
+
appendFrom = i + 1;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
if ( quotedBytes != null ) { // append what's left in the end :
|
104
|
+
quotedBytes.append(bytes, appendFrom, begin + realSize - appendFrom);
|
78
105
|
}
|
106
|
+
else return string; // nothing changed, can return original
|
79
107
|
|
80
|
-
|
81
|
-
|
108
|
+
final Ruby runtime = context.runtime;
|
109
|
+
final RubyString quoted = runtime.newString(quotedBytes);
|
82
110
|
|
83
|
-
|
84
|
-
}
|
111
|
+
quoted.associateEncoding(UTF8Encoding.INSTANCE);
|
85
112
|
|
86
|
-
|
87
|
-
|
88
|
-
ByteList bytes = arg.asString().getByteList();
|
89
|
-
ByteList newBytes = new ByteList();
|
113
|
+
return quoted;
|
114
|
+
}
|
90
115
|
|
91
|
-
|
92
|
-
|
93
|
-
|
116
|
+
@JRubyMethod(name = "quoted_true")
|
117
|
+
public static IRubyObject quoted_true(
|
118
|
+
final ThreadContext context,
|
119
|
+
final IRubyObject self) {
|
120
|
+
return RubyString.newString(context.runtime, BYTES_1).freeze(context);
|
121
|
+
}
|
94
122
|
|
95
|
-
|
123
|
+
@JRubyMethod(name = "quoted_false")
|
124
|
+
public static IRubyObject quoted_false(
|
125
|
+
final ThreadContext context,
|
126
|
+
final IRubyObject self) {
|
127
|
+
return RubyString.newString(context.runtime, BYTES_0).freeze(context);
|
96
128
|
}
|
97
129
|
|
98
|
-
@JRubyMethod(name = "
|
99
|
-
public static IRubyObject
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
newBytes.append(bytes);
|
105
|
-
int i = 0, j = 0;
|
106
|
-
while ((i = newBytes.indexOf('.', j)) != -1) {
|
107
|
-
newBytes.replace(i, 1, QUOTED_DOT);
|
108
|
-
j = i+3;
|
109
|
-
}
|
110
|
-
newBytes.append(BACKQUOTE);
|
130
|
+
@JRubyMethod(name = "unquoted_true")
|
131
|
+
public static IRubyObject unquoted_true(
|
132
|
+
final ThreadContext context,
|
133
|
+
final IRubyObject self) {
|
134
|
+
return RubyFixnum.one(context.runtime);
|
135
|
+
}
|
111
136
|
|
112
|
-
|
137
|
+
@JRubyMethod(name = "unquoted_false")
|
138
|
+
public static IRubyObject unquoted_false(
|
139
|
+
final ThreadContext context,
|
140
|
+
final IRubyObject self) {
|
141
|
+
return RubyFixnum.zero(context.runtime);
|
113
142
|
}
|
114
143
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
public static IRubyObject kill_cancel_timer(ThreadContext context, IRubyObject recv, IRubyObject raw_connection) {
|
122
|
-
Connection conn = (Connection) raw_connection.dataGetStruct();
|
123
|
-
if (conn != null && conn.getClass().getClassLoader() == recv.getRuntime().getJRubyClassLoader()) {
|
124
|
-
try {
|
125
|
-
java.lang.reflect.Field f = conn.getClass().getDeclaredField("cancelTimer");
|
126
|
-
f.setAccessible(true);
|
127
|
-
java.util.Timer timer = (java.util.Timer) f.get(null);
|
128
|
-
timer.cancel();
|
129
|
-
} catch (Exception e) {
|
130
|
-
}
|
131
|
-
}
|
132
|
-
return recv.getRuntime().getNil();
|
144
|
+
@JRubyMethod(name = "quote_column_name", required = 1)
|
145
|
+
public static IRubyObject quote_column_name(
|
146
|
+
final ThreadContext context,
|
147
|
+
final IRubyObject self,
|
148
|
+
final IRubyObject string) { // "`#{name.to_s.gsub('`', '``')}`"
|
149
|
+
return quoteCharAndDecorateWith(context, string.asString(), '`', '`', (byte) '`', (byte) '`');
|
133
150
|
}
|
151
|
+
|
134
152
|
}
|