aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5/db_remove.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2014-07-23 18:10:24 -0400
committerRalph Amissah <ralph@amissah.com>2014-07-23 18:10:34 -0400
commit3b753e3d0e6cc20d6fd3984e60c43963c729e89f (patch)
tree7e289e8d354af8d114a244aa22e9da351fca385a /lib/sisu/v5/db_remove.rb
parentv5 v6: version & changelog (& rakefile) (diff)
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
Diffstat (limited to 'lib/sisu/v5/db_remove.rb')
-rw-r--r--lib/sisu/v5/db_remove.rb90
1 files changed, 75 insertions, 15 deletions
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=[