Fix "prepared statements" errors

See https://coderwall.com/p/45ombq
This commit is contained in:
Jonne Haß 2013-08-31 17:56:19 +02:00
parent dfa0245f4b
commit 2f1193fa36
3 changed files with 8 additions and 6 deletions

View file

@ -83,8 +83,10 @@ class ConversationsController < ApplicationController
def new
all_contacts_and_ids = Contact.connection.select_rows(
current_user.contacts.where(:sharing => true).joins(:person => :profile).
select("contacts.id, profiles.first_name, profiles.last_name, people.diaspora_handle").to_sql
Contact.connection.unprepared_statement {
current_user.contacts.where(:sharing => true).joins(:person => :profile).
select("contacts.id, profiles.first_name, profiles.last_name, people.diaspora_handle").to_sql
}
).map{|r| {:value => r[0], :name => Person.name_from_attrs(r[1], r[2], r[3]).gsub(/(")/, "'")} }
@contact_ids = ""

View file

@ -27,7 +27,7 @@ module User::Querying
opts[:klass] = klass
opts[:by_members_of] ||= self.aspect_ids
post_ids = klass.connection.select_values(visible_shareable_sql(klass, opts)).map { |id| id.to_i }
post_ids = klass.connection.select_values(visible_shareable_sql(klass, opts)).map(&:to_i)
post_ids += klass.connection.select_values("#{construct_public_followings_sql(opts).to_sql} LIMIT #{opts[:limit]}").map {|id| id.to_i }
end
@ -88,9 +88,9 @@ module User::Querying
end
def construct_shareable_from_self_query(opts)
conditions = {:pending => false }
conditions = {:pending => false, :author_id => self.person_id }
conditions[:type] = opts[:type] if opts.has_key?(:type)
query = self.person.send(opts[:klass].to_s.tableize).where(conditions)
query = opts[:klass].where(conditions)
if opts[:by_members_of]
query = query.joins(:aspect_visibilities).where(:aspect_visibilities => {:aspect_id => opts[:by_members_of]})

View file

@ -6,7 +6,7 @@ module EvilQuery
end
def id_sql(relation, id_column)
relation.select(id_column).to_sql
@class.connection.unprepared_statement { relation.select(id_column).to_sql }
end
end