Commit 5799d21b4cb6d0c7e998d44db20b271a4a8f2b9e
1 parent
f5dfa78b
Exists in
master
and in
1 other branch
use ActiveRecord quoting for table, column names
Showing
1 changed file
with
8 additions
and
10 deletions
Show diff stats
app/models/choice.rb
@@ -70,7 +70,11 @@ class Choice < ActiveRecord::Base | @@ -70,7 +70,11 @@ class Choice < ActiveRecord::Base | ||
70 | 70 | ||
71 | def compute_score! | 71 | def compute_score! |
72 | self.score = compute_score | 72 | self.score = compute_score |
73 | - Choice.connection.execute("UPDATE `choices` SET `score` = #{self.score}, `updated_at` = '#{Time.now.utc.to_s(:db)}' WHERE `id` = #{self.id}") | 73 | + Choice.connection = conn |
74 | + conn.execute("UPDATE #{conn.quote_table_name('choices')} SET | ||
75 | + #{conn.quote_column_name('score')} = #{self.score}, | ||
76 | + #{conn.quote_column_name('updated_at')} = '#{Time.now.utc.to_s(:db)}' WHERE | ||
77 | + #{conn.quote_column_name('id')} = #{self.id}") | ||
74 | end | 78 | end |
75 | 79 | ||
76 | def user_created | 80 | def user_created |
@@ -127,18 +131,12 @@ class Choice < ActiveRecord::Base | @@ -127,18 +131,12 @@ class Choice < ActiveRecord::Base | ||
127 | previous_choices.each do |l| | 131 | previous_choices.each do |l| |
128 | inserts.push("(NULL, #{self.question_id}, NULL, #{l.id}, '#{timestring}', '#{timestring}', NULL, 0, #{self.id}, NULL, NULL)") | 132 | inserts.push("(NULL, #{self.question_id}, NULL, #{l.id}, '#{timestring}', '#{timestring}', NULL, 0, #{self.id}, NULL, NULL)") |
129 | end | 133 | end |
130 | - sql = "INSERT INTO `prompts` (`algorithm_id`, `question_id`, `voter_id`, `left_choice_id`, `created_at`, `updated_at`, `tracking`, `votes_count`, `right_choice_id`, `active`, `randomkey`) VALUES #{inserts.join(', ')}" | 134 | + conn = Prompts.connection |
135 | + sql = "INSERT INTO #{conn.quote_table_name('prompts')} (#{conn.quote_column_name('algorithm_id')}, #{conn.quote_column_name('question_id')}, #{conn.quote_column_name('voter_id')}, #{conn.quote_column_name('left_choice_id')}, #{conn.quote_column_name('created_at')}, #{conn.quote_column_name('updated_at')}, #{conn.quote_column_name('tracking')}, #{conn.quote_column_name('votes_count')}, #{conn.quote_column_name('right_choice_id')}, #{conn.quote_column_name('active')}, #{conn.quote_column_name('randomkey')}) VALUES #{inserts.join(', ')}" | ||
131 | 136 | ||
132 | Question.update_counters(self.question_id, :prompts_count => 2*previous_choices.size) | 137 | Question.update_counters(self.question_id, :prompts_count => 2*previous_choices.size) |
133 | 138 | ||
134 | 139 | ||
135 | - ActiveRecord::Base.connection.execute(sql) | ||
136 | - | ||
137 | -#VALUES (NULL, 108, NULL, 1892, '2010-03-16 11:12:37', '2010-03-16 11:12:37', NULL, 0, 1893, NULL, NULL) | ||
138 | -# INSERT INTO `prompts` (`algorithm_id`, `question_id`, `voter_id`, `left_choice_id`, `created_at`, `updated_at`, `tracking`, `votes_count`, `right_choice_id`, `active`, `randomkey`) VALUES(NULL, 108, NULL, 1892, '2010-03-16 11:12:37', '2010-03-16 11:12:37', NULL, 0, 1893, NULL, NULL) | ||
139 | - #previous_choices.each { |c| | ||
140 | - # question.prompts.create!(:left_choice => c, :right_choice => self) | ||
141 | - # question.prompts.create!(:left_choice => self, :right_choice => c) | ||
142 | - #} | 140 | + conn.execute(sql) |
143 | end | 141 | end |
144 | end | 142 | end |