Browse Source

Use bound parameters

tags/last-sinatra-version
Adrian Short 11 years ago
parent
commit
54fa2cf1c3
1 changed files with 11 additions and 11 deletions
  1. +11
    -11
      app.rb

+ 11
- 11
app.rb View File

@@ -91,10 +91,10 @@ get '/bodies/:body/elections/:date' do
@total_districts = repository(:default).adapter.select(" @total_districts = repository(:default).adapter.select("
SELECT district_id SELECT district_id
FROM candidacies FROM candidacies
WHERE election_id = #{@election.id}
WHERE election_id = ?
GROUP BY district_id GROUP BY district_id
ORDER BY district_id ORDER BY district_id
").count
", @election.id).count


@results_by_party = repository(:default).adapter.select(" @results_by_party = repository(:default).adapter.select("
SELECT SELECT
@@ -108,12 +108,12 @@ get '/bodies/:body/elections/:date' do


LEFT JOIN parties p ON p.id = c.party_id LEFT JOIN parties p ON p.id = c.party_id


WHERE c.election_id = #{@election.id}
WHERE c.election_id = ?


GROUP BY c.party_id, p.colour, p.name GROUP BY c.party_id, p.colour, p.name


ORDER BY seatz DESC, votez DESC ORDER BY seatz DESC, votez DESC
")
", @election.id)


@results_by_district = repository(:default).adapter.select(" @results_by_district = repository(:default).adapter.select("
SELECT SELECT
@@ -127,12 +127,12 @@ get '/bodies/:body/elections/:date' do


WHERE WHERE
c.district_id = d.id c.district_id = d.id
AND c.election_id = #{@election.id}
AND c.election_id = ?


GROUP BY c.district_id, d.name, d.slug GROUP BY c.district_id, d.name, d.slug


ORDER BY d.name ORDER BY d.name
")
", @election.id)
haml :electionsummary haml :electionsummary
end end
@@ -187,10 +187,10 @@ get '/candidates/:id/?' do
INNER JOIN districts d INNER JOIN districts d
ON c.district_id = d.id ON c.district_id = d.id
WHERE c.candidate_id = #{@candidate.id}
WHERE c.candidate_id = ?
ORDER BY d ORDER BY d
")
", @candidate.id)
haml :candidate haml :candidate
else else
@@ -227,13 +227,13 @@ get '/bodies/:body/elections/:date/:districts_name/:district' do
LEFT JOIN parties p LEFT JOIN parties p
ON c.party_id = p.id ON c.party_id = p.id
WHERE c.district_id = #{@district.id}
AND c.election_id = #{@election.id}
WHERE c.district_id = ?
AND c.election_id = ?
GROUP BY p.name, p.colour GROUP BY p.name, p.colour
ORDER BY total_votes DESC ORDER BY total_votes DESC
")
", @district.id, @election.id)
haml :resultsdistrict haml :resultsdistrict
end end


Loading…
Cancel
Save