diff options
author | Ralph Amissah <ralph@amissah.com> | 2014-05-18 09:39:31 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2014-05-18 09:39:31 -0400 |
commit | 808c9c74a72b95e6272c8927cce839d89626ba47 (patch) | |
tree | 8047b7cee667ca0c2b6b9bb12a4c3e33a34704fa /lib/sisu/v6/db_import.rb | |
parent | debian/changelog (5.3.5-1) (diff) | |
parent | v5 v6: cgi, sample search forms: use ruby-pg & ruby-sqlite3; remove ruby-dbi (diff) |
Merge tag 'sisu_5.3.6' into debian/sid
SiSU 5.3.6
Diffstat (limited to 'lib/sisu/v6/db_import.rb')
-rw-r--r-- | lib/sisu/v6/db_import.rb | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/sisu/v6/db_import.rb b/lib/sisu/v6/db_import.rb index e1342b1d..35fb631a 100644 --- a/lib/sisu/v6/db_import.rb +++ b/lib/sisu/v6/db_import.rb @@ -72,7 +72,7 @@ module SiSU_DbImport @@dl=nil @@hname=nil attr_accessor :tp - def initialize(opt,conn,file_maint,sql_type='pg') + def initialize(opt,conn,file_maint,sql_type=:pg) @opt,@conn,@file_maint,@sql_type=opt,conn,file_maint,sql_type @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX @env=SiSU_Env::InfoEnv.new(@opt.fns) @@ -90,7 +90,7 @@ module SiSU_DbImport @col[:ocn]='' @counter={} @db=SiSU_Env::InfoDb.new - if @sql_type=='sqlite' + if @sql_type==:sqlite @driver_sqlite3=(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \ ? true : false @@ -109,7 +109,7 @@ module SiSU_DbImport begin @id_n=@driver_sqlite3 \ ? @conn.execute( sql ).join.to_i - : @id_n=@conn.execute( sql ) { |x| x.fetch_all.flatten[0] } + : @id_n=@conn.exec( sql ).getvalue(0,0).to_i @id_n ||=0 rescue puts "#{__FILE__}:#{__LINE__}" if @opt.act[:maintenance][:set]==:on @@ -136,9 +136,9 @@ module SiSU_DbImport 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/ \ + file_exist=@sql_type==:sqlite \ ? @conn.get_first_value(select_first_match) - : @conn.select_one(select_first_match) + : @conn.exec(select_first_match).field_values("tid")[0] if not file_exist t_d=[] # transaction_data t_d << db_import_metadata @@ -152,7 +152,7 @@ module SiSU_DbImport puts @conn.driver if defined? @conn.driver end begin #% sql - if @sql_type=~/sqlite/ + if @sql_type==:sqlite @conn.transaction do |conn| t_d.each do |sql| conn.execute(sql) @@ -166,11 +166,11 @@ module SiSU_DbImport #@conn.execute("COMMIT") else #'do' works for postgresql - @conn.do("BEGIN") + @conn.exec("BEGIN") t_d.each do |sql| - @conn.do(sql) + @conn.exec(sql) end - @conn.do("COMMIT") + @conn.exec("COMMIT") end rescue DBI::DatabaseError => e STDERR.puts "Error code: #{e.err}" @@ -206,7 +206,7 @@ module SiSU_DbImport else if file_exist @db=SiSU_Env::InfoDb.new - puts "\n#{@cX.grey}file #{@cX.off} #{@cX.blue}#{@opt.fns}#{@cX.off} in language code #{cX.blue}#{@opt.lng}#{cX.off} #{@cX.grey}already exists in database#{@cX.off} #{@cX.blue}#{@db.psql.db}#{@cX.off} #{@cX.brown}update instead?#{@cX.off}" + puts "\nfile #{@opt.fns} in language code #{@opt.lng} already exists in database #{@db.psql.db} update instead?" end end end @@ -497,7 +497,7 @@ module SiSU_DbImport @env=SiSU_Env::InfoEnv.new(@md.fns) @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" txt=endnotes(txt).extract_any - if @sql_type=~/pg/ \ + if @sql_type==:pg \ and txt.size > (SiSU_DbColumns::ColumnSize.new.document_clean - 1) # examine pg build & remove limitation puts "\n\nTOO LARGE (TXT - see error log)\n\n" open("#{Dir.pwd}/pg_documents_error_log",'a') do |error| |