activerecord-jdbc-adapter 0.9.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +163 -0
- data/Manifest.txt +130 -65
- data/README.txt +64 -72
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -633
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
- data/lib/activerecord-jdbc-adapter.rb +6 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/db2.rb +15 -0
- data/lib/arel/visitors/derby.rb +19 -0
- data/lib/arel/visitors/hsqldb.rb +24 -0
- data/lib/arel/visitors/mssql.rb +44 -0
- data/lib/arjdbc.rb +29 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +413 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +58 -132
- data/lib/arjdbc/derby/connection_methods.rb +18 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +36 -14
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +36 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +34 -62
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +10 -19
- data/lib/arjdbc/informix/connection_methods.rb +10 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +285 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +38 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +128 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +36 -26
- data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +17 -16
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +472 -0
- data/lib/arjdbc/mssql/connection_methods.rb +30 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
- data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +2 -1
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +416 -0
- data/lib/arjdbc/mysql/connection_methods.rb +27 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +68 -33
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +147 -72
- data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +381 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -27
- data/lib/jdbc_adapter/rake_tasks.rb +3 -10
- data/lib/jdbc_adapter/version.rb +3 -5
- data/lib/pg.rb +23 -1
- data/rails_generators/jdbc_generator.rb +2 -2
- data/rails_generators/templates/{jdbc.rb → config/initializers/jdbc.rb} +1 -1
- data/rails_generators/templates/{jdbc.rake → lib/tasks/jdbc.rake} +2 -2
- data/rakelib/compile.rake +5 -3
- data/rakelib/db.rake +19 -0
- data/rakelib/package.rake +12 -6
- data/rakelib/test.rake +24 -14
- data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +63 -34
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/{jdbc_adapter/MssqlRubyJdbcConnection.java → arjdbc/informix/InformixRubyJdbcConnection.java} +15 -12
- data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +21 -8
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +210 -67
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/test/abstract_db_create.rb +98 -19
- data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
- data/test/db/db2.rb +4 -2
- data/test/db/derby.rb +12 -14
- data/test/db/hsqldb.rb +3 -2
- data/test/db/jndi_config.rb +22 -12
- data/test/db/mssql.rb +5 -5
- data/test/db/sqlite3.rb +2 -6
- data/test/db2_simple_test.rb +56 -0
- data/test/derby_migration_test.rb +50 -3
- data/test/derby_simple_test.rb +87 -0
- data/test/generic_jdbc_connection_test.rb +21 -1
- data/test/h2_simple_test.rb +35 -0
- data/test/jdbc_common.rb +4 -5
- data/test/jndi_callbacks_test.rb +3 -1
- data/test/jndi_test.rb +1 -11
- data/test/models/entry.rb +20 -0
- data/test/models/mixed_case.rb +7 -2
- data/test/models/string_id.rb +18 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_simple_test.rb +49 -0
- data/test/mysql_db_create_test.rb +8 -6
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_simple_test.rb +19 -1
- data/test/oracle_simple_test.rb +9 -20
- data/test/oracle_specific_test.rb +83 -0
- data/test/pick_rails_version.rb +3 -0
- data/test/postgres_db_create_test.rb +11 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_mixed_case_test.rb +11 -1
- data/test/postgres_nonseq_pkey_test.rb +0 -2
- data/test/postgres_schema_search_path_test.rb +44 -0
- data/test/postgres_simple_test.rb +53 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/simple.rb +103 -9
- data/test/sqlite3_simple_test.rb +1 -0
- data/test/sybase_jtds_simple_test.rb +22 -0
- metadata +239 -137
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
- data/lib/jdbc_adapter/jdbc_db2.rb +0 -191
- data/lib/jdbc_adapter/jdbc_mssql.rb +0 -333
- data/lib/jdbc_adapter/jdbc_mysql.rb +0 -236
- data/lib/jdbc_adapter/jdbc_sqlite3.rb +0 -379
- data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
- data/src/java/jdbc_adapter/SQLBlock.java +0 -27
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
- data/test/cachedb_simple_test.rb +0 -6
- data/test/db/cachedb.rb +0 -9
- data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
- data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
- data/test/minirunit.rb +0 -109
- data/test/minirunit/testConnect.rb +0 -14
- data/test/minirunit/testH2.rb +0 -73
- data/test/minirunit/testHsqldb.rb +0 -73
- data/test/minirunit/testLoadActiveRecord.rb +0 -3
- data/test/minirunit/testMysql.rb +0 -83
- data/test/minirunit/testRawSelect.rb +0 -24
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
**** BEGIN LICENSE BLOCK *****
|
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 arjdbc.jdbc.RubyJdbcConnection;
|
30
|
+
|
31
|
+
import org.jruby.Ruby;
|
32
|
+
import org.jruby.RubyClass;
|
33
|
+
import org.jruby.runtime.ObjectAllocator;
|
34
|
+
import org.jruby.runtime.ThreadContext;
|
35
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
36
|
+
|
37
|
+
/**
|
38
|
+
*
|
39
|
+
* @author enebo
|
40
|
+
*/
|
41
|
+
public class Sqlite3RubyJdbcConnection extends RubyJdbcConnection {
|
42
|
+
protected Sqlite3RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
43
|
+
super(runtime, metaClass);
|
44
|
+
}
|
45
|
+
|
46
|
+
public static RubyClass createSqlite3JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
47
|
+
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("Sqlite3JdbcConnection",
|
48
|
+
jdbcConnection, SQLITE3_JDBCCONNECTION_ALLOCATOR);
|
49
|
+
clazz.defineAnnotatedMethods(Sqlite3RubyJdbcConnection.class);
|
50
|
+
|
51
|
+
return clazz;
|
52
|
+
}
|
53
|
+
|
54
|
+
private static ObjectAllocator SQLITE3_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
55
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
56
|
+
return new Sqlite3RubyJdbcConnection(runtime, klass);
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
@Override
|
61
|
+
protected IRubyObject tables(ThreadContext context, String catalog, String schemaPattern, String tablePattern, String[] types) {
|
62
|
+
return (IRubyObject) withConnectionAndRetry(context, tableLookupBlock(context.getRuntime(), catalog, schemaPattern, tablePattern, types, true));
|
63
|
+
}
|
64
|
+
}
|
data/test/abstract_db_create.rb
CHANGED
@@ -1,45 +1,124 @@
|
|
1
1
|
require 'jdbc_common'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
+
module Rails
|
5
|
+
class Configuration
|
6
|
+
end
|
7
|
+
class Application
|
8
|
+
def self.config
|
9
|
+
@config ||= Object.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
def self.application
|
13
|
+
Rails::Application
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
module AbstractDbCreate
|
5
18
|
def setup
|
6
19
|
@prevapp = Rake.application
|
7
20
|
Rake.application = Rake::Application.new
|
8
21
|
verbose(true)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
22
|
+
do_setup
|
23
|
+
end
|
24
|
+
|
25
|
+
def do_setup(env = 'unittest', db = 'test_rake_db_create')
|
26
|
+
@env = env
|
13
27
|
@prevconfigs = ActiveRecord::Base.configurations
|
14
28
|
ActiveRecord::Base.connection.disconnect!
|
15
|
-
@db_name =
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
@db_name = db
|
30
|
+
setup_rails
|
31
|
+
set_rails_constant("env", @env)
|
32
|
+
set_rails_constant("root", ".")
|
33
|
+
load File.dirname(__FILE__) + '/../lib/arjdbc/jdbc/jdbc.rake' if jruby?
|
34
|
+
task :environment do
|
35
|
+
ActiveRecord::Base.configurations = configurations
|
36
|
+
@full_env_loaded = true
|
37
|
+
end
|
38
|
+
task :rails_env do
|
39
|
+
@rails_env_set = true
|
23
40
|
end
|
24
|
-
load rails_databases_rake_file
|
25
|
-
load File.dirname(__FILE__) + '/../lib/jdbc_adapter/jdbc.rake' if jruby?
|
26
|
-
task :environment; task :rails_env # dummy environment, rails_env tasks
|
27
41
|
end
|
28
42
|
|
29
43
|
def teardown
|
30
44
|
Rake::Task["db:drop"].invoke
|
31
45
|
Rake.application = @prevapp
|
32
|
-
|
33
|
-
Object.const_set("RAILS_ROOT", @prevroot) if @prevroot
|
46
|
+
restore_rails
|
34
47
|
ActiveRecord::Base.configurations = @prevconfigs
|
35
48
|
ActiveRecord::Base.establish_connection(db_config)
|
49
|
+
@rails_env_set = nil
|
50
|
+
@full_env_loaded = nil
|
36
51
|
end
|
37
52
|
|
38
|
-
def
|
53
|
+
def setup_rails
|
54
|
+
if ActiveRecord::VERSION::MAJOR == 3
|
55
|
+
setup_rails3
|
56
|
+
else
|
57
|
+
setup_rails2
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def configurations
|
62
|
+
the_db_name = @db_name
|
63
|
+
the_db_config = db_config
|
64
|
+
the_db_config = the_db_config.merge({:database => the_db_name}) if the_db_name
|
65
|
+
the_db_config.stringify_keys!
|
66
|
+
@configs = { @env => the_db_config }
|
67
|
+
@configs["test"] = @configs[@env].dup
|
68
|
+
@configs
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup_rails2
|
72
|
+
configs = configurations
|
73
|
+
Rails::Configuration.class_eval do
|
74
|
+
define_method(:database_configuration) { configs }
|
75
|
+
end
|
39
76
|
ar_version = $LOADED_FEATURES.grep(%r{active_record/version}).first
|
40
77
|
ar_lib_path = $LOAD_PATH.detect {|p| p if File.exist?File.join(p, ar_version)}
|
41
78
|
ar_lib_path = ar_lib_path.sub(%r{activerecord/lib}, 'railties/lib') # edge rails
|
42
79
|
rails_lib_path = ar_lib_path.sub(/activerecord/, 'rails') # gem rails
|
43
|
-
"#{rails_lib_path}/tasks/databases.rake"
|
80
|
+
load "#{rails_lib_path}/tasks/databases.rake"
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup_rails3
|
84
|
+
configs = configurations
|
85
|
+
(class << Rails::Application.config; self ; end).instance_eval do
|
86
|
+
define_method(:database_configuration) { configs }
|
87
|
+
end
|
88
|
+
ar_version = $LOADED_FEATURES.grep(%r{active_record/version}).first
|
89
|
+
ar_lib_path = $LOAD_PATH.detect {|p| p if File.exist?File.join(p, ar_version)}
|
90
|
+
load "#{ar_lib_path}/active_record/railties/databases.rake"
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_rails_constant(name, value)
|
94
|
+
cname ="RAILS_#{name.upcase}"
|
95
|
+
@constants ||= {}
|
96
|
+
@constants[name] = Object.const_get(cname) rescue nil
|
97
|
+
silence_warnings { Object.const_set(cname, value) }
|
98
|
+
Rails.instance_eval do
|
99
|
+
if instance_methods(false).include?(name)
|
100
|
+
alias_method "orig_#{name}", name
|
101
|
+
define_method(name) { value }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def restore_rails
|
107
|
+
@constants.each do |key,value|
|
108
|
+
silence_warnings { Object.const_set("RAILS_#{key.upcase}", value) }
|
109
|
+
Rails.instance_eval do
|
110
|
+
if instance_methods(false).include?(name)
|
111
|
+
remove_method name
|
112
|
+
alias_method name, "orig_#{name}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def silence_warnings
|
119
|
+
prev, $VERBOSE = $VERBOSE, nil
|
120
|
+
yield
|
121
|
+
ensure
|
122
|
+
$VERBOSE = prev
|
44
123
|
end
|
45
124
|
end
|
data/test/db/db2.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
config = {
|
2
|
-
|
3
|
-
|
2
|
+
# DB2 uses $USER if running locally, just add
|
3
|
+
# yourself to your db2 groups in /etc/group
|
4
|
+
# :username => "blog",
|
5
|
+
# :password => "",
|
4
6
|
:adapter => "jdbc",
|
5
7
|
:driver => "com.ibm.db2.jcc.DB2Driver",
|
6
8
|
:url => "jdbc:db2:weblog_development"
|
data/test/db/derby.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
FileUtils.rm_rf('derby-testdb')
|
14
|
-
}
|
1
|
+
config = {
|
2
|
+
:adapter => 'derby',
|
3
|
+
:database => "derby-testdb"
|
4
|
+
}
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection(config)
|
7
|
+
|
8
|
+
at_exit {
|
9
|
+
# Clean up derby files
|
10
|
+
require 'fileutils'
|
11
|
+
FileUtils.rm_rf('derby-testdb')
|
12
|
+
}
|
data/test/db/hsqldb.rb
CHANGED
@@ -7,6 +7,7 @@ ActiveRecord::Base.establish_connection(config)
|
|
7
7
|
|
8
8
|
at_exit {
|
9
9
|
# Clean up hsqldb when done
|
10
|
-
|
11
|
-
|
10
|
+
require "fileutils"
|
11
|
+
Dir['test.db*'].each {|f| FileUtils.rm_rf(f)}
|
12
|
+
FileUtils.rm_rf('hsqldb-testdb.log') rescue nil #can't delete on windows
|
12
13
|
}
|
data/test/db/jndi_config.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require '
|
2
|
+
require 'arjdbc'
|
3
|
+
|
4
|
+
JNDI_CONFIG = {
|
5
|
+
:adapter => "jdbc",
|
6
|
+
:jndi => 'jdbc/derbydb'
|
7
|
+
}
|
8
|
+
|
9
|
+
# To test JNDI, grab fscontext-1_2-beta3.zip from
|
10
|
+
# http://java.sun.com/products/jndi/downloads/index.html
|
11
|
+
# and put fscontext.jar and providerutil.jar in test/
|
12
|
+
require 'test/fscontext.jar'
|
13
|
+
require 'test/providerutil.jar'
|
14
|
+
require 'jdbc/derby'
|
3
15
|
|
4
16
|
System = java.lang.System
|
5
17
|
Context = javax.naming.Context
|
6
18
|
InitialContext = javax.naming.InitialContext
|
7
19
|
Reference = javax.naming.Reference
|
8
20
|
StringRefAddr = javax.naming.StringRefAddr
|
9
|
-
|
21
|
+
|
10
22
|
System.set_property(Context::INITIAL_CONTEXT_FACTORY,
|
11
23
|
'com.sun.jndi.fscontext.RefFSContextFactory')
|
12
24
|
project_path = File.expand_path(File.dirname(__FILE__) + '/../..')
|
@@ -15,16 +27,14 @@ jdbc_dir = jndi_dir + '/jdbc'
|
|
15
27
|
FileUtils.mkdir_p jdbc_dir unless File.exist?(jdbc_dir)
|
16
28
|
|
17
29
|
System.set_property(Context::PROVIDER_URL, "file://#{jndi_dir}")
|
18
|
-
derby_ref = Reference.new('javax.sql.DataSource',
|
19
|
-
'org.apache.commons.dbcp.BasicDataSourceFactory',
|
20
|
-
nil)
|
21
|
-
derby_ref.add StringRefAddr.new('driverClassName',
|
22
|
-
'org.apache.derby.jdbc.EmbeddedDriver')
|
23
|
-
derby_ref.add StringRefAddr.new('url',
|
24
|
-
'jdbc:derby:derby-testdb;create=true')
|
25
|
-
derby_ref.add StringRefAddr.new('username', 'sa')
|
26
|
-
derby_ref.add StringRefAddr.new('password', '')
|
27
30
|
|
28
31
|
ic = InitialContext.new
|
29
|
-
ic.rebind(
|
32
|
+
ic.rebind(JNDI_CONFIG[:jndi],
|
33
|
+
org.apache.derby.jdbc.EmbeddedDataSource.new.tap {|ds|
|
34
|
+
ds.database_name = "derby-testdb-jndi"
|
35
|
+
ds.create_database = "create"
|
36
|
+
ds.user = "sa"
|
37
|
+
ds.password = ""})
|
38
|
+
|
30
39
|
|
40
|
+
ActiveRecord::Base.establish_connection(JNDI_CONFIG)
|
data/test/db/mssql.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
MSSQL_CONFIG = {
|
2
2
|
:username => 'blog',
|
3
3
|
:password => '',
|
4
|
-
:adapter => '
|
5
|
-
:
|
6
|
-
:driver => 'net.sourceforge.jtds.jdbc.Driver'
|
4
|
+
:adapter => 'mssql',
|
5
|
+
:database => 'weblog_development'
|
7
6
|
}
|
7
|
+
MSSQL_CONFIG[:host] = ENV['SQLHOST'] if ENV['SQLHOST']
|
8
8
|
|
9
|
-
ActiveRecord::Base.establish_connection(
|
9
|
+
ActiveRecord::Base.establish_connection(MSSQL_CONFIG)
|
data/test/db/sqlite3.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require 'jdbc/sqlite3' if jruby?
|
2
|
-
|
3
1
|
config = {
|
4
|
-
:adapter =>
|
5
|
-
:
|
6
|
-
# :url => 'jdbc:sqlite:test.sqlite3.db',
|
7
|
-
# :driver => 'org.sqlite.JDBC'
|
2
|
+
:adapter => 'sqlite3',
|
3
|
+
:database => 'test.sqlite3.db'
|
8
4
|
}
|
9
5
|
|
10
6
|
ActiveRecord::Base.establish_connection(config)
|
data/test/db2_simple_test.rb
CHANGED
@@ -3,8 +3,64 @@ require 'db/db2'
|
|
3
3
|
|
4
4
|
class DB2SimpleTest < Test::Unit::TestCase
|
5
5
|
include SimpleTestMethods
|
6
|
+
|
7
|
+
# For backwards compatibility with how the DB2 code in
|
8
|
+
# jdbc_adapter 0.9.x handled booleans.
|
9
|
+
#
|
10
|
+
# The old DB2 jdbc_db2.rb driver was broken enough that
|
11
|
+
# applications were exposed to the underlying type (was DECIMAL)
|
12
|
+
# and used 0 and 1 as false and true, respectively.
|
13
|
+
#
|
14
|
+
# This driver now uses SMALLINT as a boolean, and properly
|
15
|
+
# type cast's it to a Ruby boolean. Need to make sure we don't
|
16
|
+
# break existing apps!
|
17
|
+
def test_boolean_as_integer
|
18
|
+
e = DbType.find(:first)
|
19
|
+
|
20
|
+
# true
|
21
|
+
e.sample_boolean = 1
|
22
|
+
assert_equal true, e.sample_boolean
|
23
|
+
assert_equal true, e.sample_boolean?
|
24
|
+
e.save!
|
25
|
+
|
26
|
+
e = DbType.find(:first)
|
27
|
+
assert_equal true, e.sample_boolean
|
28
|
+
assert_equal true, e.sample_boolean?
|
29
|
+
|
30
|
+
# false
|
31
|
+
e.sample_boolean = 0
|
32
|
+
assert_equal false, e.sample_boolean
|
33
|
+
assert_equal false, e.sample_boolean?
|
34
|
+
e.save!
|
35
|
+
|
36
|
+
e = DbType.find(:first)
|
37
|
+
assert_equal false, e.sample_boolean
|
38
|
+
assert_equal false, e.sample_boolean?
|
39
|
+
end
|
6
40
|
end
|
7
41
|
|
8
42
|
class DB2HasManyThroughTest < Test::Unit::TestCase
|
9
43
|
include HasManyThroughMethods
|
10
44
|
end
|
45
|
+
|
46
|
+
class DB2Test < Test::Unit::TestCase
|
47
|
+
def setup
|
48
|
+
@inst = Object.new
|
49
|
+
@inst.extend ArJdbc::DB2
|
50
|
+
@column = Object.new
|
51
|
+
class << @column
|
52
|
+
attr_accessor :type
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_quote_decimal
|
57
|
+
assert_equal %q{'123.45'}, @inst.quote("123.45")
|
58
|
+
@column.type = :decimal
|
59
|
+
assert_equal %q{123.45}, @inst.quote("123.45", @column), "decimal columns should not have quotes"
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_primary_key_generation
|
63
|
+
@column.type = :primary_key
|
64
|
+
assert_equal 'int not null generated by default as identity (start with 1) primary key', @inst.modify_types({:string => {}, :integer => {}, :boolean => {}})[:primary_key]
|
65
|
+
end
|
66
|
+
end
|
@@ -8,14 +8,61 @@ class CreateDummies < ActiveRecord::Migration
|
|
8
8
|
end
|
9
9
|
add_index :dummies, :year, :unique => true
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class ChangeColumn < ActiveRecord::Migration
|
15
|
+
def self.up
|
16
|
+
create_table :people, :id => false, :force => true do |t|
|
17
|
+
t.string :id, :limit => 22, :null => false
|
18
|
+
t.string :name, :null => false
|
19
|
+
end
|
20
|
+
change_column(:people, :name, :string, {:limit=>22})
|
21
|
+
execute("SELECT id FROM people WHERE id = 'some string'")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.down
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class CreateIndex < ActiveRecord::Migration
|
30
|
+
def self.up
|
31
|
+
create_table :people, :id => false, :force => true do |t|
|
32
|
+
t.string :id, :limit => 22, :null => false
|
33
|
+
t.string :first_name, :null => false
|
34
|
+
t.string :last_name, :null => false
|
35
|
+
t.string :nickname, :null => false
|
36
|
+
t.string :long_name, :null => false
|
37
|
+
t.string :very_long_name, :null => false
|
38
|
+
t.string :extremely_long_name, :null => false
|
39
|
+
end
|
40
|
+
|
41
|
+
add_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name], :unique => true)
|
42
|
+
|
43
|
+
remove_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name])
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.down
|
47
|
+
end
|
48
|
+
|
12
49
|
end
|
13
50
|
|
14
|
-
class
|
51
|
+
class DerbyMigrationTest < Test::Unit::TestCase
|
15
52
|
include FixtureSetup
|
16
53
|
|
17
54
|
def test_create_table_column_quoting_vs_keywords
|
18
55
|
CreateDummies.up
|
19
56
|
end
|
20
|
-
|
57
|
+
|
58
|
+
def test_migrate_change_column_for_non_standard_id
|
59
|
+
ChangeColumn.up
|
60
|
+
ChangeColumn.down
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_migrate_create_index
|
64
|
+
CreateIndex.up
|
65
|
+
CreateIndex.down
|
66
|
+
end
|
67
|
+
|
21
68
|
end
|