From 09223f6ac8e547d465b01b99566aaecb993358cd Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 23 Jul 2014 18:06:58 -0400 Subject: v5 v6: version & changelog (& rakefile) --- data/doc/sisu/CHANGELOG_v5 | 7 +++++++ data/doc/sisu/CHANGELOG_v6 | 7 +++++++ data/sisu/v5/v/version.yml | 6 +++--- data/sisu/v6/v/version.yml | 6 +++--- rbuild | 4 ++-- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index c9416620..1a596776 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -31,6 +31,13 @@ v2 branch is removed; it is available in sisu =< 3.3.2 %% Reverse Chronological: +%% 5.5.3.orig.tar.xz (2014-07-23:29/3) +http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_5.5.3 +http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/debian/sisu_5.5.3-1 +http://www.jus.uio.no/sisu/pkg/src/sisu_5.5.3.orig.tar.xz + sisu_5.5.3.orig.tar.xz + sisu_5.5.3-1.dsc + %% 5.5.2.orig.tar.xz (2014-07-22:29/2) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_5.5.2 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/debian/sisu_5.5.2-1 diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6 index e41a12e0..e1201c3c 100644 --- a/data/doc/sisu/CHANGELOG_v6 +++ b/data/doc/sisu/CHANGELOG_v6 @@ -21,6 +21,13 @@ v2 branch is removed; it is available in sisu =< 3.3.2 %% Reverse Chronological: +%% 6.1.3.orig.tar.xz (2014-07-23:29/3) +http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_6.1.3 +http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/debian/sisu_6.1.3-1 +http://www.jus.uio.no/sisu/pkg/src/sisu_6.1.3.orig.tar.xz + sisu_6.1.3.orig.tar.xz + sisu_6.1.3-1.dsc + %% 6.1.2.orig.tar.xz (2014-07-22:29/2) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_6.1.2 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/debian/sisu_6.1.2-1 diff --git a/data/sisu/v5/v/version.yml b/data/sisu/v5/v/version.yml index af2b37c3..cb6a11a3 100644 --- a/data/sisu/v5/v/version.yml +++ b/data/sisu/v5/v/version.yml @@ -1,5 +1,5 @@ --- :project: SiSU -:version: 5.5.2 -:date_stamp: 2014w29/2 -:date: "2014-07-22" +:version: 5.5.3 +:date_stamp: 2014w29/3 +:date: "2014-07-23" diff --git a/data/sisu/v6/v/version.yml b/data/sisu/v6/v/version.yml index 426aff5d..ce0764ed 100644 --- a/data/sisu/v6/v/version.yml +++ b/data/sisu/v6/v/version.yml @@ -1,5 +1,5 @@ --- :project: SiSU -:version: 6.1.2 -:date_stamp: 2014w29/2 -:date: "2014-07-22" +:version: 6.1.3 +:date_stamp: 2014w29/3 +:date: "2014-07-23" diff --git a/rbuild b/rbuild index 74afe9be..ed867d94 100644 --- a/rbuild +++ b/rbuild @@ -37,8 +37,8 @@ #require 'mkmf' #create_makefile("sisu") #% manual settings, edit/update as required (note current default settings are obtained from sisu version yml file) -SiSU_version_next_stable = '5.5.2' #% set version -SiSU_version_next_unstable = '6.1.2' #% set version +SiSU_version_next_stable = '5.5.3' #% set version +SiSU_version_next_unstable = '6.1.3' #% set version #% rake file SiSU_version_generic_next_stable = '5.4.x' SiSU_version_generic_next_unstable = '6.0.x' -- cgit v1.2.3 From 3b753e3d0e6cc20d6fd3984e60c43963c729e89f Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 23 Jul 2014 18:10:24 -0400 Subject: v5 v6: db, rescue where no tables, attempt to initialize db and retry * internally run the equivalent of --createall * (if successful) permitting completion of --import or --update command * make use of action triggers --- data/doc/sisu/CHANGELOG_v5 | 6 ++++ data/doc/sisu/CHANGELOG_v6 | 6 ++++ lib/sisu/v5/db_import.rb | 73 ++++++++++++++++++++++++++++++++++--- lib/sisu/v5/db_remove.rb | 90 ++++++++++++++++++++++++++++++++++++++-------- lib/sisu/v5/db_select.rb | 39 +++++++++++++++----- lib/sisu/v5/utils.rb | 1 + lib/sisu/v6/db_import.rb | 73 ++++++++++++++++++++++++++++++++++--- lib/sisu/v6/db_remove.rb | 90 ++++++++++++++++++++++++++++++++++++++-------- lib/sisu/v6/db_select.rb | 39 +++++++++++++++----- lib/sisu/v6/utils.rb | 1 + 10 files changed, 362 insertions(+), 56 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index 1a596776..89a25da3 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -38,6 +38,12 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.5.3.orig.tar.xz sisu_5.5.3.orig.tar.xz sisu_5.5.3-1.dsc +* db, rescue where no tables attempt to initialize db and retry + (catch db message where no tables and attempt to initialize database) + * internally run the equivalent of --createall + * (if successful) permitting completion of --import or --update command + * make use of action triggers + %% 5.5.2.orig.tar.xz (2014-07-22:29/2) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_5.5.2 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/debian/sisu_5.5.2-1 diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6 index e1201c3c..7628fd67 100644 --- a/data/doc/sisu/CHANGELOG_v6 +++ b/data/doc/sisu/CHANGELOG_v6 @@ -28,6 +28,12 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.1.3.orig.tar.xz sisu_6.1.3.orig.tar.xz sisu_6.1.3-1.dsc +* db, rescue where no tables attempt to initialize db and retry + (catch db message where no tables and attempt to initialize database) + * internally run the equivalent of --createall + * (if successful) permitting completion of --import or --update command + * make use of action triggers + %% 6.1.2.orig.tar.xz (2014-07-22:29/2) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_6.1.2 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/debian/sisu_6.1.2-1 diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 3e9d19ec..579b95d5 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -138,16 +138,78 @@ module SiSU_DbImport 'Marshal Load', @fnc ).puts_grey if @opt.act[:verbose][:set]==:on -#% select_first_match=%{ SELECT metadata_and_text.tid FROM metadata_and_text 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 \ - ? @conn.get_first_value(select_first_match) - : @conn.exec(select_first_match).field_values("tid")[0] + file_exist=if @sql_type==:sqlite + begin + @conn.get_first_value(select_first_match) + rescue SQLite3::Exception => e + # not tested + puts "Exception occurred" + puts e + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + end + else + begin + @conn.exec(select_first_match).field_values("tid")[0] + rescue PG::Error => e + err=[ + e.result.error_field( PG::Result::PG_DIAG_SEVERITY ), + e.result.error_field( PG::Result::PG_DIAG_SQLSTATE ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_PRIMARY ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_DETAIL ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_HINT ), + e.result.error_field( PG::Result::PG_DIAG_STATEMENT_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_QUERY ), + e.result.error_field( PG::Result::PG_DIAG_CONTEXT ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FILE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_LINE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FUNCTION ), + ] + p err + if err[2] =~/relation "\S+?" does not exist/ \ + or err.inspect =~/relation "\S+?" does not exist/ + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + err[2] + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + retry + end + end + end if not file_exist t_d=[] # transaction_data t_d << db_import_metadata @@ -199,7 +261,7 @@ module SiSU_DbImport else if file_exist @db=SiSU_Env::InfoDb.new - puts "\nfile #{@opt.fns} in language code #{@opt.lng} already exists in database #{@db.psql.db} update instead?" + puts "\nfile #{@opt.fns} in language code #{@opt.lng} already exists in database #{@db.psql.db}, use --update instead?" end end end @@ -535,6 +597,7 @@ module SiSU_DbImport if inf[/#{Mx[:en_a_o]}(\d+)(.+?)#{Mx[:en_a_c]}/] nr,txt,digest_clean=$1,$2.strip,0 end + @id_n ||=0 @id_n+=1 txt=special_character_escape(txt) body=SiSU_FormatShared::CSS_Format.new(@md,data).endnote(nr,txt) diff --git a/lib/sisu/v5/db_remove.rb b/lib/sisu/v5/db_remove.rb index 1fbf8c9f..7075780e 100644 --- a/lib/sisu/v5/db_remove.rb +++ b/lib/sisu/v5/db_remove.rb @@ -76,22 +76,82 @@ module SiSU_DbRemove : false end del_id=if driver_sqlite3 - remove_selected=%{ - SELECT tid - FROM metadata_and_text - WHERE 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 - @conn.get_first_value(remove_selected).to_i + begin + remove_selected=%{ + SELECT tid + FROM metadata_and_text + WHERE 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 + @conn.get_first_value(remove_selected).to_i + rescue SQLite3::Exception => e + #not tested + puts "Exception occurred" + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark(e.inspect) + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + end else - remove_selected=%{ - SELECT metadata_and_text.tid - FROM metadata_and_text - 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 - x=@conn.exec(remove_selected) - x.field_values("tid")[0] + begin + remove_selected=%{ + SELECT metadata_and_text.tid + FROM metadata_and_text + 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 + x=@conn.exec(remove_selected) + x.field_values("tid")[0] + rescue PG::Error => e + err=[ + e.result.error_field( PG::Result::PG_DIAG_SEVERITY ), + e.result.error_field( PG::Result::PG_DIAG_SQLSTATE ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_PRIMARY ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_DETAIL ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_HINT ), + e.result.error_field( PG::Result::PG_DIAG_STATEMENT_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_QUERY ), + e.result.error_field( PG::Result::PG_DIAG_CONTEXT ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FILE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_LINE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FUNCTION ), + ] + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark("\n" + err.inspect) + if err[2] =~/relation "\S+?" does not exist/ \ + or err.inspect =~/relation "\S+?" does not exist/ + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + err[2] + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + end + end end if del_id sql_entry=[ diff --git a/lib/sisu/v5/db_select.rb b/lib/sisu/v5/db_select.rb index 3f232c14..26bbd3da 100644 --- a/lib/sisu/v5/db_select.rb +++ b/lib/sisu/v5/db_select.rb @@ -91,22 +91,45 @@ module SiSU_DbSelect 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, you may need to run:\n} \ - + %{ sisu --#{@sql_type} --createall\n} \ + puts %{no connection with sqlite database established, you may need to run:\n} \ + + %{ sisu --sqlite --createall\n} \ + %{ before attempting to populate the database} - exit + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + @sdb.create_table.metadata_and_text + @sdb.create_table.doc_objects + @sdb.create_table.endnotes + @sdb.create_table.endnotes_asterisk + @sdb.create_table.endnotes_plus + @sdb.create_table.urls + @sdb_index.create_indexes end if @conn.is_a?(NilClass) - db=if @sql_type==:sqlite - puts %{no connection with #{@sql_type} database established, you may need to run:\n} \ - + %{ sisu --#{@sql_type} --createall\n} \ + if @sql_type==:sqlite + puts %{no connection with sqlite database established, you may need to run:\n} \ + + %{ sisu --sqlite --createall\n} \ + %{ before attempting to populate the database} + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + @sdb.create_table.metadata_and_text + @sdb.create_table.doc_objects + @sdb.create_table.endnotes + @sdb.create_table.endnotes_asterisk + @sdb.create_table.endnotes_plus + @sdb.create_table.urls + @sdb_index.create_indexes @db.sqlite.db else - puts %{no connection with #{@sql_type} database established, you may need to run:\n} \ + puts %{no connection with pg database established, you may need to run:\n} \ + %{ createdb "#{@db.psql.db}"\n} \ + %{ after that don't forget to run:\n} \ - + %{ sisu --#{@sql_type} --createall\n} \ + + %{ sisu --pg --createall\n} \ + %{ before attempting to populate the database} @db.psql.db end diff --git a/lib/sisu/v5/utils.rb b/lib/sisu/v5/utils.rb index 4c732a8b..c5a312d2 100644 --- a/lib/sisu/v5/utils.rb +++ b/lib/sisu/v5/utils.rb @@ -211,6 +211,7 @@ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark({ m: %{ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark(%{ code: #{@@flag['code']}, open --> "#{t_o}" }) \ if t_o=~/^```/m SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark("open -->") +SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark("open -->") SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark("open -->",:green) SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:green,"open -->") SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark("open -->") diff --git a/lib/sisu/v6/db_import.rb b/lib/sisu/v6/db_import.rb index f3e8b96c..cca02edf 100644 --- a/lib/sisu/v6/db_import.rb +++ b/lib/sisu/v6/db_import.rb @@ -138,16 +138,78 @@ module SiSU_DbImport 'Marshal Load', @fnc ).puts_grey if @opt.act[:verbose][:set]==:on -#% select_first_match=%{ SELECT metadata_and_text.tid FROM metadata_and_text 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 \ - ? @conn.get_first_value(select_first_match) - : @conn.exec(select_first_match).field_values("tid")[0] + file_exist=if @sql_type==:sqlite + begin + @conn.get_first_value(select_first_match) + rescue SQLite3::Exception => e + # not tested + puts "Exception occurred" + puts e + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + end + else + begin + @conn.exec(select_first_match).field_values("tid")[0] + rescue PG::Error => e + err=[ + e.result.error_field( PG::Result::PG_DIAG_SEVERITY ), + e.result.error_field( PG::Result::PG_DIAG_SQLSTATE ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_PRIMARY ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_DETAIL ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_HINT ), + e.result.error_field( PG::Result::PG_DIAG_STATEMENT_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_QUERY ), + e.result.error_field( PG::Result::PG_DIAG_CONTEXT ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FILE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_LINE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FUNCTION ), + ] + p err + if err[2] =~/relation "\S+?" does not exist/ \ + or err.inspect =~/relation "\S+?" does not exist/ + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + err[2] + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + retry + end + end + end if not file_exist t_d=[] # transaction_data t_d << db_import_metadata @@ -199,7 +261,7 @@ module SiSU_DbImport else if file_exist @db=SiSU_Env::InfoDb.new - puts "\nfile #{@opt.fns} in language code #{@opt.lng} already exists in database #{@db.psql.db} update instead?" + puts "\nfile #{@opt.fns} in language code #{@opt.lng} already exists in database #{@db.psql.db}, use --update instead?" end end end @@ -535,6 +597,7 @@ module SiSU_DbImport if inf[/#{Mx[:en_a_o]}(\d+)(.+?)#{Mx[:en_a_c]}/] nr,txt,digest_clean=$1,$2.strip,0 end + @id_n ||=0 @id_n+=1 txt=special_character_escape(txt) body=SiSU_FormatShared::CSS_Format.new(@md,data).endnote(nr,txt) diff --git a/lib/sisu/v6/db_remove.rb b/lib/sisu/v6/db_remove.rb index 037dda33..c56f40a0 100644 --- a/lib/sisu/v6/db_remove.rb +++ b/lib/sisu/v6/db_remove.rb @@ -76,22 +76,82 @@ module SiSU_DbRemove : false end del_id=if driver_sqlite3 - remove_selected=%{ - SELECT tid - FROM metadata_and_text - WHERE 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 - @conn.get_first_value(remove_selected).to_i + begin + remove_selected=%{ + SELECT tid + FROM metadata_and_text + WHERE 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 + @conn.get_first_value(remove_selected).to_i + rescue SQLite3::Exception => e + #not tested + puts "Exception occurred" + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark(e.inspect) + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + end else - remove_selected=%{ - SELECT metadata_and_text.tid - FROM metadata_and_text - 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 - x=@conn.exec(remove_selected) - x.field_values("tid")[0] + begin + remove_selected=%{ + SELECT metadata_and_text.tid + FROM metadata_and_text + 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 + x=@conn.exec(remove_selected) + x.field_values("tid")[0] + rescue PG::Error => e + err=[ + e.result.error_field( PG::Result::PG_DIAG_SEVERITY ), + e.result.error_field( PG::Result::PG_DIAG_SQLSTATE ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_PRIMARY ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_DETAIL ), + e.result.error_field( PG::Result::PG_DIAG_MESSAGE_HINT ), + e.result.error_field( PG::Result::PG_DIAG_STATEMENT_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_POSITION ), + e.result.error_field( PG::Result::PG_DIAG_INTERNAL_QUERY ), + e.result.error_field( PG::Result::PG_DIAG_CONTEXT ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FILE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_LINE ), + e.result.error_field( PG::Result::PG_DIAG_SOURCE_FUNCTION ), + ] + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark("\n" + err.inspect) + if err[2] =~/relation "\S+?" does not exist/ \ + or err.inspect =~/relation "\S+?" does not exist/ + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + err[2] + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + sdb= + SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) + sdb_index= + SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + end + end end if del_id sql_entry=[ diff --git a/lib/sisu/v6/db_select.rb b/lib/sisu/v6/db_select.rb index 61522e3b..70b7bbbe 100644 --- a/lib/sisu/v6/db_select.rb +++ b/lib/sisu/v6/db_select.rb @@ -91,22 +91,45 @@ module SiSU_DbSelect 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, you may need to run:\n} \ - + %{ sisu --#{@sql_type} --createall\n} \ + puts %{no connection with sqlite database established, you may need to run:\n} \ + + %{ sisu --sqlite --createall\n} \ + %{ before attempting to populate the database} - exit + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + @sdb.create_table.metadata_and_text + @sdb.create_table.doc_objects + @sdb.create_table.endnotes + @sdb.create_table.endnotes_asterisk + @sdb.create_table.endnotes_plus + @sdb.create_table.urls + @sdb_index.create_indexes end if @conn.is_a?(NilClass) - db=if @sql_type==:sqlite - puts %{no connection with #{@sql_type} database established, you may need to run:\n} \ - + %{ sisu --#{@sql_type} --createall\n} \ + if @sql_type==:sqlite + puts %{no connection with sqlite database established, you may need to run:\n} \ + + %{ sisu --sqlite --createall\n} \ + %{ before attempting to populate the database} + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).mark( + "\n" \ + + 'Attempting to initialize db' + "\n" \ + + 'Creating db tables' + ) + @sdb.create_table.metadata_and_text + @sdb.create_table.doc_objects + @sdb.create_table.endnotes + @sdb.create_table.endnotes_asterisk + @sdb.create_table.endnotes_plus + @sdb.create_table.urls + @sdb_index.create_indexes @db.sqlite.db else - puts %{no connection with #{@sql_type} database established, you may need to run:\n} \ + puts %{no connection with pg database established, you may need to run:\n} \ + %{ createdb "#{@db.psql.db}"\n} \ + %{ after that don't forget to run:\n} \ - + %{ sisu --#{@sql_type} --createall\n} \ + + %{ sisu --pg --createall\n} \ + %{ before attempting to populate the database} @db.psql.db end diff --git a/lib/sisu/v6/utils.rb b/lib/sisu/v6/utils.rb index 6c34a55a..7e915429 100644 --- a/lib/sisu/v6/utils.rb +++ b/lib/sisu/v6/utils.rb @@ -211,6 +211,7 @@ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark({ m: %{ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark(%{ code: #{@@flag['code']}, open --> "#{t_o}" }) \ if t_o=~/^```/m SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark("open -->") +SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark("open -->") SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark("open -->",:green) SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:green,"open -->") SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark("open -->") -- cgit v1.2.3 From c59e0eedb91790f90cfa0a314834153660556f28 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 23 Jul 2014 18:13:36 -0400 Subject: v5 v6: db, reorganize previous commit --- lib/sisu/v5/db_import.rb | 33 ++++------ lib/sisu/v5/db_remove.rb | 33 ++++------ lib/sisu/v5/db_select.rb | 166 ++++++++++++++++++++++------------------------- lib/sisu/v6/db_import.rb | 33 ++++------ lib/sisu/v6/db_remove.rb | 33 ++++------ lib/sisu/v6/db_select.rb | 166 ++++++++++++++++++++++------------------------- 6 files changed, 198 insertions(+), 266 deletions(-) diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 579b95d5..791eef43 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -69,6 +69,7 @@ module SiSU_DbImport class Import < SiSU_DbText::Prepare include SiSU_Param include SiSU_Screen + include SiSU_DbAction @@dl=nil @@hname=nil attr_accessor :tp @@ -156,17 +157,11 @@ module SiSU_DbImport + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create end else begin @@ -195,17 +190,11 @@ module SiSU_DbImport + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create retry end end diff --git a/lib/sisu/v5/db_remove.rb b/lib/sisu/v5/db_remove.rb index 7075780e..cff42409 100644 --- a/lib/sisu/v5/db_remove.rb +++ b/lib/sisu/v5/db_remove.rb @@ -63,6 +63,7 @@ =end module SiSU_DbRemove class Remove + include SiSU_DbAction def initialize(opt,conn,file,sql_type) @opt,@conn,@file,@sql_type=opt,conn,file,sql_type @md=SiSU_Param::Parameters.new(@opt).get @@ -93,17 +94,11 @@ module SiSU_DbRemove + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create end else begin @@ -139,17 +134,11 @@ module SiSU_DbRemove + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create end end end diff --git a/lib/sisu/v5/db_select.rb b/lib/sisu/v5/db_select.rb index 26bbd3da..333c3f0c 100644 --- a/lib/sisu/v5/db_select.rb +++ b/lib/sisu/v5/db_select.rb @@ -61,30 +61,87 @@ sqlite =end +module SiSU_DbAction + def db_action(sdb) + @sdb=sdb + def createdb + @sdb[:create].output_dir? + begin + @sdb[:create].create_db + rescue + @sdb[:create].output_dir? + end + end + def drop + @sdb[:drop].drop.tables + end + def create + @sdb[:create].output_dir? + begin + @sdb[:create].create_table.metadata_and_text + @sdb[:create].create_table.doc_objects + @sdb[:create].create_table.endnotes + @sdb[:create].create_table.endnotes_asterisk + @sdb[:create].create_table.endnotes_plus + @sdb[:create].create_table.urls + @sdb[:index].create_indexes + rescue + SiSU_Errors::Rescued.new($!,$@,'--sqlite').location + @sdb[:create].output_dir? do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def import + db_exist? + @sdb[:import].marshal_load + tell=case @sql_type + when :sqlite + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + "sqlite3 #{@db.sqlite.db} database?" + ) + when :pg + 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 + end + def remove + db_exist? + @sdb[:remove_doc].remove + end + def update + remove + import + end + self + end +end module SiSU_DbSelect class Case + include SiSU_DbAction 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 - @sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - @sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - @sdb_no= - SiSU_DbDBI::Drop.new(@opt,@conn,@db,@sql_type) + @sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + drop: SiSU_DbDBI::Drop.new(@opt,@conn,@db,@sql_type), + } if (@opt.act[:psql_import][:set]==:on \ || @opt.act[:psql_update][:set]==:on) \ or (@opt.act[:sqlite_import][:set]==:on \ || @opt.act[:sqlite_update][:set]==:on) - @sdb_import= - SiSU_DbDBI::Import.new(@opt,@conn,@file_maint,@sql_type) - @sdb_remove_doc= - SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) + @sdb[:import]=SiSU_DbDBI::Import.new(@opt,@conn,@file_maint,@sql_type) + @sdb[:remove_doc]=SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) elsif (@opt.act[:psql_remove][:set]==:on \ or @opt.act[:sqlite_remove][:set]==:on) - @sdb_remove_doc= - SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) + @sdb[:remove_doc]=SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) end end def db_exist? @@ -99,13 +156,7 @@ module SiSU_DbSelect + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - @sdb.create_table.metadata_and_text - @sdb.create_table.doc_objects - @sdb.create_table.endnotes - @sdb.create_table.endnotes_asterisk - @sdb.create_table.endnotes_plus - @sdb.create_table.urls - @sdb_index.create_indexes + db_action(@sdb).create end if @conn.is_a?(NilClass) if @sql_type==:sqlite @@ -117,13 +168,7 @@ module SiSU_DbSelect + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - @sdb.create_table.metadata_and_text - @sdb.create_table.doc_objects - @sdb.create_table.endnotes - @sdb.create_table.endnotes_asterisk - @sdb.create_table.endnotes_plus - @sdb.create_table.urls - @sdb_index.create_indexes + db_action(@sdb).create @db.sqlite.db else puts %{no connection with pg database established, you may need to run:\n} \ @@ -156,87 +201,30 @@ module SiSU_DbSelect end file end - def db_action - def createdb - @sdb.output_dir? - begin - @sdb.create_db - rescue - @sdb.output_dir? - end - end - def drop - @sdb_no.drop.tables - end - def create - @sdb.output_dir? - begin - @sdb.create_table.metadata_and_text - @sdb.create_table.doc_objects - @sdb.create_table.endnotes - @sdb.create_table.endnotes_asterisk - @sdb.create_table.endnotes_plus - @sdb.create_table.urls - @sdb_index.create_indexes - rescue - SiSU_Errors::Rescued.new($!,$@,'--sqlite').location - @sdb.output_dir? do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def import - db_exist? - @sdb_import.marshal_load - tell=case @sql_type - when :sqlite - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - "sqlite3 #{@db.sqlite.db} database?" - ) - when :pg - 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 - end - def remove - db_exist? - @sdb_remove_doc.remove - end - def update - remove - import - end - self - end def cases if @opt.act[:psql_drop][:set] ==:on \ or @opt.act[:sqlite_drop][:set] ==:on - db_action.drop + db_action(@sdb).drop end if @opt.act[:psql_createdb][:set] ==:on \ or @opt.act[:sqlite_createdb][:set] ==:on - db_action.createdb + db_action(@sdb).createdb end if @opt.act[:psql_create][:set] ==:on \ or @opt.act[:sqlite_create][:set] ==:on - db_action.create + db_action(@sdb).create end if @opt.act[:psql_update][:set] ==:on \ or @opt.act[:sqlite_update][:set] ==:on - db_action.update + db_action(@sdb).update else if @opt.act[:psql_remove][:set] ==:on \ or @opt.act[:sqlite_remove][:set] ==:on - db_action.remove + db_action(@sdb).remove end if @opt.act[:psql_import][:set] ==:on \ or @opt.act[:sqlite_import][:set] ==:on - db_action.import + db_action(@sdb).import end end end diff --git a/lib/sisu/v6/db_import.rb b/lib/sisu/v6/db_import.rb index cca02edf..51eb5562 100644 --- a/lib/sisu/v6/db_import.rb +++ b/lib/sisu/v6/db_import.rb @@ -69,6 +69,7 @@ module SiSU_DbImport class Import < SiSU_DbText::Prepare include SiSU_Param include SiSU_Screen + include SiSU_DbAction @@dl=nil @@hname=nil attr_accessor :tp @@ -156,17 +157,11 @@ module SiSU_DbImport + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create end else begin @@ -195,17 +190,11 @@ module SiSU_DbImport + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create retry end end diff --git a/lib/sisu/v6/db_remove.rb b/lib/sisu/v6/db_remove.rb index c56f40a0..91909937 100644 --- a/lib/sisu/v6/db_remove.rb +++ b/lib/sisu/v6/db_remove.rb @@ -63,6 +63,7 @@ =end module SiSU_DbRemove class Remove + include SiSU_DbAction def initialize(opt,conn,file,sql_type) @opt,@conn,@file,@sql_type=opt,conn,file,sql_type @md=SiSU_Param::Parameters.new(@opt).get @@ -93,17 +94,11 @@ module SiSU_DbRemove + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create end else begin @@ -139,17 +134,11 @@ module SiSU_DbRemove + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - sdb.create_table.metadata_and_text - sdb.create_table.doc_objects - sdb.create_table.endnotes - sdb.create_table.endnotes_asterisk - sdb.create_table.endnotes_plus - sdb.create_table.urls - sdb_index.create_indexes + sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + } + db_action(sdb).create end end end diff --git a/lib/sisu/v6/db_select.rb b/lib/sisu/v6/db_select.rb index 70b7bbbe..1aadd54a 100644 --- a/lib/sisu/v6/db_select.rb +++ b/lib/sisu/v6/db_select.rb @@ -61,30 +61,87 @@ sqlite =end +module SiSU_DbAction + def db_action(sdb) + @sdb=sdb + def createdb + @sdb[:create].output_dir? + begin + @sdb[:create].create_db + rescue + @sdb[:create].output_dir? + end + end + def drop + @sdb[:drop].drop.tables + end + def create + @sdb[:create].output_dir? + begin + @sdb[:create].create_table.metadata_and_text + @sdb[:create].create_table.doc_objects + @sdb[:create].create_table.endnotes + @sdb[:create].create_table.endnotes_asterisk + @sdb[:create].create_table.endnotes_plus + @sdb[:create].create_table.urls + @sdb[:index].create_indexes + rescue + SiSU_Errors::Rescued.new($!,$@,'--sqlite').location + @sdb[:create].output_dir? do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def import + db_exist? + @sdb[:import].marshal_load + tell=case @sql_type + when :sqlite + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + "sqlite3 #{@db.sqlite.db} database?" + ) + when :pg + 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 + end + def remove + db_exist? + @sdb[:remove_doc].remove + end + def update + remove + import + end + self + end +end module SiSU_DbSelect class Case + include SiSU_DbAction 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 - @sdb= - SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type) - @sdb_index= - SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type) - @sdb_no= - SiSU_DbDBI::Drop.new(@opt,@conn,@db,@sql_type) + @sdb={ + create: SiSU_DbDBI::Create.new(@opt,@conn,@file_maint,@sql_type), + index: SiSU_DbDBI::Index.new(@opt,@conn,@file_maint,@sql_type), + drop: SiSU_DbDBI::Drop.new(@opt,@conn,@db,@sql_type), + } if (@opt.act[:psql_import][:set]==:on \ || @opt.act[:psql_update][:set]==:on) \ or (@opt.act[:sqlite_import][:set]==:on \ || @opt.act[:sqlite_update][:set]==:on) - @sdb_import= - SiSU_DbDBI::Import.new(@opt,@conn,@file_maint,@sql_type) - @sdb_remove_doc= - SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) + @sdb[:import]=SiSU_DbDBI::Import.new(@opt,@conn,@file_maint,@sql_type) + @sdb[:remove_doc]=SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) elsif (@opt.act[:psql_remove][:set]==:on \ or @opt.act[:sqlite_remove][:set]==:on) - @sdb_remove_doc= - SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) + @sdb[:remove_doc]=SiSU_DbDBI::Remove.new(@opt,@conn,@file_maint,@sql_type) end end def db_exist? @@ -99,13 +156,7 @@ module SiSU_DbSelect + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - @sdb.create_table.metadata_and_text - @sdb.create_table.doc_objects - @sdb.create_table.endnotes - @sdb.create_table.endnotes_asterisk - @sdb.create_table.endnotes_plus - @sdb.create_table.urls - @sdb_index.create_indexes + db_action(@sdb).create end if @conn.is_a?(NilClass) if @sql_type==:sqlite @@ -117,13 +168,7 @@ module SiSU_DbSelect + 'Attempting to initialize db' + "\n" \ + 'Creating db tables' ) - @sdb.create_table.metadata_and_text - @sdb.create_table.doc_objects - @sdb.create_table.endnotes - @sdb.create_table.endnotes_asterisk - @sdb.create_table.endnotes_plus - @sdb.create_table.urls - @sdb_index.create_indexes + db_action(@sdb).create @db.sqlite.db else puts %{no connection with pg database established, you may need to run:\n} \ @@ -156,87 +201,30 @@ module SiSU_DbSelect end file end - def db_action - def createdb - @sdb.output_dir? - begin - @sdb.create_db - rescue - @sdb.output_dir? - end - end - def drop - @sdb_no.drop.tables - end - def create - @sdb.output_dir? - begin - @sdb.create_table.metadata_and_text - @sdb.create_table.doc_objects - @sdb.create_table.endnotes - @sdb.create_table.endnotes_asterisk - @sdb.create_table.endnotes_plus - @sdb.create_table.urls - @sdb_index.create_indexes - rescue - SiSU_Errors::Rescued.new($!,$@,'--sqlite').location - @sdb.output_dir? do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def import - db_exist? - @sdb_import.marshal_load - tell=case @sql_type - when :sqlite - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - "sqlite3 #{@db.sqlite.db} database?" - ) - when :pg - 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 - end - def remove - db_exist? - @sdb_remove_doc.remove - end - def update - remove - import - end - self - end def cases if @opt.act[:psql_drop][:set] ==:on \ or @opt.act[:sqlite_drop][:set] ==:on - db_action.drop + db_action(@sdb).drop end if @opt.act[:psql_createdb][:set] ==:on \ or @opt.act[:sqlite_createdb][:set] ==:on - db_action.createdb + db_action(@sdb).createdb end if @opt.act[:psql_create][:set] ==:on \ or @opt.act[:sqlite_create][:set] ==:on - db_action.create + db_action(@sdb).create end if @opt.act[:psql_update][:set] ==:on \ or @opt.act[:sqlite_update][:set] ==:on - db_action.update + db_action(@sdb).update else if @opt.act[:psql_remove][:set] ==:on \ or @opt.act[:sqlite_remove][:set] ==:on - db_action.remove + db_action(@sdb).remove end if @opt.act[:psql_import][:set] ==:on \ or @opt.act[:sqlite_import][:set] ==:on - db_action.import + db_action(@sdb).import end end end -- cgit v1.2.3