Skip to content

Commit 114a467

Browse files
committed
Improve result row detection.
Use OCI8's cursor.type to tell us if it is a select statement. https://www.rubydoc.info/gems/ruby-oci8/OCI8/Cursor#type-instance_method
1 parent dc89a7a commit 114a467

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def raw_execute(sql, name = "SQL", binds = [], prepare: false, async: false, all
5454
end
5555

5656
rows = []
57-
if sql =~ /\A\s*SELECT/i # This seems a naive way to detect queries that will have row results.
57+
if cursor.select_statement?
5858
fetch_options = { get_lob_value: (name != "Writable Large Object") }
5959
while row = cursor.fetch(fetch_options)
6060
rows << row

lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ def row_count
162162
@raw_cursor.row_count
163163
end
164164

165+
def select_statement?
166+
@raw_cursor.type == :select_stmt
167+
end
168+
165169
def fetch(options = {})
166170
if row = @raw_cursor.fetch
167171
get_lob_value = options[:get_lob_value]

0 commit comments

Comments
 (0)