Skip to content

Commit eba58db

Browse files
authored
Merge pull request #1039 from rails-sqlserver/fix-connection-configuration-7.0
Fix hook method that allows custom connection configuration
2 parents a7fa84f + 5d7fadc commit eba58db

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- [#1029](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1029) Handle views defined in other databases.
66
- [#1033](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1033) Support proc default values in ruby 3.2.
77
- [#1020](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1020) Support using adapter as a stand-alone gem.
8-
8+
- [#1039](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1039) Fix hook method that allows custom connection configuration.
99

1010
#### Changed
1111

README.md

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

8686
#### Configure Connection
8787

88-
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.
88+
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.
8989

9090
```ruby
9191
module ActiveRecord

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def config_encoding(config)
157157
def initialize(connection, logger, _connection_options, config)
158158
super(connection, logger, config)
159159
@connection_options = config
160-
configure_connection
160+
perform_connection_configuration
161161
end
162162

163163
# === Abstract Adapter ========================================== #
@@ -318,14 +318,6 @@ def reset!
318318
do_execute "IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION"
319319
end
320320

321-
def configure_connection
322-
@spid = _raw_select("SELECT @@SPID", fetch: :rows).first.first
323-
@version_year = version_year
324-
325-
initialize_dateformatter
326-
use_database
327-
end
328-
329321
# === Abstract Adapter (Misc Support) =========================== #
330322

331323
def tables_with_referential_integrity
@@ -557,7 +549,20 @@ def sqlserver_version
557549

558550
def connect
559551
@connection = self.class.new_client(@connection_options)
560-
configure_connection
552+
perform_connection_configuration
553+
end
554+
555+
def perform_connection_configuration
556+
configure_connection_defaults
557+
configure_connection if self.respond_to?(:configure_connection)
558+
end
559+
560+
def configure_connection_defaults
561+
@spid = _raw_select("SELECT @@SPID", fetch: :rows).first.first
562+
@version_year = version_year
563+
564+
initialize_dateformatter
565+
use_database
561566
end
562567
end
563568
end

0 commit comments

Comments
 (0)