From 9f5b2818972fc01ffd992b2635765c982f644e24 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 17 Apr 2010 21:38:33 -0400 Subject: db_import sqlite, prevent multiple import of file with same filename(.sst) (cgi form should work correctly, without multiple entries) db_import, db_remove: * wrap some sqlite actions in sqlite check; * cosmetic code arrangement --- lib/sisu/v2/db_import.rb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'lib/sisu/v2/db_import.rb') diff --git a/lib/sisu/v2/db_import.rb b/lib/sisu/v2/db_import.rb index 5610a1d0..45aca11b 100644 --- a/lib/sisu/v2/db_import.rb +++ b/lib/sisu/v2/db_import.rb @@ -86,14 +86,17 @@ module SiSU_DB_import @col[:ocn]='' @counter={} @db=SiSU_Env::Info_db.new - @driver_sqlite3=(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) ? true : false + if @sql_type=='sqlite' + @driver_sqlite3=(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \ + ? true \ + : false + end sql='SELECT MAX(lid) FROM doc_objects' begin @col[:lid] ||=0 - @col[:lid]=if @driver_sqlite3 - @conn.execute( sql ).join.to_i - else @conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } - end + @col[:lid]=@driver_sqlite3 \ + ? @conn.execute( sql ).join.to_i \ + : @conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } rescue puts "#{__FILE__}:#{__LINE__}" if @opt.cmd =~/M/ end @@ -101,11 +104,9 @@ module SiSU_DB_import sql='SELECT MAX(nid) FROM endnotes' begin @id_n ||=0 - @id_n=if @driver_sqlite3 - @conn.execute( sql ).join.to_i - else - @id_n=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } - end + @id_n=@driver_sqlite3 \ + ? @conn.execute( sql ).join.to_i \ + : @id_n=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } rescue puts "#{__FILE__}:#{__LINE__}" if @opt.cmd =~/M/ end @@ -121,12 +122,11 @@ module SiSU_DB_import tell.puts_blue unless @opt.cmd =~/q/ tell=SiSU_Screen::Ansi.new(@opt.cmd,'Marshal Load',@fnc) tell.print_grey if @opt.cmd =~/v/ - file_exist=if @sql_type=~/sqlite/; nil - else - @conn.select_one(%{ SELECT metadata_and_text.tid FROM metadata_and_text WHERE metadata_and_text.filename = '#{@opt.fns}'; }) - end - if (@sql_type!~/sqlite/ and not file_exist) \ - or @sql_type=~/sqlite/ + select_first_match=%{ SELECT metadata_and_text.tid FROM metadata_and_text WHERE metadata_and_text.filename = '#{@opt.fns}'; } + file_exist=@sql_type=~/sqlite/ \ + ? @conn.get_first_value(select_first_match) \ + : @conn.select_one(select_first_match) + if not file_exist t_d=[] # transaction_data t_d << db_import_metadata t_d << db_import_documents(@dal_array) -- cgit v1.2.3