lib/qooxview/storages/sqlite.rb in qooxview-1.9.10 vs lib/qooxview/storages/sqlite.rb in qooxview-1.9.11
- old
+ new
@@ -9,19 +9,22 @@
require 'active_record/base'
require 'logger'
class SQLite < StorageType
- attr :db_class
+ attr :db_class, :db_file
def configure(config, name_base = 'stsql', name_file = 'sql.db')
dputs(2) { "Configuring SQLite with #{@name}" }
@db_table = "#{name_base}_#{@name.downcase}s"
@db_class_name = "#{name_base.capitalize}_#{@name.downcase}"
@db_class = nil
- %x[ mkdir -p data ]
+ @sqlite_dir = File.join($data_dir, get_config('data',
+ :StorageType, :data_dir))
+ FileUtils.mkdir_p(@sqlite_dir)
@name_file = name_file
+ @db_file = File.join(@sqlite_dir, @name_file)
# ActiveRecord::Base.logger = Logger.new('debug.log')
ActiveRecord::Migration.verbose = false
#ActiveRecord::Base.logger = Logger.new(STDERR)
@mutex_es = Mutex.new
@@ -32,19 +35,19 @@
super config
end
# Allows for debugging when wanting to load another db
def close_db
- dputs(4){"Closing db #{@name_file}"}
+ dputs(4) { "Closing db #{@name_file}" }
ActiveRecord::Base.remove_connection
end
def open_db
@mutex_es.synchronize {
- dputs(4) { "Opening connection to #{@name_file}" }
+ dputs(4) { "Opening connection to #{@name_file} - #{@sqlite_dir}" }
ActiveRecord::Base.establish_connection(
- :adapter => 'sqlite3', :database => "data/#{@name_file}")
+ :adapter => 'sqlite3', :database => @db_file)
dputs(4) { 'Initializing tables' }
init_table
dputs(4) { 'Getting Base' }
@@ -73,11 +76,16 @@
@mutex_es.synchronize {
dputs(5) { "Searching id #{data.inspect}" }
if @entries[data]
@entries[data].save
end
- @entries[data] ||= @db_class.first(:conditions => {@data_field_id => data})
+ dat = @db_class.first(data).first
+ # dat = @db_class.first(:conditions => {@data_field_id => data})
+ # dp @entries[data]
+ # dp dat
+ # dp data
+ @entries[data] ||= dat
if entry = @entries[data]
entry.send("#{field}=", value)
@entries_save[data] = entry
return value
else
@@ -100,10 +108,11 @@
data[@data_field_id] = new_id
dputs(5) { "Creating data: #{e.inspect}" }
end
def init_table
+ # dputs_func
db_table, fields = @db_table, @fields
dputs(3) { "Initializing #{@db_class_name} with db_table=#{db_table.inspect}" }
ActiveRecord::Schema.define do
new_table = false
if !table_exists? db_table
@@ -123,10 +132,12 @@
add_column(db_table, f, :integer)
when /bool/
add_column(db_table, f, :boolean)
when /float/
add_column(db_table, f, :float)
+ when /date/
+ add_column(db_table, f, :date)
else
add_column(db_table, f, :string)
end
end
}
@@ -184,10 +195,17 @@
sql.open_db
}
dputs(2) { 'Loading all dbs' }
RPCQooxdooService.entities { |e|
e.is_loaded = false
- e.load
+ }
+ RPCQooxdooService.entities { |e|
+ unless e.is_loaded
+ e.loading = true
+ e.load
+ e.loading = false
+ u = Users.match_by_name('local')
+ end
}
end
def self.dbs_open_load_migrate
SQLite.dbs_open_load