Skip to content

Commit ec0ef18

Browse files
committed
Ensure Result#fields and #rows are always arrays
Fix: #282
1 parent 73df802 commit ec0ef18

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

contrib/ruby/lib/trilogy/result.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ class Trilogy
22
class Result
33
attr_reader :fields, :rows, :query_time, :affected_rows, :last_insert_id
44

5+
EMPTY_ARRAY = [].freeze
6+
private_constant :EMPTY_ARRAY
7+
58
def initialize(fields, rows, query_time, in_transaction, affected_rows, last_insert_id)
6-
@fields = fields
7-
@rows = rows
9+
@fields = fields || EMPTY_ARRAY
10+
@rows = rows || EMPTY_ARRAY
811
@query_time = query_time
912
@in_transaction = in_transaction
1013
@affected_rows = affected_rows

contrib/ruby/test/client_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ def test_trilogy_query_values
264264

265265
client.query("INSERT INTO trilogy_test (int_test) VALUES ('4')")
266266
client.query("INSERT INTO trilogy_test (int_test) VALUES ('3')")
267-
client.query("INSERT INTO trilogy_test (int_test) VALUES ('1')")
267+
result = client.query("INSERT INTO trilogy_test (int_test) VALUES ('1')")
268+
269+
assert_equal [], result.fields
270+
assert_equal [], result.rows
268271

269272
result = client.query_with_flags("SELECT id, int_test FROM trilogy_test", client.query_flags | Trilogy::QUERY_FLAGS_FLATTEN_ROWS)
270273

0 commit comments

Comments
 (0)