aboutsummaryrefslogtreecommitdiff
path: root/web/lib
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2013-01-11 12:02:51 +0100
committerJochen Topf <jochen@topf.org>2013-01-11 12:02:51 +0100
commit71e1327b05eae06a39128b1bd288c4685861ab10 (patch)
tree34a6ef9e46f03bd09527a1827d85fadad0abccec /web/lib
parent3df767aa62268e209a4c0749f82aa594919a0af5 (diff)
downloadtaginfo-71e1327b05eae06a39128b1bd288c4685861ab10.tar
taginfo-71e1327b05eae06a39128b1bd288c4685861ab10.tar.gz
Changed database initialization code.
All sources are now automatically attached.
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/sql.rb32
1 files changed, 26 insertions, 6 deletions
diff --git a/web/lib/sql.rb b/web/lib/sql.rb
index 4bfb020..7240f05 100644
--- a/web/lib/sql.rb
+++ b/web/lib/sql.rb
@@ -6,20 +6,40 @@ module SQL
# Wrapper for a database connection.
class Database
- def initialize(dir)
- filename = dir + '/taginfo-master.db'
- @db = SQLite3::Database.new(filename)
- @db.results_as_hash = true
+ # This has to be called once to initialize the context for the database
+ def self.init(dir)
+ @@dir = dir
- [:db, :wiki, :josm, :potlatch, :merkaartor, :search].each do |dbname|
- @db.execute("ATTACH DATABASE '#{dir}/taginfo-#{dbname}.db' AS #{dbname}")
+ db = SQL::Database.new
+
+ db.select('SELECT * FROM sources ORDER BY no').execute().each do |source|
+ Source.new(source['id'], source['name'], source['data_until'], source['update_start'], source['update_end'], source['visible'].to_i == 1)
end
+ data_until = db.select("SELECT min(data_until) FROM sources").get_first_value().sub(/:..$/, '')
+
+ db.close
+
+ data_until
+ end
+
+ def initialize
+ filename = @@dir + '/taginfo-master.db'
+ @db = SQLite3::Database.new(filename)
+ @db.results_as_hash = true
+
@db.execute('SELECT * FROM languages') do |row|
Language.new(row)
end
end
+ def attach_sources
+ Source.each do |source|
+ @db.execute("ATTACH DATABASE ? AS ?", "#{ @@dir }/#{ source.dbname }", source.id.to_s)
+ end
+ self
+ end
+
def close
@db.close
@db = nil