class SaganCrafter::Backends::SQLite
create temp view merge_fqdns as select * from F.fqdns union select * from M.fqdns union select * from O.fqdns; select DISTINCT count(*) as cnt, max(sub1.import_time) as max_import_time, sub1.name, sub1.feed_name, sub1.feed_provider from (select * from F.fqdns union select * from M.fqdns union select * from O.fqdns) sub1 group by sub1.name;
Attributes
rule_collection[R]
Public Class Methods
new(factory, existing_db_connection = nil)
click to toggle source
# File lib/sagan_crafter/backends/sqlite.rb, line 20 def initialize(factory, existing_db_connection = nil) if existing_db_connection @db = existing_db_connection else @db = connect(SaganCrafter::Settings.sql_file_location) end @factory = factory @db.results_as_hash = true @rule_collection = [] end
Public Instance Methods
build()
click to toggle source
# File lib/sagan_crafter/backends/sqlite.rb, line 44 def build @db.execute("select DISTINCT count(*) as cnt, max(import_time) as max_import_time, name, feed_name, feed_provider from #{SaganCrafter::Settings.sql_table_name} group by name") do |row| @rule_collection << @factory.rule(row["name"], row["feed_provider"], row["feed_name"], row["cnt"], row["max_import_time"]) end @rule_collection end
size()
click to toggle source
# File lib/sagan_crafter/backends/sqlite.rb, line 31 def size count = @db.get_first_value("select count(DISTINCT name) from #{SaganCrafter::Settings.sql_table_name}") puts "count(*): #{count}" if SaganCrafter::Settings.verbose count end
to_s()
click to toggle source
# File lib/sagan_crafter/backends/sqlite.rb, line 51 def to_s @rule_collection.to_s end
validate!()
click to toggle source
# File lib/sagan_crafter/backends/sqlite.rb, line 37 def validate! @db.execute("PRAGMA table_info(#{SaganCrafter::Settings.sql_table_name});") do |row| raise UnknownDBSchemaError, "Unknown Schema" unless ["id","feed_provider","feed_name", "import_time","name"].include? row["name"] end puts "#[sagan-crafter] schema validated" if SaganCrafter::Settings.verbose end
Private Instance Methods
connect(file)
click to toggle source
# File lib/sagan_crafter/backends/sqlite.rb, line 57 def connect(file) begin db = SQLite3::Database.open(file) return db rescue ::SQLite3::Exception => e puts "Exception occurred" puts e db.close if db end end