activerecord_sqlserver_crm 4.2.4 → 4.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a1aee0ccf6eaa2664c8787a3d37234fad3542c7
4
- data.tar.gz: 5039b1cd46e1dec7077b686eef79c9f306de2b04
3
+ metadata.gz: 04c61257ab2299b47f3e71dfc4e0967dc0dd82c3
4
+ data.tar.gz: 4335bc027dbba84fae3db4769696bd5217428bf6
5
5
  SHA512:
6
- metadata.gz: 315ee83ad3afe9386b2648066eb16d22d6e36204950d75e6d4b6210ad9294cbf2f672ba9d9b46461f80dcb6e610476f26c73f81be4061e966fa44a9511e36c55
7
- data.tar.gz: 71ebb70cc16c4fd80fe95bd508fe48cebb8a200bbc21837f7380dcd7ff77133063bd3aca6c7276c21d6011c1b633dd9ceb1982cf87d0c37232cb5056f1ecf04a
6
+ metadata.gz: 92c6fa1ea3379529feab1dbc5fb9bbcf112a53f96b8339eab27a15312749302e8f080d967b876f0d32e78ec357d66e5978b5b8c8cd574b93c6adcd0fa77441c5
7
+ data.tar.gz: 09e4ee73ea5d37e3e0dcd6f05ce11e1b1049573440cab4c3d198b366a91951f5bc0b45b7e87766c2f6e124d78c8177d350e8b238669558ce737e618907dbfe2e
@@ -1,2 +1,3 @@
1
1
  require "active_record_extension"
2
2
  require "big_decimal"
3
+ require "sql_server_adapter"
@@ -1,3 +1,3 @@
1
1
  module ActiverecordSqlserverCrm
2
- VERSION = "4.2.4"
2
+ VERSION = "4.2.5"
3
3
  end
@@ -0,0 +1,107 @@
1
+ # The code changes here are for using failover. Add you secondary host in database.yml as a slave. For example
2
+ #
3
+ # development:
4
+ # adapter: sqlserver
5
+ # host: master.db.int
6
+ # port: 1433
7
+ # database: FailoverDatabase
8
+ # username: user
9
+ # password: pass
10
+ # slaves:
11
+ # - host: slave.db.int
12
+ #
13
+ module ActiveRecord
14
+ module ConnectionAdapters
15
+ class SQLServerAdapter
16
+
17
+ def connect
18
+ config = @connection_options
19
+ # If using host database, try connect to master again after x minutes
20
+ if using_slave? && @switch_back_next_attempt.present? && @switch_back_next_attempt <= Time.now
21
+ change_active_host
22
+ end
23
+ @connection = case config[:mode]
24
+ when :dblib
25
+ begin
26
+ # Attempt first connect
27
+ dblib_connect(config)
28
+ rescue
29
+ begin
30
+ dblib_connect(config)
31
+ rescue
32
+ change_active_host
33
+ dblib_connect(config)
34
+ end
35
+ end
36
+ when :odbc
37
+ odbc_connect(config)
38
+ end
39
+ @spid = _raw_select('SELECT @@SPID', fetch: :rows).first.first
40
+ configure_connection
41
+ end
42
+
43
+ def using_master?
44
+ @active_host == @connection_options[:host]
45
+ end
46
+
47
+ def using_slave?
48
+ !using_master?
49
+ end
50
+
51
+ def active_host=(host)
52
+ @active_host = host
53
+ end
54
+
55
+ def active_host
56
+ @active_host ||= @connection_options[:host]
57
+ end
58
+
59
+ def change_active_host
60
+ slave_host = @connection_options[:slaves][0]['host']
61
+ return unless slave_host
62
+ if using_master?
63
+ self.active_host = slave_host
64
+ # After x minutes, try using the master database again
65
+ @switch_back_next_attempt = Time.now + 5.minute
66
+ else
67
+ self.active_host = @connection_options[:host]
68
+ @switch_back_next_attempt = nil
69
+ end
70
+ end
71
+
72
+ def dblib_connect(config)
73
+ TinyTds::Client.new(
74
+ dataserver: config[:dataserver],
75
+ host: active_host,
76
+ port: config[:port],
77
+ username: config[:username],
78
+ password: config[:password],
79
+ database: config[:database],
80
+ tds_version: config[:tds_version],
81
+ appname: config_appname(config),
82
+ login_timeout: config_login_timeout(config),
83
+ timeout: config_timeout(config),
84
+ encoding: config_encoding(config),
85
+ azure: config[:azure]
86
+ ).tap do |client|
87
+ if config[:azure]
88
+ client.execute('SET ANSI_NULLS ON').do
89
+ client.execute('SET CURSOR_CLOSE_ON_COMMIT OFF').do
90
+ client.execute('SET ANSI_NULL_DFLT_ON ON').do
91
+ client.execute('SET IMPLICIT_TRANSACTIONS OFF').do
92
+ client.execute('SET ANSI_PADDING ON').do
93
+ client.execute('SET QUOTED_IDENTIFIER ON').do
94
+ client.execute('SET ANSI_WARNINGS ON').do
95
+ else
96
+ client.execute('SET ANSI_DEFAULTS ON').do
97
+ client.execute('SET CURSOR_CLOSE_ON_COMMIT OFF').do
98
+ client.execute('SET IMPLICIT_TRANSACTIONS OFF').do
99
+ end
100
+ client.execute('SET TEXTSIZE 2147483647').do
101
+ client.execute('SET CONCAT_NULL_YIELDS_NULL ON').do
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_sqlserver_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.4
4
+ version: 4.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rolf Lawrenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -151,6 +151,7 @@ files:
151
151
  - lib/odata/model.rb
152
152
  - lib/odata/operation.rb
153
153
  - lib/odata/update_operation.rb
154
+ - lib/sql_server_adapter.rb
154
155
  - lib/tasks/activerecord_sqlserver_crm_tasks.rake
155
156
  homepage: https://github.com/RolfLawrenz/activerecord_sqlserver_crm
156
157
  licenses: