aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/db_load_tuple.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2009-07-01 13:45:51 -0400
committerRalph Amissah <ralph@amissah.com>2009-07-01 13:45:51 -0400
commit0cdd579c809f3041df8842adb4d6f74d9cabd457 (patch)
tree36c902c33d24ea141653658b14d42cf50e7412a3 /lib/sisu/v0/db_load_tuple.rb
parentminor fixes and touches (diff)
db dbi, interfaces to sqlite and pgsql, fixes, pass individual sql statements
Diffstat (limited to 'lib/sisu/v0/db_load_tuple.rb')
-rw-r--r--lib/sisu/v0/db_load_tuple.rb67
1 files changed, 35 insertions, 32 deletions
diff --git a/lib/sisu/v0/db_load_tuple.rb b/lib/sisu/v0/db_load_tuple.rb
index 37bfb1e6..447e9354 100644
--- a/lib/sisu/v0/db_load_tuple.rb
+++ b/lib/sisu/v0/db_load_tuple.rb
@@ -22,7 +22,7 @@
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
@@ -77,38 +77,35 @@ module SiSU_DB_tuple
@cX=SiSU_Screen::Ansi.new(@opt.cmd).cX
end
def tuple #% import line
- begin
- sql_entry=if @col[:en_a]
- "INSERT INTO documents (lid, metadata_tid, lev, clean, body, ocn, ocnd, ocns, seg, lev1, lev2, lev3, lev4, lev5, lev6, en_a, en_z, digest_clean, digest_all) VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:en_a]}', '#{@col[:en_z]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');"
- else
- "INSERT INTO documents (lid, metadata_tid, lev, clean, body, ocn, ocnd, ocns, seg, lev1, lev2, lev3, lev4, lev5, lev6, digest_clean, digest_all) VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');"
- end
- if @opt.cmd =~/M/
- if @opt.cmd =~/V/
- puts @file.inspect
- puts sql_entry
- end
- @file.puts sql_entry
- else @conn.execute(sql_entry)
+ sql_entry=if @col[:en_a]
+ "INSERT INTO documents (lid, metadata_tid, lev, clean, body, ocn, ocnd, ocns, seg, lev1, lev2, lev3, lev4, lev5, lev6, en_a, en_z, digest_clean, digest_all) VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:en_a]}', '#{@col[:en_z]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');"
+ else
+ "INSERT INTO documents (lid, metadata_tid, lev, clean, body, ocn, ocnd, ocns, seg, lev1, lev2, lev3, lev4, lev5, lev6, digest_clean, digest_all) VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');"
+ end
+ if @opt.cmd =~/M/
+ if @opt.cmd =~/V/
+ puts @file.inspect
+ puts sql_entry
end
- if @opt.cmd =~/v/
- if @col[:lev].inspect =~/[1235678]/
- lev=case @col[:lev].inspect
- when /1/; ':A'
- when /2/; ':B'
- when /3/; ':C'
- when /5/; ' 2'
- when /6/; ' 3'
- end
- puts %{#{lev}>\t#{@col[:lv1]}\t#{@col[:lv2]}\t#{@col[:lv3]}\t#{@col[:lv4]}\t#{@col[:lv5]}\t#{@col[:lv6]}\t#{@col[:ocn]}\t#{@col[:ocnd]}\t#{@col[:ocns]}}
- elsif @col[:lev].inspect =~/[4]/
- puts %{ #{@cX.green}1>#{@cX.off}\t#{@col[:lv1]}\t#{@col[:lv2]}\t#{@col[:lv3]}\t#{@col[:lv4]}\t#{@col[:lv5]}\t#{@col[:lv6]}\t#{@col[:ocn]}\t#{@col[:ocnd]}\t#{@col[:ocns]}\t#{@col[:seg]}}
+ @file.puts sql_entry
+ else
+ @file.puts sql_entry if @opt.cmd =~/V/
+ end
+ if @opt.cmd =~/v/
+ if @col[:lev].inspect =~/[1235678]/
+ lev=case @col[:lev].inspect
+ when /1/; ':A'
+ when /2/; ':B'
+ when /3/; ':C'
+ when /5/; ' 2'
+ when /6/; ' 3'
end
+ puts %{#{lev}>\t#{@col[:lv1]}\t#{@col[:lv2]}\t#{@col[:lv3]}\t#{@col[:lv4]}\t#{@col[:lv5]}\t#{@col[:lv6]}\t#{@col[:ocn]}\t#{@col[:ocnd]}\t#{@col[:ocns]}}
+ elsif @col[:lev].inspect =~/[4]/
+ puts %{ #{@cX.green}1>#{@cX.off}\t#{@col[:lv1]}\t#{@col[:lv2]}\t#{@col[:lv3]}\t#{@col[:lv4]}\t#{@col[:lv5]}\t#{@col[:lv6]}\t#{@col[:ocn]}\t#{@col[:ocnd]}\t#{@col[:ocns]}\t#{@col[:seg]}}
end
- rescue; SiSU_Errors::Info_error.new($!,$@,@opt.cmd,@opt.fns).error
- ensure
- #@conn.execute("COMMIT")
end
+ sql_entry
end
end
class Load_metadata
@@ -120,8 +117,10 @@ module SiSU_DB_tuple
if @opt.cmd =~/M/
puts "maintenance mode on: creating sql transaction file (for last transaction set (document) only):\n\t#{@file.inspect}"
@file.puts sql_entry
- else @conn.execute(sql_entry)
+ else
+ @file.puts sql_entry if @opt.cmd =~/V/
end
+ sql_entry
end
end
class Load_urls
@@ -132,8 +131,10 @@ module SiSU_DB_tuple
sql_entry="INSERT INTO urls (#{@f[:txt]} #{@f[:html_toc]} #{@f[:html_doc]} #{@f[:xhtml]} #{@f[:xml_sax]} #{@f[:xml_dom]} #{@f[:odf]} #{@f[:pdf_p]} #{@f[:pdf_l]} #{@f[:concordance]} #{@f[:latex_p]} #{@f[:latex_l]} #{@f[:manifest]} #{@f[:digest]} #{@f[:markup]} #{@f[:sisupod]} metadata_tid) VALUES (#{@u[:txt]} #{@u[:html_toc]} #{@u[:html_doc]} #{@u[:xhtml]} #{@u[:xml_sax]} #{@u[:xml_dom]} #{@u[:odf]} #{@u[:pdf_p]} #{@u[:pdf_l]} #{@u[:concordance]} #{@u[:latex_p]} #{@u[:latex_l]} #{@u[:manifest]} #{@u[:digest]} #{@u[:markup]} #{@u[:sisupod]} #{@id});"
if @opt.cmd =~/M/
@file.puts sql_entry
- else @conn.execute(sql_entry)
+ else
+ @file.puts sql_entry if @opt.cmd =~/V/
end
+ sql_entry
end
end
class Load_endnotes
@@ -144,8 +145,10 @@ module SiSU_DB_tuple
sql_entry="INSERT INTO #{@en[:type]} (nid, document_lid, nr, clean, body, ocn, ocnd, ocns, metadata_tid, digest_clean) VALUES ('#{@en[:id]}', '#{@en[:lid]}', '#{@en[:nr]}', '#{@en[:txt]}', '#{@en[:body]}', '#{@en[:ocn]}', '#{@en[:ocnd]}', '#{@en[:ocns]}', '#{@en[:id_t]}', '#{@en[:hash]}');"
if @opt.cmd =~/M/
@file.puts sql_entry
- else @conn.execute(sql_entry)
+ else
+ @file.puts sql_entry if @opt.cmd =~/V/
end
+ sql_entry
end
end
end