mysql_framework 2.0.1 → 2.1.0

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
  SHA256:
3
- metadata.gz: 3694d868584973bdad19a924b7b50961e2c5fcca8ea45e7222605b5145152c24
4
- data.tar.gz: d92fe8d7004501fab5e05cd0277f04287bafd3a2352439a1ec4fa5d2cedefe10
3
+ metadata.gz: f48c69762d95976838c6779c9acfc6591e2113d9a91128f69a2621890332bee0
4
+ data.tar.gz: 5d9d0250828d1e93626010796f79364d2f23b22554c38f4bda313ca718faffc6
5
5
  SHA512:
6
- metadata.gz: a7c05de40f9bcecbbef52444d78a3d07cde007aa7122da4eebc94d411deee65e9805c42bf2f4ead59150668346108348eca7cb04e264aa36882e925a20bd8c60
7
- data.tar.gz: abbc47dbbd4a95b3c3e1956089308b7e4f052185698cd36e00d0f887594e17e5491a5ee28e00988cabc24831b76e8a1c5e2ccc2d4fd0dc7517a4ac1bb8bf2598
6
+ metadata.gz: 0e477a4a454360a80a979421aad3ba7db1b7399656062dc7cd129174af1f48953fb3c56d2ad2d959fafbf009a7c1e9f9aa57d34c91c5a06aeb853d0f0e518fb8
7
+ data.tar.gz: 2c0980c6a0c94718d0df07d56ae1f88367ce8716d5af457b1c9c6526c29878380bbaeaffaca314dcdf4943d1366c27940675d693fdec4fe961fc183e7a6bb3ed
@@ -75,10 +75,19 @@ module MysqlFramework
75
75
  end
76
76
 
77
77
  # This method is called to execute a prepared statement
78
+ #
79
+ # @note Ensure we close each statement, otherwise we can run into
80
+ # a 'Commands out of sync' error if multiple threads are running different
81
+ # queries at the same time.
78
82
  def execute(query, provided_client = nil)
79
83
  with_client(provided_client) do |client|
80
- statement = client.prepare(query.sql)
81
- statement.execute(*query.params)
84
+ begin
85
+ statement = client.prepare(query.sql)
86
+ result = statement.execute(*query.params)
87
+ result.to_a if result
88
+ ensure
89
+ statement.close if statement
90
+ end
82
91
  end
83
92
  end
84
93
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MysqlFramework
4
- VERSION = '2.0.1'
4
+ VERSION = '2.1.0'
5
5
  end
@@ -272,6 +272,33 @@ describe MysqlFramework::Connector do
272
272
  expect(results.length).to eq(1)
273
273
  expect(results[0][:id]).to eq(guid)
274
274
  end
275
+
276
+ it 'does not raise a commands out of sync error' do
277
+ threads = []
278
+ threads << Thread.new do
279
+ 350.times do
280
+ update_query = MysqlFramework::SqlQuery.new.update('gems')
281
+ .set(updated_at: Time.now)
282
+ expect { subject.execute(update_query) }.not_to raise_error
283
+ end
284
+ end
285
+
286
+ threads << Thread.new do
287
+ 350.times do
288
+ select_query = MysqlFramework::SqlQuery.new.select('*').from('demo')
289
+ expect { subject.execute(select_query) }.not_to raise_error
290
+ end
291
+ end
292
+
293
+ threads << Thread.new do
294
+ 350.times do
295
+ select_query = MysqlFramework::SqlQuery.new.select('*').from('test')
296
+ expect { subject.execute(select_query) }.not_to raise_error
297
+ end
298
+ end
299
+
300
+ threads.each(&:join)
301
+ end
275
302
  end
276
303
 
277
304
  describe '#query' 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.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-23 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -137,8 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.7.7
140
+ rubygems_version: 3.0.8
142
141
  signing_key:
143
142
  specification_version: 4
144
143
  summary: A lightweight framework to provide managers for working with MySQL.