when i run a complicated sql query from the command line like this
sqlite3 db/development.sqlite3 < queries.sql
i get a result like this
Competency Name|Component Name|3.77|4.0|0.23
Another Competency Name|Another Component Name|3.77|4.0|0.23
which i can easily parse like this
hidden_strengh_strings = results.split("\n")[1..-1];
hidden_strengh_strings.each do |hidden_strength_string|
hidden_strengh_values = hidden_strength_string.split("|");
hidden_strength = {}
hidden_strength.merge!(:competency => hidden_strengh_values[0]);
hidden_strength.merge!(:component => hidden_strengh_values[1]);
hidden_strength.merge!(:reviewer_average_score => hidden_strengh_values[2]);
hidden_strength.merge!(:reviewee_average_score => hidden_strengh_values[3]);
hidden_strength.merge!(:exceedance => hidden_strengh_values[4]);
hidden_strengths << hidden_strength
end
but i have no idea how to get these results from within ActiveRecord.
results = ActiveRecord::Base.connection.execute(File.open(Rails.root.join('queries.sql'), 'r') { |f| f.read } );
doesn’t seem to do what i want it to.
i’d be happy to take any approach to solve this problem. even rewriting the sql from within the ActiveRecord DSL. but i need help finding the right direction.
thanks : )
Nishant lead me to the solution.
Works fine its just that the query started with:
so exec ended at the semicolon.
Thanks!