Created
March 3, 2014 23:10
-
-
Save MonicaDev/9336595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sqlite3' | |
| $db = SQLite3::Database.open "congress_poll_results.db" #This is telling how to open the db file. It's in SQlite3 gem. .open command. | |
| def print_arizona_reps | |
| puts "AZ REPRESENTATIVES" | |
| az_reps = $db.execute("SELECT name FROM congress_members WHERE location = 'AZ'") #This is querying the db. | |
| az_reps.each { |rep| puts rep } #looping and putsing each AZ rep. | |
| end | |
| def print_longest_serving_reps(minimum_years) #sorry guys, oracle needs me, i didn't finish this! | |
| puts "LONGEST SERVING REPRESENTATIVES" | |
| puts $db.execute("SELECT name, years_in_congress FROM congress_members WHERE years_in_congress > #{minimum_years}") | |
| end | |
| def print_lowest_grade_level_speakers(minimum_grade) | |
| puts "LOWEST GRADE LEVEL SPEAKERS" | |
| puts $db.execute("SELECT name, location FROM congress_members WHERE grade_current < #{minimum_grade}") | |
| end | |
| def print_separator | |
| puts | |
| puts "------------------------------------------------------------------------------" | |
| puts | |
| end | |
| #Driver test code------ | |
| print_arizona_reps | |
| print_separator | |
| print_longest_serving_reps(35) | |
| print_separator | |
| print_lowest_grade_level_speakers(8.0) | |
| ##### BONUS ####### | |
| # TODO (bonus) - Stop SQL injection attacks! Statmaster learned that interpolation of variables in SQL statements leaves some security vulnerabilities. Use the google to figure out how to protect from this type of attack. | |
| # TODO (bonus) | |
| # Create a listing of all of the Politicians and the number of votes they recieved | |
| # output should look like: Sen. John McCain - 7,323 votes (This is an example, yours will not return this value, it should just | |
| # have a similar format) | |
| # Create a listing of each Politician and the voter that voted for them | |
| # output should include the senators name, then a long list of voters separated by a comma | |
| # | |
| # * you'll need to do some join statements to complete these last queries!ma |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment