diff options
-rw-r--r-- | lib/sisu/v2/db_select.rb | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/sisu/v2/db_select.rb b/lib/sisu/v2/db_select.rb index 1ac9195f..87452c5c 100644 --- a/lib/sisu/v2/db_select.rb +++ b/lib/sisu/v2/db_select.rb @@ -61,16 +61,30 @@ module SiSU_DB_select class Case def initialize(opt,conn='',sql_type='pg') @opt,@conn,@sql_type=opt,conn,sql_type - @file=sql_maintenance_file @db=SiSU_Env::Info_db.new + @file=sql_maintenance_file @sdb=SiSU_DB_DBI::Create.new(@opt,@conn,@file,@sql_type) # db_dbi.rb @sdb_index=SiSU_DB_DBI::Index.new(@opt,@conn,@file,@sql_type) # db_dbi.rb @sdb_no=SiSU_DB_DBI::Drop.new(@opt,@conn,@db,@sql_type) # db_dbi.rb if @opt.mod.inspect =~/update|import/ @sdb_import=SiSU_DB_DBI::Import.new(@opt,@conn,@file,@sql_type) - @sdb_remove_doc=SiSU_DB_DBI::Remove.new(@opt,@conn,@file) + @sdb_remove_doc=SiSU_DB_DBI::Remove.new(@opt,@conn,@file,@sql_type) elsif @opt.mod.inspect =~/remove/ - @sdb_remove_doc=SiSU_DB_DBI::Remove.new(@opt,@conn,@file) + @sdb_remove_doc=SiSU_DB_DBI::Remove.new(@opt,@conn,@file,@sql_type) + end + end + def db_exist? + if @sql_type=='sqlite' \ + and (not (FileTest.file?(@db.sqlite.db)) or FileTest.zero?(@db.sqlite.db)) + puts %{no connection with #{@sql_type} database established, createdb "#{@db.sqlite.db}"?} + exit + end + if @conn.class==NilClass + db=@sql_type=='sqlite' \ + ? @db.sqlite.db \ + : @db.psql.db + puts %{no connection with #{@sql_type} database established, createdb "#{db}"?} + exit end end def sql_maintenance_file @@ -109,7 +123,7 @@ module SiSU_DB_select @sdb_index.create_indexes rescue; SiSU_Errors::Info_error.new($!,$@,'-D').error; @sdb.output_dir? end - when /^--createtable(s)?$/ + when /^--createtables?$/ @sdb.output_dir? begin @sdb.create_table.metadata_and_text @@ -147,6 +161,7 @@ module SiSU_DB_select rescue; @sdb.output_dir? end when /^--import$/ + db_exist? @sdb_import.marshal_load tell=case @sql_type when /sqlite/; SiSU_Screen::Ansi.new(@opt.cmd,"sqlite #{@db.sqlite.db} database?") @@ -155,19 +170,25 @@ module SiSU_DB_select end tell.puts_grey if @opt.cmd =~/v/ when /^--update$/ + db_exist? @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 /^--remove$/ + db_exist? @sdb_remove_doc.remove when /^--index$/ + db_exist? @sdb_index.create_indexes when /^droptable(s)?$/ + db_exist? @sdb_no.drop.tables when /^--dropindex(es)?$/ + db_exist? @sdb_no.drop.indexes when /^--(?:dropall|drop)$/ + db_exist? @sdb_no.drop.tables when /^--(?:db=)?(?:(?:sq)?lite|pg(?:sql)?|my(?:sql)?)$/ else |