activerecord-sqlserver-adapter 2.3.5 → 2.3.6
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
MASTER
|
3
3
|
|
4
4
|
|
5
|
+
* 2.3.6
|
6
|
+
|
7
|
+
* Allow DNS's to not contain a database and use what is in database.yml [Marco Mastrodonato]
|
8
|
+
|
9
|
+
* Rake tasks methods for vanallia rails :db namespace parity. [Ken Collins]
|
10
|
+
|
11
|
+
* IronRuby integrated security fixes [Jimmy Schementi]
|
12
|
+
|
13
|
+
|
5
14
|
* 2.3.5
|
6
15
|
|
7
16
|
* Initial IronRuby ADONET connection mode support baked right in. Removed most &block
|
data/README.rdoc
CHANGED
@@ -6,6 +6,7 @@ The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are cur
|
|
6
6
|
|
7
7
|
== What's New
|
8
8
|
|
9
|
+
* Integration with rails :db namespaced rake tasks.
|
9
10
|
* IronRuby support using ADONET connection mode.
|
10
11
|
* Direct ODBC mode. No DBI anymore, means around 20% faster!
|
11
12
|
* Now supports SQL Server 2008 too!
|
@@ -24,6 +25,13 @@ The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are cur
|
|
24
25
|
* Automatically reconnects to lost database connections.
|
25
26
|
|
26
27
|
|
28
|
+
==== Testing Rake Tasks Support
|
29
|
+
|
30
|
+
This is a long story, but if you are not working with a legacy database and you can trust your schema.rb to setup you local development or test database, then we have adapter level support for rails :db rake tasks. Please read this wiki page for full details.
|
31
|
+
|
32
|
+
http://wiki.github.com/rails-sqlserver/2000-2005-adapter/rails-db-rake-tasks
|
33
|
+
|
34
|
+
|
27
35
|
==== SQL Server 2008 Support
|
28
36
|
|
29
37
|
Because this adapter is primarily coded to SQL Server 2000/2005, it does not take advantage of many of the things in 2008 that would speed up the code. At some point in the future there will be a branch of this code that is specifically targeted for 2008. That adapter version will remove much of the dirty innards of this version that are meant to code around many previous SQL Server 2000/2005 short comings, the biggest being no limit/offset.
|
@@ -163,7 +163,7 @@ module ActiveRecord
|
|
163
163
|
class SQLServerAdapter < AbstractAdapter
|
164
164
|
|
165
165
|
ADAPTER_NAME = 'SQLServer'.freeze
|
166
|
-
VERSION = '2.3.
|
166
|
+
VERSION = '2.3.6'.freeze
|
167
167
|
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
|
168
168
|
SUPPORTED_VERSIONS = [2000,2005,2008].freeze
|
169
169
|
LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
|
@@ -192,6 +192,7 @@ module ActiveRecord
|
|
192
192
|
connect
|
193
193
|
super(raw_connection, logger)
|
194
194
|
initialize_sqlserver_caches
|
195
|
+
use_database
|
195
196
|
unless SUPPORTED_VERSIONS.include?(database_year)
|
196
197
|
raise NotImplementedError, "Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported."
|
197
198
|
end
|
@@ -401,6 +402,11 @@ module ActiveRecord
|
|
401
402
|
end
|
402
403
|
end
|
403
404
|
|
405
|
+
def use_database(database=nil)
|
406
|
+
database ||= @connection_options[:database]
|
407
|
+
do_execute "USE #{database}" unless database.blank?
|
408
|
+
end
|
409
|
+
|
404
410
|
def outside_transaction?
|
405
411
|
info_schema_query { select_value("SELECT @@TRANCOUNT") == 0 }
|
406
412
|
end
|
@@ -664,7 +670,7 @@ module ActiveRecord
|
|
664
670
|
end
|
665
671
|
|
666
672
|
def remove_index(table_name, options = {})
|
667
|
-
do_execute "DROP INDEX #{table_name}.#{quote_column_name(index_name(table_name, options))}"
|
673
|
+
do_execute "DROP INDEX #{table_name}.#{quote_column_name(index_name(table_name, options))}" rescue nil
|
668
674
|
end
|
669
675
|
|
670
676
|
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
|
@@ -707,30 +713,36 @@ module ActiveRecord
|
|
707
713
|
end
|
708
714
|
|
709
715
|
# RAKE UTILITY METHODS =====================================#
|
710
|
-
|
711
|
-
def recreate_database
|
712
|
-
|
713
|
-
|
714
|
-
do_execute 'USE master'
|
716
|
+
|
717
|
+
def recreate_database
|
718
|
+
remove_database_connections_and_rollback do
|
719
|
+
do_execute "EXEC sp_MSforeachtable 'DROP TABLE ?'"
|
715
720
|
end
|
716
|
-
|
717
|
-
|
721
|
+
end
|
722
|
+
|
723
|
+
def recreate_database!(database=nil)
|
724
|
+
current_db = current_database
|
725
|
+
database ||= current_db
|
726
|
+
this_db = database.to_s == current_db
|
727
|
+
do_execute 'USE master' if this_db
|
728
|
+
drop_database(database)
|
729
|
+
create_database(database)
|
718
730
|
ensure
|
719
|
-
|
731
|
+
use_database(current_db) if this_db
|
720
732
|
end
|
721
|
-
|
722
|
-
|
733
|
+
|
734
|
+
# Remove existing connections and rollback any transactions if we received the message
|
735
|
+
# 'Cannot drop the database 'test' because it is currently in use'
|
736
|
+
def drop_database(database)
|
723
737
|
retry_count = 0
|
724
738
|
max_retries = 1
|
725
739
|
begin
|
726
|
-
do_execute "DROP DATABASE #{
|
740
|
+
do_execute "DROP DATABASE #{database}"
|
727
741
|
rescue ActiveRecord::StatementInvalid => err
|
728
|
-
|
729
|
-
# 'Cannot drop the database 'test' because it is currently in use'
|
730
|
-
if err.message =~ /because it is currently in use/
|
742
|
+
if err.message =~ /because it is currently in use/i
|
731
743
|
raise if retry_count >= max_retries
|
732
744
|
retry_count += 1
|
733
|
-
remove_database_connections_and_rollback(
|
745
|
+
remove_database_connections_and_rollback(database)
|
734
746
|
retry
|
735
747
|
else
|
736
748
|
raise
|
@@ -738,18 +750,28 @@ module ActiveRecord
|
|
738
750
|
end
|
739
751
|
end
|
740
752
|
|
741
|
-
def create_database(
|
742
|
-
do_execute "CREATE DATABASE #{
|
753
|
+
def create_database(database)
|
754
|
+
do_execute "CREATE DATABASE #{database}"
|
743
755
|
end
|
744
756
|
|
745
757
|
def current_database
|
746
758
|
select_value 'SELECT DB_NAME()'
|
747
759
|
end
|
748
|
-
|
749
|
-
def
|
750
|
-
|
751
|
-
|
752
|
-
|
760
|
+
|
761
|
+
def charset
|
762
|
+
select_value "SELECT SERVERPROPERTY('SqlCharSetName')"
|
763
|
+
end
|
764
|
+
|
765
|
+
# This should disconnect all other users and rollback any transactions for SQL 2000 and 2005
|
766
|
+
# http://sqlserver2000.databases.aspfaq.com/how-do-i-drop-a-sql-server-database.html
|
767
|
+
def remove_database_connections_and_rollback(database=nil)
|
768
|
+
database ||= current_database
|
769
|
+
do_execute "ALTER DATABASE #{database} SET SINGLE_USER WITH ROLLBACK IMMEDIATE"
|
770
|
+
begin
|
771
|
+
yield
|
772
|
+
ensure
|
773
|
+
do_execute "ALTER DATABASE #{database} SET MULTI_USER"
|
774
|
+
end if block_given?
|
753
775
|
end
|
754
776
|
|
755
777
|
|
@@ -766,9 +788,12 @@ module ActiveRecord
|
|
766
788
|
when :adonet
|
767
789
|
System::Data::SqlClient::SqlConnection.new.tap do |connection|
|
768
790
|
connection.connection_string = System::Data::SqlClient::SqlConnectionStringBuilder.new.tap do |cs|
|
769
|
-
|
770
|
-
|
771
|
-
|
791
|
+
if config[:integrated_security]
|
792
|
+
cs.integrated_security = true
|
793
|
+
else
|
794
|
+
cs.user_i_d = config[:username]
|
795
|
+
cs.password = config[:password]
|
796
|
+
end
|
772
797
|
cs.add 'Server', config[:host].to_clr_string
|
773
798
|
cs.initial_catalog = config[:database]
|
774
799
|
cs.multiple_active_result_sets = false
|
@@ -71,6 +71,17 @@ class ConnectionTestSqlserver < ActiveRecord::TestCase
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
should 'allow usage of :database connection option to remove setting from dsn' do
|
75
|
+
assert_equal 'activerecord_unittest', @connection.current_database
|
76
|
+
begin
|
77
|
+
@connection.use_database('activerecord_unittest2')
|
78
|
+
assert_equal 'activerecord_unittest2', @connection.current_database
|
79
|
+
ensure
|
80
|
+
@connection.use_database
|
81
|
+
assert_equal 'activerecord_unittest', @connection.current_database, 'Would default back to connection options'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
74
85
|
context 'Connection management' do
|
75
86
|
|
76
87
|
setup do
|
@@ -10,14 +10,16 @@ ActiveRecord::Base.configurations = {
|
|
10
10
|
:mode => 'ODBC',
|
11
11
|
:host => 'localhost',
|
12
12
|
:username => 'rails',
|
13
|
-
:dsn
|
13
|
+
:dsn => 'activerecord_unittest',
|
14
|
+
:database => 'activerecord_unittest'
|
14
15
|
},
|
15
16
|
'arunit2' => {
|
16
17
|
:adapter => 'sqlserver',
|
17
18
|
:mode => 'ODBC',
|
18
19
|
:host => 'localhost',
|
19
20
|
:username => 'rails',
|
20
|
-
:dsn
|
21
|
+
:dsn => 'activerecord_unittest2',
|
22
|
+
:database => 'activerecord_unittest2'
|
21
23
|
}
|
22
24
|
}
|
23
25
|
|