aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/db_select.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v0/db_select.rb')
-rw-r--r--lib/sisu/v0/db_select.rb46
1 files changed, 35 insertions, 11 deletions
diff --git a/lib/sisu/v0/db_select.rb b/lib/sisu/v0/db_select.rb
index 0b456262..002f0039 100644
--- a/lib/sisu/v0/db_select.rb
+++ b/lib/sisu/v0/db_select.rb
@@ -63,14 +63,31 @@ module SiSU_DB_select
class Case
def initialize(opt,conn='',sql_type='pg')
@opt,@conn,@sql_type=opt,conn,sql_type
+#@conn.execute("BEGIN;")
#@sdb=Create.new(@conn)
- @sdb=SiSU_DB_DBI::Create.new(@opt,@conn,@sql_type)
- @index=SiSU_DB_DBI::Index.new(@opt,@conn,@sql_type)
- @sdb_no=SiSU_DB_DBI::Drop.new(@opt,@conn,@sql_type)
- @sdb_import=SiSU_DB_DBI::Import.new(@opt,@conn,@sql_type) if @opt.mod.inspect =~/update|import/
- @remove=SiSU_DB_DBI::Remove.new(@opt,@conn) if @opt.mod.inspect =~/update|remove/
+ @file=sql_maintenance_file
+ @sdb=SiSU_DB_DBI::Create.new(@opt,@conn,@file,@sql_type)
+ @sdb_index=SiSU_DB_DBI::Index.new(@opt,@conn,@file,@sql_type)
+ @sdb_no=SiSU_DB_DBI::Drop.new(@opt,@conn,@file,@sql_type)
+ @sdb_import=SiSU_DB_DBI::Import.new(@opt,@conn,@file,@sql_type) if @opt.mod.inspect =~/update|import/
+ @sdb_remove_doc=SiSU_DB_DBI::Remove.new(@opt,@conn,@file) if @opt.mod.inspect =~/update|remove/
@db=SiSU_Env::Info_db.new
end
+ def sql_maintenance_file
+ file=if @opt.inspect =~/M/
+ x=if @opt.fns and not @opt.fns.empty?
+ @env=SiSU_Env::Info_env.new(@opt.fns) if @opt.fns
+ puts "\n#{@env.path.sqlite}/#{@opt.fns}.sql"
+ @db=SiSU_Env::Info_db.new
+ @job="sqlite3 #{@db.sqlite.db} < #{@env.path.sqlite}/#{@opt.fns}.sql"
+ File.new("#{@env.path.sqlite}/#{@opt.fns}.sql",'w+')
+ elsif @opt.fns and @opt.fns.inspect =~/create/; nil #sort variations later
+ else nil
+ end
+ else nil
+ end
+ file
+ end
def cases
@opt.mod.each do |mod|
case mod
@@ -84,13 +101,14 @@ module SiSU_DB_select
@sdb.output_dir?
#@sdb.create_db
begin
+ #@sdb.create_db
@sdb.create_table.metadata
@sdb.create_table.documents
@sdb.create_table.endnotes
@sdb.create_table.endnotes_asterisk
@sdb.create_table.endnotes_plus
@sdb.create_table.urls
- @index.create_indexes
+ @sdb_index.create_indexes
rescue; SiSU_Errors::Info_error.new($!,$@,'-D').error; @sdb.output_dir?
end
when /^--createtable(s)?$/
@@ -102,7 +120,7 @@ module SiSU_DB_select
@sdb.create_table.endnotes_asterisk
@sdb.create_table.endnotes_plus
@sdb.create_table.urls
- @index.create_indexes
+ @sdb_index.create_indexes
rescue; @sdb.output_dir?
end
when /^--recreate$/
@@ -115,7 +133,7 @@ module SiSU_DB_select
@sdb.create_table.endnotes_asterisk
@sdb.create_table.endnotes_plus
@sdb.create_table.urls
- @index.create_indexes
+ @sdb_index.create_indexes
rescue; @sdb.output_dir?
end
when /^--cr(eate)?lex$/
@@ -139,14 +157,14 @@ module SiSU_DB_select
end
tell.puts_grey if @opt.cmd =~/v/
when /^--remove$/
- @remove.remove
+ @sdb_remove_doc.remove
when /^--update$/
- @remove.remove
+ @sdb_remove_doc.remove
@sdb_import.marshal_load
tell=SiSU_Screen::Ansi.new(@opt.cmd,"pgaccess or psql #{@db.psql.db} database?")
tell.puts_grey if @opt.cmd =~/v/
when /^--index$/
- @index.create_indexes
+ @sdb_index.create_indexes
when /^droptable(s)?$/
@sdb_no.drop.tables
when /^--dropindex(es)?$/
@@ -160,6 +178,12 @@ module SiSU_DB_select
help.summary
help.commands
end
+ if @opt.cmd =~/M/
+ #@conn.commit
+ #@conn.disconnect
+ puts @job
+ #system(@job)
+ end
end
begin
@conn.commit if @sql_type =~/sqlite/