Skip to content

Instantly share code, notes, and snippets.

@ZuBB
Created Aug 30, 2013
Embed
What would you like to do?
sqlite3-ruby issue
#!/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','neurogeek@gentoo.org','',8);
INSERT INTO "tmp_package_maintainers" VALUES(11,'','neurogeek@gentoo.org','',17);
INSERT INTO "tmp_package_maintainers" VALUES(26,'Jesus Rivero','neurogeek@gentoo.org','',57);
SQL
query = <<-SQL
select name, count(name) as c
from tmp_package_maintainers
where LOWER(email) like '%?%' 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, 'neurogeek@gentoo.org')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment