diff options
author | Ralph Amissah <ralph@amissah.com> | 2010-04-17 21:38:33 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2010-04-17 21:44:31 -0400 |
commit | 9f5b2818972fc01ffd992b2635765c982f644e24 (patch) | |
tree | 5c4676d9000456eab58eadb4c83b1fade7d3b0d9 | |
parent | db_create, on processing screen output appropriate display for pgsql & sqlite... (diff) |
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
-rw-r--r-- | lib/sisu/v2/db_import.rb | 32 | ||||
-rw-r--r-- | lib/sisu/v2/db_remove.rb | 10 |
2 files changed, 23 insertions, 19 deletions
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) diff --git a/lib/sisu/v2/db_remove.rb b/lib/sisu/v2/db_remove.rb index 0a51b892..e7942a15 100644 --- a/lib/sisu/v2/db_remove.rb +++ b/lib/sisu/v2/db_remove.rb @@ -59,14 +59,18 @@ =end module SiSU_DB_remove class Remove - def initialize(opt,conn,file) - @opt,@conn,@file=opt,conn,file + def initialize(opt,conn,file,sql_type) + @opt,@conn,@file,@sql_type=opt,conn,file,sql_type @md=SiSU_Param::Parameters.new(@opt).get @fnb=@md.fnb @db=SiSU_Env::Info_db.new end def remove - driver_sqlite3=(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) ? true : false + driver_sqlite3=if @sql_type=='sqlite' + (@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \ + ? true \ + : false + end del_id=if driver_sqlite3 @conn.get_first_value(%{ SELECT tid FROM metadata_and_text WHERE filename = '#{@opt.fns}'; }).to_i else |