mysql_framework 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e296a8fc2b6937d61814f1b2722600dddcc767b88d234cdffe312137698fd0b5
4
- data.tar.gz: 29a3f6549675f886369c5b42be8722fd026100d1717cb1d58ccce11624fc8088
3
+ metadata.gz: 38653f6e3d1d849566574e58eb8386b4c32890370404cb3eade583b0070f5041
4
+ data.tar.gz: 5534eca9f224d13580cfd09f4e2478208857e5b353c9a664ed7b772bf8a088e1
5
5
  SHA512:
6
- metadata.gz: 4133713152e216029f6c5e1a91d9911fb4df4eb62fe13bad814eb1f7530c6483dde53c3f55e2f19cc92f04758a72ac7d1cf8e7e9e39981b64554e0df2d7f783b
7
- data.tar.gz: 62ce8b6bfbead9defc37117c9f5385df533e85051e8515ccecf6d3cf247f12afa95a2ef37627b96f109219e8ac2154f68ce5918e0960430014e51da8237bb762
6
+ metadata.gz: aa4e726ac90ac8b1ecd8ca20a64b4c33e81d003c395b49c340f712df500fc7879956f5479f9c23e53fe20ca947d41d2798ad42732c596a03ab219129f02a7dbd
7
+ data.tar.gz: ba2080bb5f7595b82996a48a0316ed70cf7560b5687abb9d5c9768c73f5e2b296e42378aa9139c80e2d5f705a8fa7bdb08167a740c019a6d5d0a0825436873e7
@@ -75,17 +75,18 @@ module MysqlFramework
75
75
 
76
76
  # This method is called to execute a prepared statement
77
77
  #
78
- # @note Ensure we close each statement, otherwise we can run into
79
- # a 'Commands out of sync' error if multiple threads are running different
80
- # queries at the same time.
78
+ # @note Ensure we free any result and close each statement, otherwise we
79
+ # can run into a 'Commands out of sync' error if multiple threads are
80
+ # running different queries at the same time.
81
81
  def execute(query, provided_client = nil)
82
82
  with_client(provided_client) do |client|
83
83
  begin
84
84
  statement = client.prepare(query.sql)
85
85
  result = statement.execute(*query.params)
86
- result.to_a if result
86
+ result&.to_a
87
87
  ensure
88
- statement.close if statement
88
+ result&.free
89
+ statement&.close
89
90
  end
90
91
  end
91
92
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MysqlFramework
4
- VERSION = '2.1.2'
4
+ VERSION = '2.1.3'
5
5
  end
@@ -291,6 +291,35 @@ describe MysqlFramework::Connector do
291
291
  expect(results[0][:id]).to eq(guid)
292
292
  end
293
293
 
294
+ context 'when cleaning up resources' do
295
+ let(:mock_client) { double('client') }
296
+ let(:mock_statement) { double('statement') }
297
+ let(:mock_result) { double('result') }
298
+ let(:select_query) { MysqlFramework::SqlQuery.new.select('*').from('demo') }
299
+
300
+ before do
301
+ allow(mock_result).to receive(:to_a)
302
+ allow(mock_result).to receive(:free)
303
+
304
+ allow(mock_statement).to receive(:close)
305
+ allow(mock_statement).to receive(:execute).and_return(mock_result)
306
+
307
+ allow(mock_client).to receive(:prepare).and_return(mock_statement)
308
+ end
309
+
310
+ it 'frees the result' do
311
+ expect(mock_result).to receive(:free)
312
+
313
+ subject.execute(select_query, mock_client)
314
+ end
315
+
316
+ it 'closes the statement' do
317
+ expect(mock_statement).to receive(:close)
318
+
319
+ subject.execute(select_query, mock_client)
320
+ end
321
+ end
322
+
294
323
  it 'does not raise a commands out of sync error' do
295
324
  threads = []
296
325
  threads << Thread.new do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake