Created
October 18, 2013 13:29
-
-
Save ZuBB/7041565 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'sqlite3' | |
database = SQLite3::Database.new('/tmp/test_db.sqlite') | |
table_def = <<-SQL | |
CREATE TABLE tmp_package_maintainers ( | |
id INTEGER, | |
name VARCHAR, | |
email VARCHAR, | |
role VARCHAR, | |
package_id INTEGER, | |
PRIMARY KEY (id) | |
) | |
SQL | |
table_data = <<-SQL | |
INSERT INTO "tmp_package_maintainers" VALUES(6,'Jesus Rivero','[email protected]','',8); | |
INSERT INTO "tmp_package_maintainers" VALUES(11,'','[email protected]','',17); | |
INSERT INTO "tmp_package_maintainers" VALUES(26,'Jesus Rivero','[email protected]','',57); | |
SQL | |
query = <<-SQL | |
select name, count(name) as c | |
from tmp_package_maintainers | |
where email = ? and name != '' | |
group by name | |
order by c desc | |
limit 1; | |
SQL | |
database.execute_batch(table_def) | |
database.execute_batch(table_data) | |
database.execute(query, '[email protected]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment