Skip to content

Commit 02f5b30

Browse files
committed
Merge pull request #1039 from rails-sqlserver/fix-connection-configuration-7.0
Fix hook method that allows custom connection configuration
1 parent 53c9f82 commit 02f5b30

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Fixed
44

55
- [#1006](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1006) Fix support for index types
6+
- [#x](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/x) Fix hook method that allows custom connection configuration.
67

78
#### Changed
89

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ end
8484

8585
#### Configure Connection
8686

87-
We currently conform to an unpublished and non-standard AbstractAdapter interface to configure connections made to the database. To do so, just override the `configure_connection` method in an initializer like so. In this case below we are setting the `TEXTSIZE` to 64 megabytes.
87+
We currently conform to an unpublished and non-standard AbstractAdapter interface to configure connections made to the database. To do so, just implement the `configure_connection` method in an initializer like so. In this case below we are setting the `TEXTSIZE` to 64 megabytes.
8888

8989
```ruby
9090
module ActiveRecord

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def config_encoding(config)
140140
def initialize(connection, logger, _connection_options, config)
141141
super(connection, logger, config)
142142
@connection_options = config
143-
configure_connection
143+
perform_connection_configuration
144144
end
145145

146146
# === Abstract Adapter ========================================== #
@@ -301,14 +301,6 @@ def reset!
301301
do_execute "IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION"
302302
end
303303

304-
def configure_connection
305-
@spid = _raw_select("SELECT @@SPID", fetch: :rows).first.first
306-
@version_year = version_year
307-
308-
initialize_dateformatter
309-
use_database
310-
end
311-
312304
# === Abstract Adapter (Misc Support) =========================== #
313305

314306
def tables_with_referential_integrity
@@ -530,7 +522,20 @@ def sqlserver_version
530522

531523
def connect
532524
@connection = self.class.new_client(@connection_options)
533-
configure_connection
525+
perform_connection_configuration
526+
end
527+
528+
def perform_connection_configuration
529+
configure_connection_defaults
530+
configure_connection if self.respond_to?(:configure_connection)
531+
end
532+
533+
def configure_connection_defaults
534+
@spid = _raw_select("SELECT @@SPID", fetch: :rows).first.first
535+
@version_year = version_year
536+
537+
initialize_dateformatter
538+
use_database
534539
end
535540
end
536541
end

0 commit comments

Comments
 (0)