Skip to content

Commit

Permalink
Specify no format in :exec_insert and :exec_insert_all instead of inf…
Browse files Browse the repository at this point in the history
…erring within FormatManager
  • Loading branch information
leboshi committed Dec 6, 2024
1 parent a65dffb commit dc87568
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def with_settings(**settings)

# Request a specific format for the duration of the provided block.
# Pass `nil` to explicitly send the SQL statement without a `FORMAT` clause.
# @param [String] format
# @param [String, nil] format
#
# @example Specify CSVWithNamesAndTypes format
# with_response_format('CSVWithNamesAndTypes') do
Expand Down Expand Up @@ -49,7 +49,7 @@ def execute(sql, name = nil, format: @response_format, settings: {})

def exec_insert(sql, name, _binds, _pk = nil, _sequence_name = nil, returning: nil)
new_sql = sql.sub(/ (DEFAULT )?VALUES/, " VALUES")
execute(new_sql, name)
with_response_format(nil) { execute(new_sql, name) }
true
end

Expand All @@ -70,7 +70,7 @@ def internal_exec_query(sql, name = nil, binds = [], prepare: false, async: fals
end

def exec_insert_all(sql, name)
execute(sql, name)
with_response_format(nil) { execute(sql, name) }
true
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Statement
class FormatManager

def initialize(sql, format:)
@sql = sql
@sql = sql.strip
@format = format
end

Expand All @@ -18,29 +18,25 @@ def apply
end

def skip_format?
for_insert? || system_command? || schema_command? || format_specified? || delete?
system_command? || schema_command? || format_specified? || delete?
end

private

def for_insert?
/^insert into/i.match?(@sql)
end

def system_command?
/^system|^optimize/i.match?(@sql)
/\Asystem|\Aoptimize/i.match?(@sql)
end

def schema_command?
/^create|^alter|^drop|^rename/i.match?(@sql)
/\Acreate|\Aalter|\Adrop|\Arename/i.match?(@sql)
end

def format_specified?
/format [a-z]+\z/i.match?(@sql)
end

def delete?
/^delete from/i.match?(@sql)
/\Adelete from/i.match?(@sql)
end

end
Expand Down

0 comments on commit dc87568

Please sign in to comment.