From 307ecb4df591aa675b71839014debf6e81d462e1 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 18 May 2014 08:49:03 -0400 Subject: v5 v6: db, use symbols to identify sql engine --- lib/sisu/v5/db_create.rb | 16 ++++++++-------- lib/sisu/v5/db_drop.rb | 8 ++++---- lib/sisu/v5/db_import.rb | 10 +++++----- lib/sisu/v5/db_indexes.rb | 4 ++-- lib/sisu/v5/db_remove.rb | 2 +- lib/sisu/v5/db_select.rb | 16 ++++++++-------- lib/sisu/v5/dbi.rb | 16 ++++++++-------- lib/sisu/v5/dbi_discrete.rb | 10 +++++----- lib/sisu/v6/db_create.rb | 16 ++++++++-------- lib/sisu/v6/db_drop.rb | 8 ++++---- lib/sisu/v6/db_import.rb | 10 +++++----- lib/sisu/v6/db_indexes.rb | 4 ++-- lib/sisu/v6/db_remove.rb | 2 +- lib/sisu/v6/db_select.rb | 16 ++++++++-------- lib/sisu/v6/dbi.rb | 16 ++++++++-------- lib/sisu/v6/dbi_discrete.rb | 12 ++++++------ 16 files changed, 83 insertions(+), 83 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/db_create.rb b/lib/sisu/v5/db_create.rb index 4de362c5..d558aacd 100644 --- a/lib/sisu/v5/db_create.rb +++ b/lib/sisu/v5/db_create.rb @@ -66,10 +66,10 @@ module SiSU_DbCreate class Create < SiSU_DbColumns::Columns require_relative 'sysenv' # sysenv.rb @@dl=nil - def initialize(opt,conn,file,sql_type='pg') + def initialize(opt,conn,file,sql_type=:pg) @opt,@conn,@file,@sql_type=opt,conn,file,sql_type @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX - @comment=(@sql_type=='pg') \ + @comment=(@sql_type==:pg) \ ? (SiSU_DbCreate::Comment.new(@conn,@sql_type)) : nil @@dl ||=SiSU_Env::InfoEnv.new.digest.length @@ -84,7 +84,7 @@ module SiSU_DbCreate end def create_db @env=SiSU_Env::InfoEnv.new(@opt.fns) - tell=(@sql_type=='sqlite') \ + tell=(@sql_type==:sqlite) \ ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create SQLite db tables in:',%{"#{@file}"}) : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create pgSQL db tables in:',%{"#{Db[:name_prefix]}#{@env.path.stub_pwd}"}) if (@opt.act[:verbose][:set]==:on \ @@ -92,7 +92,7 @@ module SiSU_DbCreate || @opt.act[:maintenance][:set]==:on) tell.dark_grey_title_hi end - SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type=='pg' #watch use of path.stub_pwd instead of stub + SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type==:pg #watch use of path.stub_pwd instead of stub end def output_dir? dir=SiSU_Env::InfoEnv.new('') @@ -105,7 +105,7 @@ module SiSU_DbCreate if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ - currently using sisu dbi module + currently using sisu_dbi module to be populated from document files create tables metadata_and_text data import through ruby transfer @@ -343,7 +343,7 @@ module SiSU_DbCreate if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ - currently using sisu dbi module + currently using sisu_dbi module to be populated from doc_objects files create tables urls data import through ruby transfer @@ -377,9 +377,9 @@ module SiSU_DbCreate end end class Comment < SiSU_DbColumns::Columns - def initialize(conn,sql_type='pg') + def initialize(conn,sql_type=:pg) @conn=conn - if sql_type =~ /pg/; psql + if sql_type == :pg then psql end end def psql diff --git a/lib/sisu/v5/db_drop.rb b/lib/sisu/v5/db_drop.rb index b1ff634e..1a76eff9 100644 --- a/lib/sisu/v5/db_drop.rb +++ b/lib/sisu/v5/db_drop.rb @@ -64,11 +64,11 @@ module SiSU_DbDrop class Drop require_relative 'response' # response.rb - def initialize(opt,conn,db_info,sql_type='') + def initialize(opt,conn,db_info,sql_type) @opt,@conn,@db_info,@sql_type=opt,conn,db_info,sql_type @ans=SiSU_Response::Response.new case @sql_type - when /sqlite/ + when :sqlite cascade='' else cascade='CASCADE' @@ -87,7 +87,7 @@ module SiSU_DbDrop begin msg_sqlite="as not all disk space is recovered after dropping the database << #{@db_info.sqlite.db} >>, you may be better off deleting the file, and recreating it as necessary" case @sql_type - when /sqlite/ + when :sqlite puts msg_sqlite ans=@ans.response?('remove sql database?') if ans \ @@ -129,7 +129,7 @@ module SiSU_DbDrop end rescue case @sql_type - when /sqlite/ + when :sqlite ans=@ans.response?('remove sql database?') if ans and File.exist?(@db_info.sqlite.db); File.unlink(@db_info.sqlite.db) end diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 0dc5a29b..3d0b7f8c 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -72,7 +72,7 @@ module SiSU_DbImport @@dl=nil @@hname=nil attr_accessor :tp - def initialize(opt,conn,file_maint,sql_type='pg') + def initialize(opt,conn,file_maint,sql_type=:pg) @opt,@conn,@file_maint,@sql_type=opt,conn,file_maint,sql_type @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX @env=SiSU_Env::InfoEnv.new(@opt.fns) @@ -90,7 +90,7 @@ module SiSU_DbImport @col[:ocn]='' @counter={} @db=SiSU_Env::InfoDb.new - if @sql_type=='sqlite' + if @sql_type==:sqlite @driver_sqlite3=(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \ ? true : false @@ -136,7 +136,7 @@ module SiSU_DbImport WHERE metadata_and_text.src_filename = '#{@md.fns}' AND metadata_and_text.language_document_char = '#{@opt.lng}' ;} # note, for .ssm: @md.fns (is set during runtime & is) != @opt.fns @md.opt.fns - file_exist=@sql_type=~/sqlite/ \ + file_exist=@sql_type==:sqlite \ ? @conn.get_first_value(select_first_match) : @conn.select_one(select_first_match) if not file_exist @@ -152,7 +152,7 @@ module SiSU_DbImport puts @conn.driver if defined? @conn.driver end begin #% sql - if @sql_type=~/sqlite/ + if @sql_type==:sqlite @conn.transaction do |conn| t_d.each do |sql| conn.execute(sql) @@ -497,7 +497,7 @@ module SiSU_DbImport @env=SiSU_Env::InfoEnv.new(@md.fns) @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" txt=endnotes(txt).extract_any - if @sql_type=~/pg/ \ + if @sql_type==:pg \ and txt.size > (SiSU_DbColumns::ColumnSize.new.document_clean - 1) # examine pg build & remove limitation puts "\n\nTOO LARGE (TXT - see error log)\n\n" open("#{Dir.pwd}/pg_documents_error_log",'a') do |error| diff --git a/lib/sisu/v5/db_indexes.rb b/lib/sisu/v5/db_indexes.rb index 0fa51b3f..8a269a4c 100644 --- a/lib/sisu/v5/db_indexes.rb +++ b/lib/sisu/v5/db_indexes.rb @@ -62,8 +62,8 @@ =end module SiSU_DbIndex - class Index # create documents Indexes def initialize(opt,conn='',sql_type='') - def initialize(opt,conn,file,sql_type='') + class Index # create documents Indexes def initialize(opt,conn='',sql_type) + def initialize(opt,conn,file,sql_type) @opt,@conn,@file,@sql_type=opt,conn,file,sql_type end def create_indexes # check added from pg not tested diff --git a/lib/sisu/v5/db_remove.rb b/lib/sisu/v5/db_remove.rb index 9ffba024..9a7ea8ea 100644 --- a/lib/sisu/v5/db_remove.rb +++ b/lib/sisu/v5/db_remove.rb @@ -70,7 +70,7 @@ module SiSU_DbRemove @db=SiSU_Env::InfoDb.new end def remove - driver_sqlite3=if @sql_type=='sqlite' + driver_sqlite3=if @sql_type==:sqlite (@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \ ? true : false diff --git a/lib/sisu/v5/db_select.rb b/lib/sisu/v5/db_select.rb index 06d8c429..3aebe828 100644 --- a/lib/sisu/v5/db_select.rb +++ b/lib/sisu/v5/db_select.rb @@ -63,7 +63,7 @@ =end module SiSU_DbSelect class Case - def initialize(opt,conn='',sql_type='pg') + def initialize(opt,conn='',sql_type=:pg) @opt,@conn,@sql_type=opt,conn,sql_type @db=SiSU_Env::InfoDb.new @file_maint=sql_maintenance_file @@ -78,13 +78,13 @@ module SiSU_DbSelect end end def db_exist? - if @sql_type=='sqlite' \ + 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.is_a?(NilClass) - db=@sql_type=='sqlite' \ + db=@sql_type==:sqlite \ ? @db.sqlite.db : @db.psql.db puts %{no connection with #{@sql_type} database established, createdb "#{db}"?} @@ -95,7 +95,7 @@ module SiSU_DbSelect file=if @opt.inspect =~/M/ if @opt.fns and not @opt.fns.empty? @env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns - puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on + puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on @db=SiSU_Env::InfoDb.new @job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql" File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+') @@ -173,8 +173,8 @@ module SiSU_DbSelect db_exist? @sdb_import.marshal_load tell=case @sql_type - when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") - when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") + when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") + when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") else '???' end tell.puts_grey if @opt.act[:verbose][:set]==:on @@ -183,8 +183,8 @@ module SiSU_DbSelect @sdb_remove_doc.remove @sdb_import.marshal_load tell=case @sql_type - when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") - when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") + when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") + when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") else '???' end tell.puts_grey if @opt.act[:verbose][:set]==:on diff --git a/lib/sisu/v5/dbi.rb b/lib/sisu/v5/dbi.rb index 1ab9bc9c..737f02fd 100644 --- a/lib/sisu/v5/dbi.rb +++ b/lib/sisu/v5/dbi.rb @@ -79,22 +79,22 @@ module SiSU_DBI @sql_type=if @opt.cmd=~/D/ \ or @opt.mod.inspect =~/--pg(?:sql)?/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'pg' + :pg elsif @opt.cmd =~/d/ \ and @opt.mod.inspect =~/--(?:db[=-])?pg(?:sql)?/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'pg' + :pg elsif @opt.cmd=~/d/ \ or @opt.mod.inspect =~/--(?:sq)?lite/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'sqlite' + :sqlite elsif @opt.cmd =~/d/ \ and @opt.mod.inspect =~/--(?:db[=-])?(?:sq)?lite/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'sqlite' + :sqlite else maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'sqlite' + :sqlite end end end @@ -107,7 +107,7 @@ module SiSU_DBI begin @conn=@db.psql.conn_dbi rescue - if @opt.mod.inspect=~/--(createall|create)/ + if @opt.mod.inspect=~/--(?:createall|create)/ cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX puts <<-WOK manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet exist @@ -130,8 +130,8 @@ manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet end def connect case @sql_type - when /pg/ then read_psql - when /sqlite/ then read_sqlite + when :pg then read_psql #read_pg + when :sqlite then read_sqlite end SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"DBI (#{@sql_type}) #{@opt.mod}",@opt.fno).dbi_title unless @opt.act[:quiet][:set]==:on begin diff --git a/lib/sisu/v5/dbi_discrete.rb b/lib/sisu/v5/dbi_discrete.rb index cd8c7de1..b0468e8d 100644 --- a/lib/sisu/v5/dbi_discrete.rb +++ b/lib/sisu/v5/dbi_discrete.rb @@ -83,7 +83,7 @@ module SiSU_DBI_Discrete #% database building @md=@particulars.md if @opt.cmd =~/[d]/ \ or @opt.mod.inspect =~/--((?:sq)?lite)/ - @sql_type='sqlite' + @sql_type=:sqlite maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on end @output_path=@md.file.output_path.sqlite_discrete.dir @@ -122,8 +122,8 @@ module SiSU_DBI_Discrete #% database building def create_and_populate db=SiSU_Env::DbOp.new(@md) conn=db.sqlite_discrete.conn_sqlite3 - sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,'sqlite') - sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,'sqlite') + sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,:sqlite) + sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,:sqlite) sdb.output_dir? begin SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'SQLite',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_title_hi unless @opt.act[:quiet][:set]==:on @@ -136,7 +136,7 @@ module SiSU_DBI_Discrete #% database building sdb.create_table.urls sdb_index.create_indexes db_exist?(db,conn) - sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,'sqlite') + sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,:sqlite) sdb_import.marshal_load tell=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{db.sqlite.db} database?") tell.puts_grey if @opt.act[:verbose][:set]==:on @@ -174,7 +174,7 @@ module SiSU_DBI_Discrete #% database building file=if @opt.inspect =~/M/ if @opt.fns and not @opt.fns.empty? @env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns - puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on + puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on @db=SiSU_Env::InfoDb.new @job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql" File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+') diff --git a/lib/sisu/v6/db_create.rb b/lib/sisu/v6/db_create.rb index 661059a1..105f089c 100644 --- a/lib/sisu/v6/db_create.rb +++ b/lib/sisu/v6/db_create.rb @@ -66,10 +66,10 @@ module SiSU_DbCreate class Create < SiSU_DbColumns::Columns require_relative 'sysenv' # sysenv.rb @@dl=nil - def initialize(opt,conn,file,sql_type='pg') + def initialize(opt,conn,file,sql_type=:pg) @opt,@conn,@file,@sql_type=opt,conn,file,sql_type @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX - @comment=(@sql_type=='pg') \ + @comment=(@sql_type==:pg) \ ? (SiSU_DbCreate::Comment.new(@conn,@sql_type)) : nil @@dl ||=SiSU_Env::InfoEnv.new.digest.length @@ -84,7 +84,7 @@ module SiSU_DbCreate end def create_db @env=SiSU_Env::InfoEnv.new(@opt.fns) - tell=(@sql_type=='sqlite') \ + tell=(@sql_type==:sqlite) \ ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create SQLite db tables in:',%{"#{@file}"}) : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create pgSQL db tables in:',%{"#{Db[:name_prefix]}#{@env.path.stub_pwd}"}) if (@opt.act[:verbose][:set]==:on \ @@ -92,7 +92,7 @@ module SiSU_DbCreate || @opt.act[:maintenance][:set]==:on) tell.dark_grey_title_hi end - SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type=='pg' #watch use of path.stub_pwd instead of stub + SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type==:pg #watch use of path.stub_pwd instead of stub end def output_dir? dir=SiSU_Env::InfoEnv.new('') @@ -105,7 +105,7 @@ module SiSU_DbCreate if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ - currently using sisu dbi module + currently using sisu_dbi module to be populated from document files create tables metadata_and_text data import through ruby transfer @@ -343,7 +343,7 @@ module SiSU_DbCreate if (@opt.act[:verbose_plus][:set]==:on \ or @opt.act[:maintenance][:set]==:on) print %{ - currently using sisu dbi module + currently using sisu_dbi module to be populated from doc_objects files create tables urls data import through ruby transfer @@ -377,9 +377,9 @@ module SiSU_DbCreate end end class Comment < SiSU_DbColumns::Columns - def initialize(conn,sql_type='pg') + def initialize(conn,sql_type=:pg) @conn=conn - if sql_type =~ /pg/; psql + if sql_type == :pg then psql end end def psql diff --git a/lib/sisu/v6/db_drop.rb b/lib/sisu/v6/db_drop.rb index 94fc5e99..9ab73186 100644 --- a/lib/sisu/v6/db_drop.rb +++ b/lib/sisu/v6/db_drop.rb @@ -64,11 +64,11 @@ module SiSU_DbDrop class Drop require_relative 'response' # response.rb - def initialize(opt,conn,db_info,sql_type='') + def initialize(opt,conn,db_info,sql_type) @opt,@conn,@db_info,@sql_type=opt,conn,db_info,sql_type @ans=SiSU_Response::Response.new case @sql_type - when /sqlite/ + when :sqlite cascade='' else cascade='CASCADE' @@ -87,7 +87,7 @@ module SiSU_DbDrop begin msg_sqlite="as not all disk space is recovered after dropping the database << #{@db_info.sqlite.db} >>, you may be better off deleting the file, and recreating it as necessary" case @sql_type - when /sqlite/ + when :sqlite puts msg_sqlite ans=@ans.response?('remove sql database?') if ans \ @@ -129,7 +129,7 @@ module SiSU_DbDrop end rescue case @sql_type - when /sqlite/ + when :sqlite ans=@ans.response?('remove sql database?') if ans and File.exist?(@db_info.sqlite.db); File.unlink(@db_info.sqlite.db) end diff --git a/lib/sisu/v6/db_import.rb b/lib/sisu/v6/db_import.rb index e1342b1d..dd9dfe84 100644 --- a/lib/sisu/v6/db_import.rb +++ b/lib/sisu/v6/db_import.rb @@ -72,7 +72,7 @@ module SiSU_DbImport @@dl=nil @@hname=nil attr_accessor :tp - def initialize(opt,conn,file_maint,sql_type='pg') + def initialize(opt,conn,file_maint,sql_type=:pg) @opt,@conn,@file_maint,@sql_type=opt,conn,file_maint,sql_type @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX @env=SiSU_Env::InfoEnv.new(@opt.fns) @@ -90,7 +90,7 @@ module SiSU_DbImport @col[:ocn]='' @counter={} @db=SiSU_Env::InfoDb.new - if @sql_type=='sqlite' + if @sql_type==:sqlite @driver_sqlite3=(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \ ? true : false @@ -136,7 +136,7 @@ module SiSU_DbImport WHERE metadata_and_text.src_filename = '#{@md.fns}' AND metadata_and_text.language_document_char = '#{@opt.lng}' ;} # note, for .ssm: @md.fns (is set during runtime & is) != @opt.fns @md.opt.fns - file_exist=@sql_type=~/sqlite/ \ + file_exist=@sql_type==:sqlite \ ? @conn.get_first_value(select_first_match) : @conn.select_one(select_first_match) if not file_exist @@ -152,7 +152,7 @@ module SiSU_DbImport puts @conn.driver if defined? @conn.driver end begin #% sql - if @sql_type=~/sqlite/ + if @sql_type==:sqlite @conn.transaction do |conn| t_d.each do |sql| conn.execute(sql) @@ -497,7 +497,7 @@ module SiSU_DbImport @env=SiSU_Env::InfoEnv.new(@md.fns) @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" txt=endnotes(txt).extract_any - if @sql_type=~/pg/ \ + if @sql_type==:pg \ and txt.size > (SiSU_DbColumns::ColumnSize.new.document_clean - 1) # examine pg build & remove limitation puts "\n\nTOO LARGE (TXT - see error log)\n\n" open("#{Dir.pwd}/pg_documents_error_log",'a') do |error| diff --git a/lib/sisu/v6/db_indexes.rb b/lib/sisu/v6/db_indexes.rb index f293012f..6550fe51 100644 --- a/lib/sisu/v6/db_indexes.rb +++ b/lib/sisu/v6/db_indexes.rb @@ -62,8 +62,8 @@ =end module SiSU_DbIndex - class Index # create documents Indexes def initialize(opt,conn='',sql_type='') - def initialize(opt,conn,file,sql_type='') + class Index # create documents Indexes def initialize(opt,conn='',sql_type) + def initialize(opt,conn,file,sql_type) @opt,@conn,@file,@sql_type=opt,conn,file,sql_type end def create_indexes # check added from pg not tested diff --git a/lib/sisu/v6/db_remove.rb b/lib/sisu/v6/db_remove.rb index 650c84a2..5a392649 100644 --- a/lib/sisu/v6/db_remove.rb +++ b/lib/sisu/v6/db_remove.rb @@ -70,7 +70,7 @@ module SiSU_DbRemove @db=SiSU_Env::InfoDb.new end def remove - driver_sqlite3=if @sql_type=='sqlite' + driver_sqlite3=if @sql_type==:sqlite (@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \ ? true : false diff --git a/lib/sisu/v6/db_select.rb b/lib/sisu/v6/db_select.rb index 56b424d7..9a2c2eb0 100644 --- a/lib/sisu/v6/db_select.rb +++ b/lib/sisu/v6/db_select.rb @@ -63,7 +63,7 @@ =end module SiSU_DbSelect class Case - def initialize(opt,conn='',sql_type='pg') + def initialize(opt,conn='',sql_type=:pg) @opt,@conn,@sql_type=opt,conn,sql_type @db=SiSU_Env::InfoDb.new @file_maint=sql_maintenance_file @@ -78,13 +78,13 @@ module SiSU_DbSelect end end def db_exist? - if @sql_type=='sqlite' \ + 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.is_a?(NilClass) - db=@sql_type=='sqlite' \ + db=@sql_type==:sqlite \ ? @db.sqlite.db : @db.psql.db puts %{no connection with #{@sql_type} database established, createdb "#{db}"?} @@ -95,7 +95,7 @@ module SiSU_DbSelect file=if @opt.inspect =~/M/ if @opt.fns and not @opt.fns.empty? @env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns - puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on + puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on @db=SiSU_Env::InfoDb.new @job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql" File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+') @@ -173,8 +173,8 @@ module SiSU_DbSelect db_exist? @sdb_import.marshal_load tell=case @sql_type - when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") - when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") + when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") + when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") else '???' end tell.puts_grey if @opt.act[:verbose][:set]==:on @@ -183,8 +183,8 @@ module SiSU_DbSelect @sdb_remove_doc.remove @sdb_import.marshal_load tell=case @sql_type - when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") - when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") + when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?") + when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?") else '???' end tell.puts_grey if @opt.act[:verbose][:set]==:on diff --git a/lib/sisu/v6/dbi.rb b/lib/sisu/v6/dbi.rb index acb75e0f..5bd98b8a 100644 --- a/lib/sisu/v6/dbi.rb +++ b/lib/sisu/v6/dbi.rb @@ -79,22 +79,22 @@ module SiSU_DBI @sql_type=if @opt.cmd=~/D/ \ or @opt.mod.inspect =~/--pg(?:sql)?/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'pg' + :pg elsif @opt.cmd =~/d/ \ and @opt.mod.inspect =~/--(?:db[=-])?pg(?:sql)?/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'pg' + :pg elsif @opt.cmd=~/d/ \ or @opt.mod.inspect =~/--(?:sq)?lite/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'sqlite' + :sqlite elsif @opt.cmd =~/d/ \ and @opt.mod.inspect =~/--(?:db[=-])?(?:sq)?lite/ maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'sqlite' + :sqlite else maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on - 'sqlite' + :sqlite end end end @@ -107,7 +107,7 @@ module SiSU_DBI begin @conn=@db.psql.conn_dbi rescue - if @opt.mod.inspect=~/--(createall|create)/ + if @opt.mod.inspect=~/--(?:createall|create)/ cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX puts <<-WOK manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet exist @@ -130,8 +130,8 @@ manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet end def connect case @sql_type - when /pg/ then read_psql - when /sqlite/ then read_sqlite + when :pg then read_psql #read_pg + when :sqlite then read_sqlite end SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"DBI (#{@sql_type}) #{@opt.mod}",@opt.fno).dbi_title unless @opt.act[:quiet][:set]==:on begin diff --git a/lib/sisu/v6/dbi_discrete.rb b/lib/sisu/v6/dbi_discrete.rb index 0ac84db4..0f534e42 100644 --- a/lib/sisu/v6/dbi_discrete.rb +++ b/lib/sisu/v6/dbi_discrete.rb @@ -77,13 +77,13 @@ module SiSU_DBI_Discrete #% database building end class SQL def initialize(opt) - SiSU_Env::Load.new('dbi',true).prog + SiSU_Env::Load.new('sqlite3',true).prog @opt=opt @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) @md=@particulars.md if @opt.cmd =~/[d]/ \ or @opt.mod.inspect =~/--((?:sq)?lite)/ - @sql_type='sqlite' + @sql_type=:sqlite maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on end @output_path=@md.file.output_path.sqlite_discrete.dir @@ -122,8 +122,8 @@ module SiSU_DBI_Discrete #% database building def create_and_populate db=SiSU_Env::DbOp.new(@md) conn=db.sqlite_discrete.conn_sqlite3 - sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,'sqlite') - sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,'sqlite') + sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,:sqlite) + sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,:sqlite) sdb.output_dir? begin SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'SQLite',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_title_hi unless @opt.act[:quiet][:set]==:on @@ -136,7 +136,7 @@ module SiSU_DBI_Discrete #% database building sdb.create_table.urls sdb_index.create_indexes db_exist?(db,conn) - sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,'sqlite') + sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,:sqlite) sdb_import.marshal_load tell=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{db.sqlite.db} database?") tell.puts_grey if @opt.act[:verbose][:set]==:on @@ -174,7 +174,7 @@ module SiSU_DBI_Discrete #% database building file=if @opt.inspect =~/M/ if @opt.fns and not @opt.fns.empty? @env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns - puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on + puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on @db=SiSU_Env::InfoDb.new @job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql" File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+') -- cgit v1.2.3