@@ -25,7 +25,7 @@ module Blazer
private
def process_vars(statement, data_source)
- (@bind_vars ||= []).concat(extract_vars(statement)).uniq!
+ (@bind_vars ||= []).concat(Blazer.extract_vars(statement)).uniq!
@bind_vars.each do |var|
params[var] ||= Blazer.data_sources[data_source].variable_defaults[var]
end
@@ -79,13 +79,6 @@ module Blazer
[smart_var, error]
- def extract_vars(statement)
- # strip commented out lines
- # and regex {1} or {1,2}
- statement.gsub(/\-\-.+/, "").gsub(/\/\*.+\*\//m, "").scan(/\{\w*?\}/i).map { |v| v[1...-1] }.reject { |v| /\A\d+(\,\d+)?\z/.match(v) || v.empty? }.uniq
- end
- helper_method :extract_vars
-
def variable_params
params.except(:controller, :action, :id, :host, :query, :dashboard, :query_id, :query_ids, :table_names, :authenticity_token, :utf8, :_method, :commit, :statement, :data_source, :name, :fork_query_id, :blazer, :run_id).permit!
@@ -279,7 +279,7 @@ module Blazer
id: q.id,
name: q.name,
creator: blazer_user && q.try(:creator) == blazer_user ? "You" : q.try(:creator).try(Blazer.user_name),
- vars: extract_vars(q.statement).join(", "),
+ vars: q.variables.join(", "),
to_param: q.to_param
}
@@ -5,6 +5,7 @@ module Blazer
validates :query_id, presence: true
validate :validate_emails
+ validate :validate_variables, if: -> { query_id_changed? }
before_validation :set_state
before_validation :fix_emails
@@ -84,5 +85,11 @@ module Blazer
errors.add(:base, "Invalid emails")
+
+ def validate_variables
+ if query.variables.any?
+ errors.add(:base, "Query can't have variables")
+ end
@@ -23,5 +23,9 @@ module Blazer
editable &&= Blazer.query_editable.call(self, user) if Blazer.query_editable
editable
+ def variables
+ Blazer.extract_vars(statement)
@@ -88,6 +88,12 @@ module Blazer
+ def self.extract_vars(statement)
+ # strip commented out lines
+ # and regex {1} or {1,2}
+ statement.gsub(/\-\-.+/, "").gsub(/\/\*.+\*\//m, "").scan(/\{\w*?\}/i).map { |v| v[1...-1] }.reject { |v| /\A\d+(\,\d+)?\z/.match(v) || v.empty? }.uniq
def self.run_checks(schedule: nil)
checks = Blazer::Check.includes(:query)
checks = checks.where(schedule: schedule) if schedule
@@ -28,7 +28,7 @@ module Blazer
audit.save! if audit.changed?
- if query && !result.timed_out?
+ if query && !result.timed_out? && !query.variables.any?
query.checks.each do |check|
check.update_state(result)