diff options
Diffstat (limited to 'lib/sisu/v0/db_import.rb')
-rw-r--r-- | lib/sisu/v0/db_import.rb | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/sisu/v0/db_import.rb b/lib/sisu/v0/db_import.rb index 1e1e25d7..03f72065 100644 --- a/lib/sisu/v0/db_import.rb +++ b/lib/sisu/v0/db_import.rb @@ -8,7 +8,7 @@ * Author: Ralph Amissah * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008 Ralph Amissah All Rights Reserved. + 2007, 2008, 2009 Ralph Amissah All Rights Reserved. * License: GPL 3 or later: @@ -62,7 +62,7 @@ module SiSU_DB_import require "#{SiSU_lib}/db_columns" require "#{SiSU_lib}/db_load_tuple" require "#{SiSU_lib}/shared_html_lite" - #require 'sqlite3' + require 'sqlite3' class Import < SiSU_DB_columns::Column_size include SiSU_Param include SiSU_Screen @@ -85,18 +85,30 @@ module SiSU_DB_import @col=Hash.new('') @col[:ocn]='' @counter={} + @db=SiSU_Env::Info_db.new + @driver_sqlite3=false + @driver_sqlite3=true if @conn.inspect.match(/^(.{10})/)[1] == @db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1] sql='SELECT MAX(lid) FROM documents' begin @col[:lid] ||=0 - @col[:lid]=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } + @col[:lid]=if @driver_sqlite3 + @conn.execute( sql ).join.to_i + else @conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } + end rescue + puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/ end @col[:lid] =0 if @col[:lid].nil? or @col[:lid].to_s.empty? sql='SELECT MAX(nid) FROM endnotes' begin @id_n ||=0 - @id_n=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } + @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 rescue + puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/ end @id_n =0 if @col[:lid].nil? or @col[:lid].to_s.empty? @col[:lv1]=@col[:lv2]=@col[:lv3]=@col[:lv4]=@col[:lv5]=@col[:lv6]=0 @@ -112,6 +124,7 @@ module SiSU_DB_import tell.print_grey if @opt.cmd =~/v/ case @sql_type when /sqlite/ #fix logic for sqlite ! + #sqlite watch #pf_db_import_transaction_open if @opt =~/M/ db_import_metadata db_import_documents(@dal_array) @@ -120,7 +133,10 @@ module SiSU_DB_import #@conn.commit #@conn.close #@conn.disconnect -#sqlite watch + if @opt.cmd =~/M/ + puts "\n" + @conn.inspect + puts "\nat #{__FILE__} #{__LINE__}" + end else file_exist=@conn.select_one(%{ SELECT metadata.tid FROM metadata WHERE metadata.filename ~ '#{@opt.fns}'; }) unless file_exist @@ -129,6 +145,10 @@ module SiSU_DB_import db_import_documents(@dal_array) db_import_urls(@dal_array,@fnm) #import OID on/off @conn.execute('COMMIT') + if @opt.cmd =~/[MV]/ + puts "\n" + @conn.inspect + puts "\nat #{__FILE__} #{__LINE__}" + end else @db=SiSU_Env::Info_db.new puts "\n#{@cX.grey}file #{@cX.off} #{@cX.blue}#{@opt.fns}#{@cX.off} #{@cX.grey}already exists in database#{@cX.off} #{@cX.blue}#{@db.psql.db}#{@cX.off} #{@cX.brown}update instead?#{@cX.off}" @@ -171,9 +191,13 @@ module SiSU_DB_import sql='SELECT MAX(tid) FROM metadata' begin @@id_t ||=0 - id_t=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } + id_t=if @driver_sqlite3 + @conn.execute( sql ).join.to_i # { |x| id_t=x.join.to_i } + else @conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } + end @@id_t=id_t if id_t rescue + puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/ end @@id_t =0 if @col[:lid].nil? or @col[:lid].to_s.empty? @@id_t+=1 #bug related, needs to be performed once at start of file, but consider moving, as, placed here it means program will fail if document header lacks 0~title |