aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v3/db_import.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2011-05-04 23:27:02 -0400
committerRalph Amissah <ralph@amissah.com>2011-05-04 23:41:00 -0400
commit2d79257e0b2fe90e036fa6554cadb2d587128bc5 (patch)
treee92fc587731e72310dc1ed61c501ed944c2a02a5 /lib/sisu/v3/db_import.rb
parentv3: urls, sqlite, a fix (diff)
v3: db, review, directory structure changed, database prefix renamed
* language_document_char field made larger [consider renaming] * title, src_filename and language_document_char fields mandatory (title, title_main, src_filename, language_document_char) * review of unique key setting, now based on combination of filename and language (filename no longer sufficient with intro of language subdirectories) * [retest sqlite3]
Diffstat (limited to 'lib/sisu/v3/db_import.rb')
-rw-r--r--lib/sisu/v3/db_import.rb30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/sisu/v3/db_import.rb b/lib/sisu/v3/db_import.rb
index 45bb37f3..541399a9 100644
--- a/lib/sisu/v3/db_import.rb
+++ b/lib/sisu/v3/db_import.rb
@@ -96,17 +96,17 @@ module SiSU_DB_import
@col[:lid] ||=0
@col[:lid]=@driver_sqlite3 \
? @conn.execute( sql ).join.to_i \
- : @conn.execute( sql ) { |x| x.fetch_all.to_s.to_i }
+ : @conn.execute( sql ) { |x| x.fetch_all.flatten[0] }
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=@driver_sqlite3 \
? @conn.execute( sql ).join.to_i \
- : @id_n=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i }
+ : @id_n=@conn.execute( sql ) { |x| x.fetch_all.flatten[0] }
+ @id_n ||=0
rescue
puts "#{__FILE__}:#{__LINE__}" if @opt.cmd =~/M/
end
@@ -121,7 +121,12 @@ module SiSU_DB_import
SiSU_Screen::Ansi.new(@opt.cmd,"#{@db.psql.db}::#{@opt.fns}").puts_blue if @opt.cmd =~/vVM/
SiSU_Screen::Ansi.new(@opt.cmd,'Marshal Load',@fnc).puts_grey if @opt.cmd =~/v/
#%
- select_first_match=%{ SELECT metadata_and_text.tid FROM metadata_and_text WHERE metadata_and_text.src_filename = '#{@opt.fns}' AND metadata_and_text.language_document_char = '#{@opt.lng}'; }
+ select_first_match=%{
+ SELECT metadata_and_text.tid
+ FROM metadata_and_text
+ WHERE metadata_and_text.src_filename = '#{@opt.fns}'
+ AND metadata_and_text.language_document_char = '#{@opt.lng}'
+ ;}
file_exist=@sql_type=~/sqlite/ \
? @conn.get_first_value(select_first_match) \
: @conn.select_one(select_first_match)
@@ -188,7 +193,7 @@ module SiSU_DB_import
else
if file_exist
@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}"
+ 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}"
end
end
end
@@ -216,18 +221,18 @@ module SiSU_DB_import
#@tp[:title]=@md.title.full
#special_character_escape(@tp[:title])
#@tp[:title_f],@tp[:title_i]='title, ',"'#{@tp[:title]}', "
- sql='SELECT MAX(tid) FROM metadata_and_text'
+ sql='SELECT MAX(tid) FROM metadata_and_text;'
begin
@@id_t ||=0
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 }
+ else
+ @conn.execute( sql ) { |x| x.fetch_all.flatten[0] }
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 @title:
puts %{\n#{@cX.grey}Processing file number#{@cX.off}: #{@cX.green}#{@@id_t}#{@@cX.off}} if @opt.cmd =~/vVM/
end
@@ -422,7 +427,8 @@ module SiSU_DB_import
txt=%{\n\nLARGE TEXT BLOCK OMITTED\n\n}
end
if txt
- en={ type: 'endnotes',
+ en={
+ type: 'endnotes',
id: @id_n,
lid: @col[:lid],
nr: nr,
@@ -460,7 +466,8 @@ module SiSU_DB_import
txt=%{\n\nLARGE TEXT BLOCK OMITTED\n\n}
end
if txt
- en={ type: 'endnotes_asterisk',
+ en={
+ type: 'endnotes_asterisk',
id: @id_n,
lid: @col[:lid],
nr: nr,
@@ -498,7 +505,8 @@ module SiSU_DB_import
txt=%{\n\nLARGE TEXT BLOCK OMITTED\n\n}
end
if txt
- en={ type: 'endnotes_plus',
+ en={
+ type: 'endnotes_plus',
id: @id_n,
lid: @col[:lid],
nr: nr,