Module: RuboCop::Cop::Isucon::Mixin::Sqlite3ExecuteMethods
- Extended by:
- NodePattern::Macros
- Includes:
- OffenceLocationMethods
- Included in:
- Sqlite3::JoinWithoutIndex, Sqlite3::ManyJoinTable, Sqlite3::NPlusOneQuery, Sqlite3::SelectAsterisk, Sqlite3::WhereWithoutIndex
- Defined in:
- lib/rubocop/cop/isucon/mixin/sqlite3_execute_methods.rb
Overview
Helper methods for db.execute
in AST
Constant Summary collapse
- NON_STRING_WARNING_MSG =
"Warning: non-string was passed to `execute` or `get_first_row` 1st argument. " \ "So argument doesn't parsed as SQL (%<file_path>s:%<line_num>d)"
Instance Method Summary collapse
Methods included from OffenceLocationMethods
Instance Method Details
#find_xquery(node) ⇒ Object
15 16 17 |
# File 'lib/rubocop/cop/isucon/mixin/sqlite3_execute_methods.rb', line 15 def_node_search :find_execute, <<~PATTERN (send _ {:execute | :get_first_row} (${str dstr lvar ivar cvar} $...) ...) PATTERN |
#with_db_query(node) {|type, root_gda| ... } ⇒ Object
Note:
If arguments of db.xquery
isn't string, root_gda
is nil
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/isucon/mixin/sqlite3_execute_methods.rb', line 27 def with_db_query(node) find_execute(node) do |type, params| sql = execute_param(type: type, params: params) unless sql warn format(NON_STRING_WARNING_MSG, file_path: processed_source.file_path, line_num: node.loc.expression.line) end root_gda = sql ? RuboCop::Isucon::GDA::Client.new(sql) : nil yield type, root_gda end end |