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