aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/db_import.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2008-12-22 01:08:06 -0500
committerRalph Amissah <ralph@amissah.com>2008-12-24 00:34:18 -0500
commit71223cf6cd035b3e395f6d4c3e4c41b79ed29510 (patch)
tree58fe17f8c2340792924b0eb2eeea51a8e9805e53 /lib/sisu/v0/db_import.rb
parentSiSU's sqlite module still broken for the time being: inconsistent ruby dbi api (diff)
sqlite3 fix, populate do using rb sqlite3 driver directly (rb dbi problematic
at present) sqlite fix, change ruby driver used to populate sisu sqlite3 db to rb sqlite3 for the time being. Use rb sqlite3 driver directly rather (than more convenient when working) rb dbi interface to populate content. Used to bypass problems with rb dbi sqlite3 interface noted in sisu 0.66.2 (2008-04-25) and 0.66.3 (2008-05-11) that have have persisted (apparently worked at end 2007 (v.0.62.4) and start of 2008 (v.0.64.0) * sqlite dropall, fix * fix to auto-generated sqlite cgi script sample, only works if at least one existing populated sisu sqlite database is found during the generation process
Diffstat (limited to 'lib/sisu/v0/db_import.rb')
-rw-r--r--lib/sisu/v0/db_import.rb48
1 files changed, 26 insertions, 22 deletions
diff --git a/lib/sisu/v0/db_import.rb b/lib/sisu/v0/db_import.rb
index bcdfc497..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,15 +124,8 @@ module SiSU_DB_import
tell.print_grey if @opt.cmd =~/v/
case @sql_type
when /sqlite/ #fix logic for sqlite !
-#sqlite watch
-unless @opt.cmd =~/[MVv]/
- puts "\nSiSU's sqlite module for the time being broken: inconsistent ruby dbi api for sqlite3, (unable to begin and commit transaction)\n".upcase
- p @conn.methods.sort
- #p "here #{__FILE__} #{__LINE__}"
- exit
-else
+ #sqlite watch
#pf_db_import_transaction_open if @opt =~/M/
- #@conn.begin
db_import_metadata
db_import_documents(@dal_array)
db_import_urls(@dal_array,@fnm) #import OID on/off
@@ -128,15 +133,10 @@ else
#@conn.commit
#@conn.close
#@conn.disconnect
- puts "\nSiSU's sqlite module for the time being broken: inconsistent ruby dbi api for sqlite3, (unable to begin and commit transaction)\n".upcase
- p @conn.methods.sort
- if @opt.cmd =~/M/
- puts "\n" + @conn.inspect
- puts "\nat #{__FILE__} #{__LINE__}"
- end
- exit
-end
-#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
@@ -191,9 +191,13 @@ end
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