activerecord-jdbc-adapter 1.2.2.1 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -2
- data/.travis.yml +18 -3
- data/Appraisals +16 -0
- data/Gemfile +10 -10
- data/Gemfile.lock +27 -17
- data/LICENSE.txt +20 -17
- data/README.rdoc +29 -14
- data/Rakefile +4 -4
- data/activerecord-jdbc-adapter.gemspec +2 -1
- data/gemfiles/rails23.gemfile +12 -0
- data/gemfiles/rails23.gemfile.lock +44 -0
- data/gemfiles/rails30.gemfile +11 -0
- data/gemfiles/rails30.gemfile.lock +39 -0
- data/gemfiles/rails31.gemfile +11 -0
- data/gemfiles/rails31.gemfile.lock +41 -0
- data/gemfiles/rails32.gemfile +11 -0
- data/gemfiles/rails32.gemfile.lock +41 -0
- data/lib/arel/visitors/sql_server.rb +7 -0
- data/lib/arjdbc/db2/adapter.rb +82 -32
- data/lib/arjdbc/derby.rb +0 -4
- data/lib/arjdbc/derby/adapter.rb +1 -1
- data/lib/arjdbc/derby/connection_methods.rb +3 -2
- data/lib/arjdbc/discover.rb +16 -1
- data/lib/arjdbc/firebird/adapter.rb +5 -1
- data/lib/arjdbc/h2.rb +0 -1
- data/lib/arjdbc/h2/connection_methods.rb +3 -1
- data/lib/arjdbc/hsqldb.rb +0 -1
- data/lib/arjdbc/hsqldb/adapter.rb +4 -3
- data/lib/arjdbc/hsqldb/connection_methods.rb +3 -3
- data/lib/arjdbc/informix/adapter.rb +5 -1
- data/lib/arjdbc/jdbc/adapter.rb +22 -24
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +1 -1
- data/lib/arjdbc/jdbc/connection.rb +23 -29
- data/lib/arjdbc/jdbc/core_ext.rb +1 -1
- data/lib/arjdbc/jdbc/discover.rb +1 -1
- data/lib/arjdbc/jdbc/driver.rb +1 -1
- data/lib/arjdbc/jdbc/extension.rb +3 -3
- data/lib/arjdbc/jdbc/jdbc.rake +15 -5
- data/lib/arjdbc/mssql.rb +0 -1
- data/lib/arjdbc/mssql/adapter.rb +10 -4
- data/lib/arjdbc/mssql/connection_methods.rb +15 -15
- data/lib/arjdbc/mssql/limit_helpers.rb +24 -2
- data/lib/arjdbc/mssql/tsql_helper.rb +0 -8
- data/lib/arjdbc/mysql.rb +0 -1
- data/lib/arjdbc/mysql/adapter.rb +82 -0
- data/lib/arjdbc/mysql/connection_methods.rb +3 -4
- data/lib/arjdbc/oracle/adapter.rb +12 -2
- data/lib/arjdbc/postgresql.rb +0 -1
- data/lib/arjdbc/postgresql/adapter.rb +127 -27
- data/lib/arjdbc/postgresql/connection_methods.rb +3 -4
- data/lib/arjdbc/sqlite3.rb +0 -1
- data/lib/arjdbc/sqlite3/adapter.rb +13 -14
- data/lib/arjdbc/sqlite3/connection_methods.rb +3 -4
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/01-tomcat.rake +52 -0
- data/rakelib/02-test.rake +111 -0
- data/rakelib/db.rake +4 -3
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +7 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +8 -3
- data/test/abstract_db_create.rb +5 -1
- data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -1
- data/test/activerecord/jall.sh +0 -0
- data/test/activerecord/jtest.sh +0 -0
- data/test/db/db2.rb +2 -0
- data/test/db/derby.rb +3 -5
- data/test/db/h2.rb +3 -1
- data/test/db/hsqldb.rb +2 -0
- data/test/db/informix.rb +2 -0
- data/test/db/jdbc.rb +11 -10
- data/test/db/jdbc_derby.rb +14 -0
- data/test/db/jdbc_h2.rb +17 -0
- data/test/db/jdbc_mysql.rb +13 -0
- data/test/db/jdbc_postgres.rb +23 -0
- data/test/db/jndi_config.rb +28 -33
- data/test/db/jndi_pooled_config.rb +35 -0
- data/test/db/logger.rb +1 -1
- data/test/db/mssql.rb +2 -0
- data/test/db/mysql.rb +2 -7
- data/test/db/mysql_config.rb +7 -0
- data/test/db/oracle.rb +2 -0
- data/test/db/postgres.rb +9 -7
- data/test/db/postgres_config.rb +10 -0
- data/test/db/sqlite3.rb +2 -0
- data/test/db2_reset_column_information_test.rb +0 -2
- data/test/derby_migration_test.rb +0 -1
- data/test/derby_multibyte_test.rb +0 -1
- data/test/derby_reset_column_information_test.rb +0 -3
- data/test/derby_row_locking_test.rb +0 -3
- data/test/derby_simple_test.rb +0 -1
- data/test/generic_jdbc_connection_test.rb +72 -17
- data/test/h2_change_column_test.rb +0 -1
- data/test/h2_simple_test.rb +0 -1
- data/test/helper.rb +22 -91
- data/test/jdbc_common.rb +98 -3
- data/test/jndi_callbacks_test.rb +6 -5
- data/test/jndi_test.rb +40 -15
- data/test/models/custom_pk_name.rb +14 -0
- data/test/mssql_ignore_system_views_test.rb +7 -4
- data/test/mssql_limit_offset_test.rb +30 -0
- data/test/mssql_multibyte_test.rb +1 -2
- data/test/mssql_reset_column_information_test.rb +0 -2
- data/test/mssql_row_locking_sql_test.rb +0 -2
- data/test/mssql_row_locking_test.rb +0 -2
- data/test/mysql_reset_column_information_test.rb +0 -2
- data/test/mysql_simple_test.rb +3 -18
- data/test/oracle_limit_test.rb +23 -0
- data/test/oracle_reset_column_information_test.rb +0 -2
- data/test/postgres_db_create_test.rb +0 -1
- data/test/postgres_drop_db_test.rb +0 -1
- data/test/postgres_information_schema_leak_test.rb +0 -1
- data/test/postgres_native_type_mapping_test.rb +17 -14
- data/test/postgres_nonseq_pkey_test.rb +0 -1
- data/test/postgres_reserved_test.rb +1 -2
- data/test/postgres_reset_column_information_test.rb +0 -3
- data/test/postgres_schema_search_path_test.rb +0 -1
- data/test/postgres_simple_test.rb +40 -1
- data/test/postgres_table_alias_length_test.rb +0 -1
- data/test/postgres_type_conversion_test.rb +0 -1
- data/test/row_locking.rb +6 -2
- data/test/simple.rb +57 -20
- data/test/sqlite3_reset_column_information_test.rb +0 -2
- data/test/sqlite3_simple_test.rb +1 -16
- data/test/sybase_reset_column_information_test.rb +0 -2
- metadata +366 -343
- data/lib/arjdbc/jdbc/require_driver.rb +0 -16
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
|
3
|
+
config = {
|
4
|
+
:adapter => 'jdbc',
|
5
|
+
:url => 'jdbc:derby:memory:derby-testdb;create=true',
|
6
|
+
:driver => 'org.apache.derby.jdbc.EmbeddedDriver',
|
7
|
+
:username => 'arjdbc',
|
8
|
+
:password => 'arjdbc'
|
9
|
+
}
|
10
|
+
|
11
|
+
require 'jdbc/derby' # driver not loaded for plain JDBC
|
12
|
+
Jdbc::Derby.load_driver(:require)
|
13
|
+
|
14
|
+
ActiveRecord::Base.establish_connection(config)
|
data/test/db/jdbc_h2.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
|
3
|
+
config = {
|
4
|
+
:adapter => 'jdbc',
|
5
|
+
:driver => 'org.h2.Driver',
|
6
|
+
:url => 'jdbc:h2:test.db'
|
7
|
+
}
|
8
|
+
|
9
|
+
require 'jdbc/h2' # driver not loaded for plain JDBC
|
10
|
+
Jdbc::H2.load_driver(:require)
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection(config)
|
13
|
+
|
14
|
+
at_exit {
|
15
|
+
# Clean up hsqldb when done
|
16
|
+
Dir['test.db*'].each { |f| FileUtils.rm_rf(f) }
|
17
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/mysql_config'
|
3
|
+
|
4
|
+
require 'jdbc/mysql' # driver not loaded for plain JDBC
|
5
|
+
Jdbc::MySQL.load_driver
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection({
|
8
|
+
:adapter => 'jdbc',
|
9
|
+
:driver => 'com.mysql.jdbc.Driver',
|
10
|
+
:url => "jdbc:mysql://#{MYSQL_CONFIG[:host]}/#{MYSQL_CONFIG[:database]}",
|
11
|
+
:username => MYSQL_CONFIG[:username],
|
12
|
+
:password => MYSQL_CONFIG[:password],
|
13
|
+
})
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres_config'
|
3
|
+
|
4
|
+
require 'jdbc/postgres' # driver not loaded for plain JDBC
|
5
|
+
Jdbc::Postgres::load_driver
|
6
|
+
|
7
|
+
url = POSTGRES_CONFIG[:host].dup
|
8
|
+
url << ":#{POSTGRES_CONFIG[:port]}" if POSTGRES_CONFIG[:port]
|
9
|
+
|
10
|
+
ActiveRecord::Base.establish_connection({
|
11
|
+
:adapter => 'jdbc',
|
12
|
+
:driver => 'org.postgresql.Driver',
|
13
|
+
:url => "jdbc:postgresql://#{url}/#{POSTGRES_CONFIG[:database]}",
|
14
|
+
:username => POSTGRES_CONFIG[:username],
|
15
|
+
:password => POSTGRES_CONFIG[:password],
|
16
|
+
})
|
17
|
+
|
18
|
+
begin
|
19
|
+
result = ActiveRecord::Base.connection.execute("SHOW server_version_num")
|
20
|
+
PG_VERSION = result.first.first[1].to_i
|
21
|
+
rescue
|
22
|
+
PG_VERSION = 0
|
23
|
+
end
|
data/test/db/jndi_config.rb
CHANGED
@@ -1,40 +1,35 @@
|
|
1
|
-
require 'fileutils'
|
2
1
|
require 'arjdbc'
|
2
|
+
require 'jdbc_common'
|
3
3
|
|
4
4
|
JNDI_CONFIG = {
|
5
|
-
:adapter =>
|
6
|
-
:jndi => 'jdbc/derbydb'
|
5
|
+
:adapter => 'jdbc', :jndi => 'jdbc/DerbyDB'
|
7
6
|
}
|
8
7
|
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
require 'test/fscontext.jar'
|
13
|
-
require 'test/providerutil.jar'
|
14
|
-
require 'jdbc/derby'
|
15
|
-
|
16
|
-
System = java.lang.System
|
17
|
-
Context = javax.naming.Context
|
18
|
-
InitialContext = javax.naming.InitialContext
|
19
|
-
Reference = javax.naming.Reference
|
20
|
-
StringRefAddr = javax.naming.StringRefAddr
|
21
|
-
|
22
|
-
System.set_property(Context::INITIAL_CONTEXT_FACTORY,
|
23
|
-
'com.sun.jndi.fscontext.RefFSContextFactory')
|
24
|
-
project_path = File.expand_path(File.dirname(__FILE__) + '/../..')
|
25
|
-
jndi_dir = project_path + '/jndi_test'
|
26
|
-
jdbc_dir = jndi_dir + '/jdbc'
|
27
|
-
FileUtils.mkdir_p jdbc_dir unless File.exist?(jdbc_dir)
|
8
|
+
# FS based JNDI impl borrowed from tomcat :
|
9
|
+
load 'test/jars/tomcat-juli.jar'
|
10
|
+
load 'test/jars/tomcat-catalina.jar'
|
28
11
|
|
29
|
-
System.set_property(
|
12
|
+
java.lang.System.set_property(
|
13
|
+
javax.naming.Context::INITIAL_CONTEXT_FACTORY,
|
14
|
+
'org.apache.naming.java.javaURLContextFactory'
|
15
|
+
)
|
16
|
+
java.lang.System.set_property(
|
17
|
+
javax.naming.Context::URL_PKG_PREFIXES,
|
18
|
+
'org.apache.naming'
|
19
|
+
)
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
21
|
+
require 'jdbc/derby'
|
22
|
+
Jdbc::Derby.load_driver
|
23
|
+
|
24
|
+
data_source = org.apache.derby.jdbc.EmbeddedDataSource.new
|
25
|
+
data_source.database_name = "memory:DerbyDB-JNDI"
|
26
|
+
data_source.create_database = "create"
|
27
|
+
data_source.user = "sa"
|
28
|
+
data_source.password = ""
|
29
|
+
|
30
|
+
init_context = javax.naming.InitialContext.new
|
31
|
+
begin
|
32
|
+
init_context.create_subcontext 'jdbc'
|
33
|
+
rescue javax.naming.NameAlreadyBoundException
|
34
|
+
end
|
35
|
+
init_context.bind JNDI_CONFIG[:jndi], data_source
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'arjdbc'
|
2
|
+
require 'jdbc_common'
|
3
|
+
|
4
|
+
JNDI_POOLED_CONFIG = {
|
5
|
+
:adapter => 'jdbc', :jndi => 'jdbc/PooledDerbyDB'
|
6
|
+
}
|
7
|
+
|
8
|
+
# FS based JNDI impl borrowed from tomcat :
|
9
|
+
load 'test/jars/tomcat-juli.jar'
|
10
|
+
load 'test/jars/tomcat-catalina.jar'
|
11
|
+
|
12
|
+
java.lang.System.set_property(
|
13
|
+
javax.naming.Context::INITIAL_CONTEXT_FACTORY,
|
14
|
+
'org.apache.naming.java.javaURLContextFactory'
|
15
|
+
)
|
16
|
+
java.lang.System.set_property(
|
17
|
+
javax.naming.Context::URL_PKG_PREFIXES,
|
18
|
+
'org.apache.naming'
|
19
|
+
)
|
20
|
+
|
21
|
+
require 'jdbc/derby'
|
22
|
+
Jdbc::Derby.load_driver
|
23
|
+
|
24
|
+
data_source = org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource.new
|
25
|
+
data_source.database_name = "memory:PooledDerbyDB-JNDI"
|
26
|
+
data_source.create_database = "create"
|
27
|
+
data_source.user = "sa"
|
28
|
+
data_source.password = ""
|
29
|
+
|
30
|
+
init_context = javax.naming.InitialContext.new
|
31
|
+
begin
|
32
|
+
init_context.create_subcontext 'jdbc'
|
33
|
+
rescue javax.naming.NameAlreadyBoundException
|
34
|
+
end
|
35
|
+
init_context.bind JNDI_POOLED_CONFIG[:jndi], data_source
|
data/test/db/logger.rb
CHANGED
data/test/db/mssql.rb
CHANGED
data/test/db/mysql.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
:password => 'arjdbc',
|
4
|
-
:adapter => 'mysql',
|
5
|
-
:database => 'arjdbc_test',
|
6
|
-
:host => 'localhost'
|
7
|
-
}
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/mysql_config'
|
8
3
|
|
9
4
|
ActiveRecord::Base.establish_connection(MYSQL_CONFIG)
|
10
5
|
|
data/test/db/oracle.rb
CHANGED
data/test/db/postgres.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
:database => 'arjdbc_test',
|
4
|
-
:host => 'localhost',
|
5
|
-
:username => 'arjdbc',
|
6
|
-
:password => 'arjdbc'
|
7
|
-
}
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres_config'
|
8
3
|
|
9
4
|
ActiveRecord::Base.establish_connection(POSTGRES_CONFIG)
|
5
|
+
|
6
|
+
begin
|
7
|
+
result = ActiveRecord::Base.connection.execute("SHOW server_version_num")
|
8
|
+
PG_VERSION = result.first.first[1].to_i
|
9
|
+
rescue
|
10
|
+
PG_VERSION = 0
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
POSTGRES_CONFIG = {
|
2
|
+
:adapter => 'postgresql',
|
3
|
+
:database => 'arjdbc_test',
|
4
|
+
:host => 'localhost',
|
5
|
+
:username => 'arjdbc',
|
6
|
+
:password => 'arjdbc'
|
7
|
+
}
|
8
|
+
|
9
|
+
POSTGRES_CONFIG[:host] = ENV['PGHOST'] if ENV['PGHOST']
|
10
|
+
POSTGRES_CONFIG[:port] = ENV['PGPORT'] if ENV['PGPORT']
|
data/test/db/sqlite3.rb
CHANGED
data/test/derby_simple_test.rb
CHANGED
@@ -2,28 +2,83 @@ require 'jdbc_common'
|
|
2
2
|
require 'db/jdbc'
|
3
3
|
|
4
4
|
class GenericJdbcConnectionTest < Test::Unit::TestCase
|
5
|
+
|
5
6
|
def test_connection_available_through_jdbc_adapter
|
6
|
-
|
7
|
-
|
7
|
+
ActiveRecord::Base.connection.execute("show databases") # MySQL
|
8
|
+
assert ActiveRecord::Base.connected?
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
-
connection = Object.new
|
12
|
-
connection.extend ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper
|
13
|
-
connection.config = { :url => "jdbc://somehost", :options => { :hoge => "true", :fuya => "false"} }
|
14
|
-
assert_equal "jdbc://somehost?hoge=true&fuya=false", connection.configure_url
|
11
|
+
class ConfigHelperTest < Test::Unit::TestCase
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
test 'configure connection url' do
|
14
|
+
connection = Object.new
|
15
|
+
connection.extend ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper
|
16
|
+
connection.config = { :url => "jdbc://somehost", :options => { :hoge => "true", :fuya => "false"} }
|
17
|
+
assert_equal "jdbc://somehost?hoge=true&fuya=false", connection.send(:configure_url)
|
18
|
+
|
19
|
+
connection.config = { :url => "jdbc://somehost?param=0", :options => { :hoge => "true", :fuya => "false"} }
|
20
|
+
assert_equal "jdbc://somehost?param=0&hoge=true&fuya=false", connection.send(:configure_url)
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'connection fails without driver and url' do
|
24
|
+
with_connection_removed do
|
25
|
+
ActiveRecord::Base.establish_connection :adapter => 'jdbc'
|
26
|
+
assert_raises(ActiveRecord::ConnectionNotEstablished) do
|
27
|
+
ActiveRecord::Base.connection
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'connection fails without driver' do
|
33
|
+
with_connection_removed do
|
34
|
+
ActiveRecord::Base.establish_connection :adapter => 'jdbc', :url => 'jdbc:derby:test.derby;create=true'
|
35
|
+
assert_raises(ActiveRecord::ConnectionNotEstablished) do
|
36
|
+
ActiveRecord::Base.connection
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'connection does not fail with driver_instance and url' do
|
42
|
+
load_derby_driver
|
43
|
+
with_connection_removed do
|
44
|
+
driver_instance = ActiveRecord::ConnectionAdapters::JdbcDriver.new('org.apache.derby.jdbc.EmbeddedDriver')
|
45
|
+
ActiveRecord::Base.establish_connection :adapter => 'jdbc',
|
46
|
+
:url => 'jdbc:derby:memory:TestDB;create=true', :driver_instance => driver_instance
|
47
|
+
assert_nothing_raised do
|
48
|
+
ActiveRecord::Base.connection
|
49
|
+
end
|
19
50
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
51
|
+
assert ActiveRecord::Base.connected?
|
52
|
+
assert_nothing_raised do
|
53
|
+
connection = ActiveRecord::Base.connection
|
54
|
+
connection.execute("create table my_table(x int)")
|
55
|
+
#connection.execute("insert into my_table values 42")
|
56
|
+
#connection.execute("select * from my_table")
|
57
|
+
end
|
58
|
+
end
|
25
59
|
end
|
26
|
-
|
27
|
-
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def with_connection_removed
|
64
|
+
connection = ActiveRecord::Base.remove_connection
|
65
|
+
begin
|
66
|
+
yield
|
67
|
+
ensure
|
68
|
+
ActiveRecord::Base.establish_connection connection
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@@derby_driver_loaded = nil
|
73
|
+
|
74
|
+
def load_derby_driver
|
75
|
+
@@derby_driver_loaded ||= begin
|
76
|
+
require 'jdbc/derby'
|
77
|
+
Jdbc::Derby.load_driver
|
78
|
+
true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
28
82
|
end
|
83
|
+
|
29
84
|
end
|
data/test/h2_simple_test.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,104 +1,35 @@
|
|
1
|
+
# Defining helper methods useful both in the definition of test tasks, as well as in the execution
|
2
|
+
# of tests themselves. Do not require test/unit within this file, as that'll make the rake process
|
3
|
+
# attempt to run tests itself. Test-specific helpers should go in test/jdbc_common.rb.
|
4
|
+
|
1
5
|
module Kernel
|
2
6
|
def find_executable?(name)
|
3
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).
|
7
|
+
(ENV['PATH'] || '').split(File::PATH_SEPARATOR).
|
8
|
+
detect { |p| File.executable?(File.join(p, name)) }
|
4
9
|
end
|
10
|
+
end
|
5
11
|
|
6
|
-
|
12
|
+
module PostgresHelper
|
13
|
+
def self.pg_cmdline_params
|
14
|
+
params = ""
|
15
|
+
params += "-h #{ENV['PGHOST']} " if ENV['PGHOST']
|
16
|
+
params += "-p #{ENV['PGPORT']} " if ENV['PGPORT']
|
17
|
+
params
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.have_postgres?(warn = nil)
|
7
21
|
if find_executable?("psql")
|
8
|
-
if `psql -c '\\l' -U postgres 2>&1` && $?.exitstatus == 0
|
22
|
+
if `psql -c '\\l' -U postgres #{pg_cmdline_params}2>&1` && $?.exitstatus == 0
|
9
23
|
true
|
10
24
|
else
|
11
|
-
warn
|
25
|
+
if warn.nil?
|
26
|
+
warn = "No \"postgres\" role? You might need to execute `createuser postgres -drs' first."
|
27
|
+
end
|
28
|
+
send(:warn, warn) if warn # warn == false disables warnings
|
12
29
|
false
|
13
30
|
end
|
14
31
|
end
|
15
32
|
end
|
16
33
|
end
|
17
34
|
|
18
|
-
|
19
|
-
|
20
|
-
# assert_queries and SQLCounter taken from rails active_record tests
|
21
|
-
require 'test/unit'
|
22
|
-
class Test::Unit::TestCase
|
23
|
-
def assert_queries(num = 1, matching = nil)
|
24
|
-
ActiveRecord::SQLCounter.log = []
|
25
|
-
yield
|
26
|
-
ensure
|
27
|
-
queries = nil
|
28
|
-
ActiveRecord::SQLCounter.log.tap {|log| queries = (matching ? log.select {|s| s =~ matching } : log) }
|
29
|
-
assert_equal num, queries.size, "#{queries.size} instead of #{num} queries were executed.#{queries.size == 0 ? '' : "\nQueries:\n#{queries.join("\n")}"}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
module ActiveRecord
|
34
|
-
class SQLCounter
|
35
|
-
def self.ignored_sql
|
36
|
-
@@ignored_sql
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.ignored_sql=(value)
|
40
|
-
@@ignored_sql = value
|
41
|
-
end
|
42
|
-
|
43
|
-
self.ignored_sql = [
|
44
|
-
/^PRAGMA (?!(table_info))/,
|
45
|
-
/^SELECT currval/,
|
46
|
-
/^SELECT CAST/,
|
47
|
-
/^SELECT @@IDENTITY/,
|
48
|
-
/^SELECT @@ROWCOUNT/,
|
49
|
-
/^SAVEPOINT/,
|
50
|
-
/^ROLLBACK TO SAVEPOINT/,
|
51
|
-
/^RELEASE SAVEPOINT/,
|
52
|
-
/^SHOW max_identifier_length/,
|
53
|
-
/^BEGIN/,
|
54
|
-
/^COMMIT/
|
55
|
-
]
|
56
|
-
|
57
|
-
# FIXME: this needs to be refactored so specific database can add their own
|
58
|
-
# ignored SQL. This ignored SQL is for Oracle.
|
59
|
-
ignored_sql.concat [/^select .*nextval/i,
|
60
|
-
/^SAVEPOINT/,
|
61
|
-
/^ROLLBACK TO/,
|
62
|
-
/^\s*select .* from all_triggers/im
|
63
|
-
]
|
64
|
-
|
65
|
-
def self.log=(v)
|
66
|
-
@@log = v
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.log
|
70
|
-
@@log
|
71
|
-
end
|
72
|
-
|
73
|
-
self.log = []
|
74
|
-
|
75
|
-
def call(name, start, finish, message_id, values)
|
76
|
-
sql = values[:sql]
|
77
|
-
|
78
|
-
# FIXME: this seems bad. we should probably have a better way to indicate
|
79
|
-
# the query was cached
|
80
|
-
unless 'CACHE' == values[:name]
|
81
|
-
self.class.log << sql unless self.class.ignored_sql.
|
82
|
-
any? { |r| sql =~ r }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.instance
|
87
|
-
@instance || self.new
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
begin
|
92
|
-
require 'active_support/notifications'
|
93
|
-
ActiveSupport::Notifications.subscribe('sql.active_record', SQLCounter.new)
|
94
|
-
rescue LoadError
|
95
|
-
class ActiveRecord::ConnectionAdapters::JdbcAdapter
|
96
|
-
def log_info(sql, name, ms)
|
97
|
-
ActiveRecord::SQLCounter.instance.call(name, ms, ms, nil, :sql => sql)
|
98
|
-
super
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
35
|
+
require 'fileutils'
|