aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sisu/v5/cgi_pgsql.rb22
-rw-r--r--lib/sisu/v5/cgi_sqlite.rb12
-rw-r--r--lib/sisu/v5/db_create.rb43
-rw-r--r--lib/sisu/v5/db_drop.rb38
-rw-r--r--lib/sisu/v5/db_import.rb22
-rw-r--r--lib/sisu/v5/db_indexes.rb20
-rw-r--r--lib/sisu/v5/db_remove.rb18
-rw-r--r--lib/sisu/v5/db_select.rb16
-rw-r--r--lib/sisu/v5/dbi.rb16
-rw-r--r--lib/sisu/v5/dbi_discrete.rb12
-rw-r--r--lib/sisu/v5/sysenv.rb2
-rw-r--r--lib/sisu/v6/cgi_pgsql.rb29
-rw-r--r--lib/sisu/v6/cgi_sqlite.rb12
-rw-r--r--lib/sisu/v6/db_create.rb43
-rw-r--r--lib/sisu/v6/db_drop.rb38
-rw-r--r--lib/sisu/v6/db_import.rb22
-rw-r--r--lib/sisu/v6/db_indexes.rb20
-rw-r--r--lib/sisu/v6/db_remove.rb18
-rw-r--r--lib/sisu/v6/db_select.rb16
-rw-r--r--lib/sisu/v6/dbi.rb23
-rw-r--r--lib/sisu/v6/dbi_discrete.rb12
-rw-r--r--lib/sisu/v6/sysenv.rb23
-rw-r--r--lib/sisu/v6/utils.rb14
23 files changed, 298 insertions, 193 deletions
diff --git a/lib/sisu/v5/cgi_pgsql.rb b/lib/sisu/v5/cgi_pgsql.rb
index 53c73c8d..6c4385e4 100644
--- a/lib/sisu/v5/cgi_pgsql.rb
+++ b/lib/sisu/v5/cgi_pgsql.rb
@@ -128,12 +128,9 @@ module SiSU_CGI_PgSQL
default database name: #{@cX.green}#{Db[:name_prefix]}#{@name_of[:db]}#{@cX.off} (#{@name_of[:db]})
db user: #{@cX.green}#{@name_of[:user]}#{@cX.off}
to modify use: #{@cX.brown}sisu --db-pg --db-user='#{@name_of[:user]}'#{@cX.off}
- cgi & db host on: #{@cX.blue}#{@name_of[:host_url_cgi]}#{@cX.off}
- to modify use: #{@cX.brown}sisu --db-pg --webserv-search='#{@name_of[:host_url_cgi]}'#{@cX.off}
- sisu output on: #{@cX.blue}#{@name_of[:host_url_docs]}#{@cX.off}
- to modify use: #{@cX.brown}sisu --db-pg --webserv-output='#{@name_of[:host_url_docs]}'#{@cX.off}
- cgi search form link name: #{@cX.green}#{@name_of[:cgi_script]}#{@cX.off}
- to modify use: #{@cX.brown}sisu --db-pg --cgi-search-form-name='#{@name_of[:cgi_script]}'#{@cX.off}
+ to create static cgi & db host use: #{@cX.brown}sisu --db-pg --webserv-search='#{@name_of[:host_url_cgi]}'#{@cX.off}
+ for static location for sisu output use: #{@cX.brown}sisu --db-pg --webserv-output='#{@name_of[:host_url_docs]}'#{@cX.off}
+ for static cgi search form link name use: #{@cX.brown}sisu --db-pg --cgi-search-form-name='#{@name_of[:cgi_script]}'#{@cX.off}
#{@cX.fuchsia}(settings priority: command line; sisurc.yml; else defaults)#{@cX.off}
#{@cX.fuchsia}BASED ON ALREADY EXISTING databases#{@cX.off} (default database name: #{@db.psql.db})
@@ -151,7 +148,7 @@ module SiSU_CGI_PgSQL
#{@cX.brown}createdb #{@db.psql.db}#{@cX.off}
[for a list of existing databases try 'psql --list']"
- now you can use sisu to create the database tables and populate the database with documents
+ you can use sisu to create the database tables and populate the database with documents
sisu --pg --dropall # removes existing postgresql db & tables
sisu --pg --createall -v # creates postgresql db & tables
@@ -195,9 +192,9 @@ module SiSU_CGI_PgSQL
begin
require 'cgi'
require 'fcgi'
- require 'dbi'
+ require 'pg'
rescue LoadError
- puts 'cgi, fcgi or dbi NOT FOUND (LoadError)'
+ puts 'cgi, fcgi or pg NOT FOUND (LoadError)'
end
@stub_default='#{@name_of[:db]}'
@image_src="#{@image_src}"
@@ -277,10 +274,10 @@ module SiSU_CGI_PgSQL
%{<font color="#666666" size="2">#{sql_select_endnotes}</font>}
end
def contents
- @conn.select_all(sql_select_body)
+ @conn.exec(sql_select_body)
end
def endnotes
- @conn.select_all(sql_select_endnotes)
+ @conn.exec(sql_select_endnotes)
end
end
WOK_SQL
@@ -292,8 +289,7 @@ module SiSU_CGI_PgSQL
end
def dbi_connect
<<-'WOK_SQL'
- dbi="dbi:Pg:database=#{@db};port=#{@port}"
- @conn=DBI.connect(dbi,@user)
+ @conn=PG::Connection.open(dbname: @db, port: @port, user: @user)
WOK_SQL
end
end
diff --git a/lib/sisu/v5/cgi_sqlite.rb b/lib/sisu/v5/cgi_sqlite.rb
index 4351a64c..2d185f20 100644
--- a/lib/sisu/v5/cgi_sqlite.rb
+++ b/lib/sisu/v5/cgi_sqlite.rb
@@ -172,9 +172,9 @@ module SiSU_CGI_SQLite
begin
require 'cgi'
require 'fcgi'
- require 'dbi'
+ require 'sqlite3'
rescue LoadError
- puts 'cgi, fcgi or dbi NOT FOUND (LoadError)'
+ puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)'
end
@stub_default='sisu_sqlite'
@image_src="#{@image_src}"
@@ -247,18 +247,18 @@ module SiSU_CGI_SQLite
%{<font color="#666666" size="2">#{sql_select_endnotes}</font>}
end
def contents
- @conn.select_all(sql_select_body)
+ @conn.execute(sql_select_body)
end
def endnotes
- @conn.select_all(sql_select_endnotes)
+ @conn.execute(sql_select_endnotes)
end
end
WOK_SQL
end
def dbi_connect
<<-'WOK_SQL'
- @dbi="DBI:SQLite3:#{db_sqlite}" #sqlite3 ?
- @conn=DBI.connect(@dbi)
+ @conn=SQLite3::Database.new(db_sqlite)
+ @conn.results_as_hash=true
WOK_SQL
end
end
diff --git a/lib/sisu/v5/db_create.rb b/lib/sisu/v5/db_create.rb
index 4de362c5..451a0a34 100644
--- a/lib/sisu/v5/db_create.rb
+++ b/lib/sisu/v5/db_create.rb
@@ -66,10 +66,10 @@ module SiSU_DbCreate
class Create < SiSU_DbColumns::Columns
require_relative 'sysenv' # sysenv.rb
@@dl=nil
- def initialize(opt,conn,file,sql_type='pg')
+ def initialize(opt,conn,file,sql_type=:pg)
@opt,@conn,@file,@sql_type=opt,conn,file,sql_type
@cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX
- @comment=(@sql_type=='pg') \
+ @comment=(@sql_type==:pg) \
? (SiSU_DbCreate::Comment.new(@conn,@sql_type))
: nil
@@dl ||=SiSU_Env::InfoEnv.new.digest.length
@@ -84,7 +84,7 @@ module SiSU_DbCreate
end
def create_db
@env=SiSU_Env::InfoEnv.new(@opt.fns)
- tell=(@sql_type=='sqlite') \
+ tell=(@sql_type==:sqlite) \
? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create SQLite db tables in:',%{"#{@file}"})
: SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create pgSQL db tables in:',%{"#{Db[:name_prefix]}#{@env.path.stub_pwd}"})
if (@opt.act[:verbose][:set]==:on \
@@ -92,7 +92,7 @@ module SiSU_DbCreate
|| @opt.act[:maintenance][:set]==:on)
tell.dark_grey_title_hi
end
- SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type=='pg' #watch use of path.stub_pwd instead of stub
+ SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type==:pg #watch use of path.stub_pwd instead of stub
end
def output_dir?
dir=SiSU_Env::InfoEnv.new('')
@@ -101,11 +101,24 @@ module SiSU_DbCreate
end
end
def create_table
+ def conn_exec(sql)
+ if @sql_type==:pg
+ conn_exec_pg(sql)
+ elsif @sql_type==:sqlite
+ conn_exec_sqlite(sql)
+ end
+ end
+ def conn_exec_pg(sql)
+ @conn.exec_params(sql)
+ end
+ def conn_exec_sqlite(sql)
+ @conn.execute(sql)
+ end
def metadata_and_text
if (@opt.act[:verbose_plus][:set]==:on \
or @opt.act[:maintenance][:set]==:on)
print %{
- currently using sisu dbi module
+ currently using sisu_dbi module
to be populated from document files
create tables metadata_and_text
data import through ruby transfer
@@ -211,7 +224,7 @@ module SiSU_DbCreate
/* writing_focus_nationality VARCHAR(100) NULL, */
);
}
- @conn.execute(create_metadata_and_text)
+ conn_exec(create_metadata_and_text)
@comment.psql.metadata_and_text if @comment
end
def doc_objects # create doc_objects base
@@ -258,7 +271,7 @@ module SiSU_DbCreate
types CHAR(1) NULL
);
}
- @conn.execute(create_doc_objects)
+ conn_exec(create_doc_objects)
@comment.psql.doc_objects if @comment
end
def endnotes
@@ -284,7 +297,7 @@ module SiSU_DbCreate
metadata_tid BIGINT REFERENCES metadata_and_text
);
}
- @conn.execute(create_endnotes)
+ conn_exec(create_endnotes)
@comment.psql.endnotes if @comment
end
def endnotes_asterisk
@@ -310,7 +323,7 @@ module SiSU_DbCreate
metadata_tid BIGINT REFERENCES metadata_and_text
);
}
- @conn.execute(create_endnotes_asterisk)
+ conn_exec(create_endnotes_asterisk)
@comment.psql.endnotes_asterisk if @comment
end
def endnotes_plus
@@ -336,14 +349,14 @@ module SiSU_DbCreate
metadata_tid BIGINT REFERENCES metadata_and_text
);
}
- @conn.execute(create_endnotes_plus)
+ conn_exec(create_endnotes_plus)
@comment.psql.endnotes_plus if @comment
end
def urls # create doc_objects file links mapping
if (@opt.act[:verbose_plus][:set]==:on \
or @opt.act[:maintenance][:set]==:on)
print %{
- currently using sisu dbi module
+ currently using sisu_dbi module
to be populated from doc_objects files
create tables urls
data import through ruby transfer
@@ -370,23 +383,23 @@ module SiSU_DbCreate
sisupod varchar(512)
);
}
- @conn.execute(create_urls)
+ conn_exec(create_urls)
@comment.psql.urls if @comment
end
self
end
end
class Comment < SiSU_DbColumns::Columns
- def initialize(conn,sql_type='pg')
+ def initialize(conn,sql_type=:pg)
@conn=conn
- if sql_type =~ /pg/; psql
+ if sql_type == :pg then psql
end
end
def psql
def conn_execute_array(sql_arr)
@conn.transaction do |conn|
sql_arr.each do |sql|
- conn.execute(sql)
+ conn.exec_params(sql)
end
end
end
diff --git a/lib/sisu/v5/db_drop.rb b/lib/sisu/v5/db_drop.rb
index b1ff634e..75e98faa 100644
--- a/lib/sisu/v5/db_drop.rb
+++ b/lib/sisu/v5/db_drop.rb
@@ -64,11 +64,11 @@
module SiSU_DbDrop
class Drop
require_relative 'response' # response.rb
- def initialize(opt,conn,db_info,sql_type='')
+ def initialize(opt,conn,db_info,sql_type)
@opt,@conn,@db_info,@sql_type=opt,conn,db_info,sql_type
@ans=SiSU_Response::Response.new
case @sql_type
- when /sqlite/
+ when :sqlite
cascade=''
else
cascade='CASCADE'
@@ -87,7 +87,7 @@ module SiSU_DbDrop
begin
msg_sqlite="as not all disk space is recovered after dropping the database << #{@db_info.sqlite.db} >>, you may be better off deleting the file, and recreating it as necessary"
case @sql_type
- when /sqlite/
+ when :sqlite
puts msg_sqlite
ans=@ans.response?('remove sql database?')
if ans \
@@ -118,24 +118,38 @@ module SiSU_DbDrop
else
@conn.transaction
@drop_table.each do |d|
- @conn.execute(d)
- end
+ begin
+ @conn.exec_params(d)
+ rescue
+ next
+ end
+ end
@conn.commit
end
- else
+ when :pg
+ @conn.transaction
@drop_table.each do |d|
- @conn.execute(d)
+ begin
+ @conn.exec_params(d)
+ rescue
+ next
+ end
end
+ @conn.commit
end
rescue
case @sql_type
- when /sqlite/
+ when :sqlite
ans=@ans.response?('remove sql database?')
if ans and File.exist?(@db_info.sqlite.db); File.unlink(@db_info.sqlite.db)
end
else
@drop_table.each do |d|
- @conn.execute(d)
+ begin
+ @conn.exec_params(d)
+ rescue
+ next
+ end
end
end
ensure
@@ -145,7 +159,11 @@ module SiSU_DbDrop
def conn_execute_array(sql_arr)
@conn.transaction do |conn|
sql_arr.each do |sql|
- conn.execute(sql)
+ begin
+ conn.exec_params(sql)
+ rescue
+ next
+ end
end
end
end
diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb
index 0dc5a29b..9e88e7ee 100644
--- a/lib/sisu/v5/db_import.rb
+++ b/lib/sisu/v5/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|
diff --git a/lib/sisu/v5/db_indexes.rb b/lib/sisu/v5/db_indexes.rb
index 0fa51b3f..7e1164ab 100644
--- a/lib/sisu/v5/db_indexes.rb
+++ b/lib/sisu/v5/db_indexes.rb
@@ -62,15 +62,29 @@
=end
module SiSU_DbIndex
- class Index # create documents Indexes def initialize(opt,conn='',sql_type='')
- def initialize(opt,conn,file,sql_type='')
+ class Index # create documents Indexes def initialize(opt,conn='',sql_type)
+ def initialize(opt,conn,file,sql_type)
@opt,@conn,@file,@sql_type=opt,conn,file,sql_type
end
def create_indexes # check added from pg not tested
+ def conn_execute_sql_pg(conn,sql)
+ conn.exec_params(sql)
+ end
+ def conn_execute_sql_sqlite(conn,sql)
+ conn.execute(sql)
+ end
+ def conn_execute_sql(conn,sql)
+ if @sql_type==:pg
+ conn_execute_sql_pg(conn,sql)
+ elsif @sql_type==:sqlite
+ conn_execute_sql_sqlite(conn,sql)
+ else
+ end
+ end
def conn_execute_array(sql_arr)
@conn.transaction do |conn|
sql_arr.each do |sql|
- conn.execute(sql)
+ conn_execute_sql(conn,sql)
end
end
end
diff --git a/lib/sisu/v5/db_remove.rb b/lib/sisu/v5/db_remove.rb
index 9ffba024..2dea65f2 100644
--- a/lib/sisu/v5/db_remove.rb
+++ b/lib/sisu/v5/db_remove.rb
@@ -70,7 +70,7 @@ module SiSU_DbRemove
@db=SiSU_Env::InfoDb.new
end
def remove
- driver_sqlite3=if @sql_type=='sqlite'
+ driver_sqlite3=if @sql_type==:sqlite
(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \
? true
: false
@@ -90,8 +90,8 @@ module SiSU_DbRemove
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
- x=@conn.select_one(remove_selected)
- x ? (x.join.to_i) : nil
+ x=@conn.exec(remove_selected)
+ x.field_values("tid")[0]
end
if del_id
sql_entry=[
@@ -105,12 +105,20 @@ module SiSU_DbRemove
if driver_sqlite3
@conn.transaction
sql_entry.each do |s|
- @conn.execute(s)
+ begin
+ @conn.execute(s)
+ rescue
+ next
+ end
end
@conn.commit if driver_sqlite3
else
sql_entry.each do |s|
- @conn.execute(s)
+ begin
+ @conn.exec_params(s)
+ rescue
+ next
+ end
end
end
if @opt.act[:maintenance][:set]==:on
diff --git a/lib/sisu/v5/db_select.rb b/lib/sisu/v5/db_select.rb
index 06d8c429..3aebe828 100644
--- a/lib/sisu/v5/db_select.rb
+++ b/lib/sisu/v5/db_select.rb
@@ -63,7 +63,7 @@
=end
module SiSU_DbSelect
class Case
- def initialize(opt,conn='',sql_type='pg')
+ def initialize(opt,conn='',sql_type=:pg)
@opt,@conn,@sql_type=opt,conn,sql_type
@db=SiSU_Env::InfoDb.new
@file_maint=sql_maintenance_file
@@ -78,13 +78,13 @@ module SiSU_DbSelect
end
end
def db_exist?
- if @sql_type=='sqlite' \
+ if @sql_type==:sqlite \
and (not (FileTest.file?(@db.sqlite.db)) or FileTest.zero?(@db.sqlite.db))
puts %{no connection with #{@sql_type} database established, createdb "#{@db.sqlite.db}"?}
exit
end
if @conn.is_a?(NilClass)
- db=@sql_type=='sqlite' \
+ db=@sql_type==:sqlite \
? @db.sqlite.db
: @db.psql.db
puts %{no connection with #{@sql_type} database established, createdb "#{db}"?}
@@ -95,7 +95,7 @@ module SiSU_DbSelect
file=if @opt.inspect =~/M/
if @opt.fns and not @opt.fns.empty?
@env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns
- puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on
+ puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on
@db=SiSU_Env::InfoDb.new
@job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql"
File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+')
@@ -173,8 +173,8 @@ module SiSU_DbSelect
db_exist?
@sdb_import.marshal_load
tell=case @sql_type
- when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
- when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
+ when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
+ when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
else '???'
end
tell.puts_grey if @opt.act[:verbose][:set]==:on
@@ -183,8 +183,8 @@ module SiSU_DbSelect
@sdb_remove_doc.remove
@sdb_import.marshal_load
tell=case @sql_type
- when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
- when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
+ when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
+ when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
else '???'
end
tell.puts_grey if @opt.act[:verbose][:set]==:on
diff --git a/lib/sisu/v5/dbi.rb b/lib/sisu/v5/dbi.rb
index 1ab9bc9c..737f02fd 100644
--- a/lib/sisu/v5/dbi.rb
+++ b/lib/sisu/v5/dbi.rb
@@ -79,22 +79,22 @@ module SiSU_DBI
@sql_type=if @opt.cmd=~/D/ \
or @opt.mod.inspect =~/--pg(?:sql)?/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'pg'
+ :pg
elsif @opt.cmd =~/d/ \
and @opt.mod.inspect =~/--(?:db[=-])?pg(?:sql)?/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'pg'
+ :pg
elsif @opt.cmd=~/d/ \
or @opt.mod.inspect =~/--(?:sq)?lite/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'sqlite'
+ :sqlite
elsif @opt.cmd =~/d/ \
and @opt.mod.inspect =~/--(?:db[=-])?(?:sq)?lite/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'sqlite'
+ :sqlite
else
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'sqlite'
+ :sqlite
end
end
end
@@ -107,7 +107,7 @@ module SiSU_DBI
begin
@conn=@db.psql.conn_dbi
rescue
- if @opt.mod.inspect=~/--(createall|create)/
+ if @opt.mod.inspect=~/--(?:createall|create)/
cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX
puts <<-WOK
manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet exist
@@ -130,8 +130,8 @@ manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet
end
def connect
case @sql_type
- when /pg/ then read_psql
- when /sqlite/ then read_sqlite
+ when :pg then read_psql #read_pg
+ when :sqlite then read_sqlite
end
SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"DBI (#{@sql_type}) #{@opt.mod}",@opt.fno).dbi_title unless @opt.act[:quiet][:set]==:on
begin
diff --git a/lib/sisu/v5/dbi_discrete.rb b/lib/sisu/v5/dbi_discrete.rb
index cd8c7de1..0b42c50e 100644
--- a/lib/sisu/v5/dbi_discrete.rb
+++ b/lib/sisu/v5/dbi_discrete.rb
@@ -77,13 +77,13 @@ module SiSU_DBI_Discrete #% database building
end
class SQL
def initialize(opt)
- SiSU_Env::Load.new('dbi',true).prog
+ SiSU_Env::Load.new('sqlite3',true).prog
@opt=opt
@particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
@md=@particulars.md
if @opt.cmd =~/[d]/ \
or @opt.mod.inspect =~/--((?:sq)?lite)/
- @sql_type='sqlite'
+ @sql_type=:sqlite
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
end
@output_path=@md.file.output_path.sqlite_discrete.dir
@@ -122,8 +122,8 @@ module SiSU_DBI_Discrete #% database building
def create_and_populate
db=SiSU_Env::DbOp.new(@md)
conn=db.sqlite_discrete.conn_sqlite3
- sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,'sqlite')
- sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,'sqlite')
+ sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,:sqlite)
+ sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,:sqlite)
sdb.output_dir?
begin
SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'SQLite',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_title_hi unless @opt.act[:quiet][:set]==:on
@@ -136,7 +136,7 @@ module SiSU_DBI_Discrete #% database building
sdb.create_table.urls
sdb_index.create_indexes
db_exist?(db,conn)
- sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,'sqlite')
+ sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,:sqlite)
sdb_import.marshal_load
tell=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{db.sqlite.db} database?")
tell.puts_grey if @opt.act[:verbose][:set]==:on
@@ -174,7 +174,7 @@ module SiSU_DBI_Discrete #% database building
file=if @opt.inspect =~/M/
if @opt.fns and not @opt.fns.empty?
@env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns
- puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on
+ puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on
@db=SiSU_Env::InfoDb.new
@job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql"
File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+')
diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb
index 491ca94f..4b94003c 100644
--- a/lib/sisu/v5/sysenv.rb
+++ b/lib/sisu/v5/sysenv.rb
@@ -2594,7 +2594,7 @@ WOK
else
(opt.mod.inspect =~/--db[=-]["']?sqlite/) \
? "#{Db[:name_prefix_db]}sqlite.cgi" \
- : "#{Db[:name_prefix_db]}pgsql.cgi"
+ : "#{Db[:name_prefix_db]}pg.cgi"
end
end
def sample_search_form_title(organised_by=:language)
diff --git a/lib/sisu/v6/cgi_pgsql.rb b/lib/sisu/v6/cgi_pgsql.rb
index a52b62e3..8372bb70 100644
--- a/lib/sisu/v6/cgi_pgsql.rb
+++ b/lib/sisu/v6/cgi_pgsql.rb
@@ -82,16 +82,15 @@ module SiSU_CGI_PgSQL
opt.lingual.to_s
else 'multi'
end
- if defined? @rc['search'] \
+ @name_of[:db]=if defined? @rc['search'] \
and defined? @rc['search']['sisu'] \
and defined? @rc['search']['sisu']['action'] \
and @rc['search']['sisu']['action'] =~/https?:\/\/\S+?\.cgi/ \
and defined? @rc['search']['sisu']['db'] \
and @rc['search']['sisu']['db'] =~/\S+/
- @name_of[:db]=@rc['search']['sisu']['db']
+ @rc['search']['sisu']['db']
else
- @name_of[:db]=@env.path.stub_pwd #'sisu' #breaks if not present
- false
+ @env.path.stub_pwd #'sisu' #breaks if not present
end
@name_of[:host_url_cgi]=%q{http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}}
@name_of[:host_url_docs]=%q{http://#{ENV['HTTP_HOST']}}
@@ -128,13 +127,6 @@ module SiSU_CGI_PgSQL
default database name: #{@cX.green}#{Db[:name_prefix]}#{@name_of[:db]}#{@cX.off} (#{@name_of[:db]})
db user: #{@cX.green}#{@name_of[:user]}#{@cX.off}
to modify use: #{@cX.brown}sisu --db-pg --db-user='#{@name_of[:user]}'#{@cX.off}
- cgi & db host on: #{@cX.blue}#{@name_of[:host_url_cgi]}#{@cX.off}
- to modify use: #{@cX.brown}sisu --db-pg --webserv-search='#{@name_of[:host_url_cgi]}'#{@cX.off}
- sisu output on: #{@cX.blue}#{@name_of[:host_url_docs]}#{@cX.off}
- to modify use: #{@cX.brown}sisu --db-pg --webserv-output='#{@name_of[:host_url_docs]}'#{@cX.off}
- cgi search form link name: #{@cX.green}#{@name_of[:cgi_script]}#{@cX.off}
- to modify use: #{@cX.brown}sisu --db-pg --cgi-search-form-name='#{@name_of[:cgi_script]}'#{@cX.off}
- #{@cX.fuchsia}(settings priority: command line; sisurc.yml; else defaults)#{@cX.off}
#{@cX.fuchsia}BASED ON ALREADY EXISTING databases#{@cX.off} (default database name: #{@db.psql.db})
NOTE it is first necessary to createdb,
@@ -151,12 +143,12 @@ module SiSU_CGI_PgSQL
#{@cX.brown}createdb #{@db.psql.db}#{@cX.off}
[for a list of existing databases try 'psql --list']"
- now you can use sisu to create the database tables and populate the database with documents
+ you can use sisu to create the database tables and populate the database with documents
sisu --pg --dropall # removes existing postgresql db & tables
sisu --pg --createall -v # creates postgresql db & tables
sisu --pg --update -v *.sst *.ssm # populate the db
- sisu --sample-search-form --pg # creates the postgresql search form
+ sisu --sample-search-form --db-pg # creates the postgresql search form
# this should be done after creating the db
# to be searched
sisu --webrick & # starts ruby webrick web server
@@ -195,9 +187,9 @@ module SiSU_CGI_PgSQL
begin
require 'cgi'
require 'fcgi'
- require 'dbi'
+ require 'pg'
rescue LoadError
- puts 'cgi, fcgi or dbi NOT FOUND (LoadError)'
+ puts 'cgi, fcgi or pg NOT FOUND (LoadError)'
end
@stub_default='#{@name_of[:db]}'
@image_src="#{@image_src}"
@@ -277,10 +269,10 @@ module SiSU_CGI_PgSQL
%{<font color="#666666" size="2">#{sql_select_endnotes}</font>}
end
def contents
- @conn.select_all(sql_select_body)
+ @conn.exec(sql_select_body)
end
def endnotes
- @conn.select_all(sql_select_endnotes)
+ @conn.exec(sql_select_endnotes)
end
end
WOK_SQL
@@ -292,8 +284,7 @@ module SiSU_CGI_PgSQL
end
def dbi_connect
<<-'WOK_SQL'
- dbi="dbi:Pg:database=#{@db};port=#{@port}"
- @conn=DBI.connect(dbi,@user)
+ @conn=PG::Connection.open(dbname: @db, port: @port, user: @user)
WOK_SQL
end
end
diff --git a/lib/sisu/v6/cgi_sqlite.rb b/lib/sisu/v6/cgi_sqlite.rb
index 696b6817..f64c3cf6 100644
--- a/lib/sisu/v6/cgi_sqlite.rb
+++ b/lib/sisu/v6/cgi_sqlite.rb
@@ -172,9 +172,9 @@ module SiSU_CGI_SQLite
begin
require 'cgi'
require 'fcgi'
- require 'dbi'
+ require 'sqlite3'
rescue LoadError
- puts 'cgi, fcgi or dbi NOT FOUND (LoadError)'
+ puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)'
end
@stub_default='sisu_sqlite'
@image_src="#{@image_src}"
@@ -247,18 +247,18 @@ module SiSU_CGI_SQLite
%{<font color="#666666" size="2">#{sql_select_endnotes}</font>}
end
def contents
- @conn.select_all(sql_select_body)
+ @conn.execute(sql_select_body)
end
def endnotes
- @conn.select_all(sql_select_endnotes)
+ @conn.execute(sql_select_endnotes)
end
end
WOK_SQL
end
def dbi_connect
<<-'WOK_SQL'
- @dbi="DBI:SQLite3:#{db_sqlite}" #sqlite3 ?
- @conn=DBI.connect(@dbi)
+ @conn=SQLite3::Database.new(db_sqlite)
+ @conn.results_as_hash=true
WOK_SQL
end
end
diff --git a/lib/sisu/v6/db_create.rb b/lib/sisu/v6/db_create.rb
index 661059a1..01fc1935 100644
--- a/lib/sisu/v6/db_create.rb
+++ b/lib/sisu/v6/db_create.rb
@@ -66,10 +66,10 @@ module SiSU_DbCreate
class Create < SiSU_DbColumns::Columns
require_relative 'sysenv' # sysenv.rb
@@dl=nil
- def initialize(opt,conn,file,sql_type='pg')
+ def initialize(opt,conn,file,sql_type=:pg)
@opt,@conn,@file,@sql_type=opt,conn,file,sql_type
@cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX
- @comment=(@sql_type=='pg') \
+ @comment=(@sql_type==:pg) \
? (SiSU_DbCreate::Comment.new(@conn,@sql_type))
: nil
@@dl ||=SiSU_Env::InfoEnv.new.digest.length
@@ -84,7 +84,7 @@ module SiSU_DbCreate
end
def create_db
@env=SiSU_Env::InfoEnv.new(@opt.fns)
- tell=(@sql_type=='sqlite') \
+ tell=(@sql_type==:sqlite) \
? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create SQLite db tables in:',%{"#{@file}"})
: SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Create pgSQL db tables in:',%{"#{Db[:name_prefix]}#{@env.path.stub_pwd}"})
if (@opt.act[:verbose][:set]==:on \
@@ -92,7 +92,7 @@ module SiSU_DbCreate
|| @opt.act[:maintenance][:set]==:on)
tell.dark_grey_title_hi
end
- SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type=='pg' #watch use of path.stub_pwd instead of stub
+ SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type==:pg #watch use of path.stub_pwd instead of stub
end
def output_dir?
dir=SiSU_Env::InfoEnv.new('')
@@ -101,11 +101,24 @@ module SiSU_DbCreate
end
end
def create_table
+ def conn_exec(sql)
+ if @sql_type==:pg
+ conn_exec_pg(sql)
+ elsif @sql_type==:sqlite
+ conn_exec_sqlite(sql)
+ end
+ end
+ def conn_exec_pg(sql)
+ @conn.exec_params(sql)
+ end
+ def conn_exec_sqlite(sql)
+ @conn.execute(sql)
+ end
def metadata_and_text
if (@opt.act[:verbose_plus][:set]==:on \
or @opt.act[:maintenance][:set]==:on)
print %{
- currently using sisu dbi module
+ currently using sisu_dbi module
to be populated from document files
create tables metadata_and_text
data import through ruby transfer
@@ -211,7 +224,7 @@ module SiSU_DbCreate
/* writing_focus_nationality VARCHAR(100) NULL, */
);
}
- @conn.execute(create_metadata_and_text)
+ conn_exec(create_metadata_and_text)
@comment.psql.metadata_and_text if @comment
end
def doc_objects # create doc_objects base
@@ -258,7 +271,7 @@ module SiSU_DbCreate
types CHAR(1) NULL
);
}
- @conn.execute(create_doc_objects)
+ conn_exec(create_doc_objects)
@comment.psql.doc_objects if @comment
end
def endnotes
@@ -284,7 +297,7 @@ module SiSU_DbCreate
metadata_tid BIGINT REFERENCES metadata_and_text
);
}
- @conn.execute(create_endnotes)
+ conn_exec(create_endnotes)
@comment.psql.endnotes if @comment
end
def endnotes_asterisk
@@ -310,7 +323,7 @@ module SiSU_DbCreate
metadata_tid BIGINT REFERENCES metadata_and_text
);
}
- @conn.execute(create_endnotes_asterisk)
+ conn_exec(create_endnotes_asterisk)
@comment.psql.endnotes_asterisk if @comment
end
def endnotes_plus
@@ -336,14 +349,14 @@ module SiSU_DbCreate
metadata_tid BIGINT REFERENCES metadata_and_text
);
}
- @conn.execute(create_endnotes_plus)
+ conn_exec(create_endnotes_plus)
@comment.psql.endnotes_plus if @comment
end
def urls # create doc_objects file links mapping
if (@opt.act[:verbose_plus][:set]==:on \
or @opt.act[:maintenance][:set]==:on)
print %{
- currently using sisu dbi module
+ currently using sisu_dbi module
to be populated from doc_objects files
create tables urls
data import through ruby transfer
@@ -370,23 +383,23 @@ module SiSU_DbCreate
sisupod varchar(512)
);
}
- @conn.execute(create_urls)
+ conn_exec(create_urls)
@comment.psql.urls if @comment
end
self
end
end
class Comment < SiSU_DbColumns::Columns
- def initialize(conn,sql_type='pg')
+ def initialize(conn,sql_type=:pg)
@conn=conn
- if sql_type =~ /pg/; psql
+ if sql_type == :pg then psql
end
end
def psql
def conn_execute_array(sql_arr)
@conn.transaction do |conn|
sql_arr.each do |sql|
- conn.execute(sql)
+ conn.exec_params(sql)
end
end
end
diff --git a/lib/sisu/v6/db_drop.rb b/lib/sisu/v6/db_drop.rb
index 94fc5e99..926da47f 100644
--- a/lib/sisu/v6/db_drop.rb
+++ b/lib/sisu/v6/db_drop.rb
@@ -64,11 +64,11 @@
module SiSU_DbDrop
class Drop
require_relative 'response' # response.rb
- def initialize(opt,conn,db_info,sql_type='')
+ def initialize(opt,conn,db_info,sql_type)
@opt,@conn,@db_info,@sql_type=opt,conn,db_info,sql_type
@ans=SiSU_Response::Response.new
case @sql_type
- when /sqlite/
+ when :sqlite
cascade=''
else
cascade='CASCADE'
@@ -87,7 +87,7 @@ module SiSU_DbDrop
begin
msg_sqlite="as not all disk space is recovered after dropping the database << #{@db_info.sqlite.db} >>, you may be better off deleting the file, and recreating it as necessary"
case @sql_type
- when /sqlite/
+ when :sqlite
puts msg_sqlite
ans=@ans.response?('remove sql database?')
if ans \
@@ -118,24 +118,38 @@ module SiSU_DbDrop
else
@conn.transaction
@drop_table.each do |d|
- @conn.execute(d)
- end
+ begin
+ @conn.exec_params(d)
+ rescue
+ next
+ end
+ end
@conn.commit
end
- else
+ when :pg
+ @conn.transaction
@drop_table.each do |d|
- @conn.execute(d)
+ begin
+ @conn.exec_params(d)
+ rescue
+ next
+ end
end
+ @conn.commit
end
rescue
case @sql_type
- when /sqlite/
+ when :sqlite
ans=@ans.response?('remove sql database?')
if ans and File.exist?(@db_info.sqlite.db); File.unlink(@db_info.sqlite.db)
end
else
@drop_table.each do |d|
- @conn.execute(d)
+ begin
+ @conn.exec_params(d)
+ rescue
+ next
+ end
end
end
ensure
@@ -145,7 +159,11 @@ module SiSU_DbDrop
def conn_execute_array(sql_arr)
@conn.transaction do |conn|
sql_arr.each do |sql|
- conn.execute(sql)
+ begin
+ conn.exec_params(sql)
+ rescue
+ next
+ end
end
end
end
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|
diff --git a/lib/sisu/v6/db_indexes.rb b/lib/sisu/v6/db_indexes.rb
index f293012f..7df20889 100644
--- a/lib/sisu/v6/db_indexes.rb
+++ b/lib/sisu/v6/db_indexes.rb
@@ -62,15 +62,29 @@
=end
module SiSU_DbIndex
- class Index # create documents Indexes def initialize(opt,conn='',sql_type='')
- def initialize(opt,conn,file,sql_type='')
+ class Index # create documents Indexes def initialize(opt,conn='',sql_type)
+ def initialize(opt,conn,file,sql_type)
@opt,@conn,@file,@sql_type=opt,conn,file,sql_type
end
def create_indexes # check added from pg not tested
+ def conn_execute_sql_pg(conn,sql)
+ conn.exec_params(sql)
+ end
+ def conn_execute_sql_sqlite(conn,sql)
+ conn.execute(sql)
+ end
+ def conn_execute_sql(conn,sql)
+ if @sql_type==:pg
+ conn_execute_sql_pg(conn,sql)
+ elsif @sql_type==:sqlite
+ conn_execute_sql_sqlite(conn,sql)
+ else
+ end
+ end
def conn_execute_array(sql_arr)
@conn.transaction do |conn|
sql_arr.each do |sql|
- conn.execute(sql)
+ conn_execute_sql(conn,sql)
end
end
end
diff --git a/lib/sisu/v6/db_remove.rb b/lib/sisu/v6/db_remove.rb
index 650c84a2..b1628030 100644
--- a/lib/sisu/v6/db_remove.rb
+++ b/lib/sisu/v6/db_remove.rb
@@ -70,7 +70,7 @@ module SiSU_DbRemove
@db=SiSU_Env::InfoDb.new
end
def remove
- driver_sqlite3=if @sql_type=='sqlite'
+ driver_sqlite3=if @sql_type==:sqlite
(@conn.inspect.match(/^(.{10})/)[1]==@db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]) \
? true
: false
@@ -90,8 +90,8 @@ module SiSU_DbRemove
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
- x=@conn.select_one(remove_selected)
- x ? (x.join.to_i) : nil
+ x=@conn.exec(remove_selected)
+ x.field_values("tid")[0]
end
if del_id
sql_entry=[
@@ -105,12 +105,20 @@ module SiSU_DbRemove
if driver_sqlite3
@conn.transaction
sql_entry.each do |s|
- @conn.execute(s)
+ begin
+ @conn.execute(s)
+ rescue
+ next
+ end
end
@conn.commit if driver_sqlite3
else
sql_entry.each do |s|
- @conn.execute(s)
+ begin
+ @conn.exec_params(s)
+ rescue
+ next
+ end
end
end
if @opt.act[:maintenance][:set]==:on
diff --git a/lib/sisu/v6/db_select.rb b/lib/sisu/v6/db_select.rb
index 56b424d7..9a2c2eb0 100644
--- a/lib/sisu/v6/db_select.rb
+++ b/lib/sisu/v6/db_select.rb
@@ -63,7 +63,7 @@
=end
module SiSU_DbSelect
class Case
- def initialize(opt,conn='',sql_type='pg')
+ def initialize(opt,conn='',sql_type=:pg)
@opt,@conn,@sql_type=opt,conn,sql_type
@db=SiSU_Env::InfoDb.new
@file_maint=sql_maintenance_file
@@ -78,13 +78,13 @@ module SiSU_DbSelect
end
end
def db_exist?
- if @sql_type=='sqlite' \
+ if @sql_type==:sqlite \
and (not (FileTest.file?(@db.sqlite.db)) or FileTest.zero?(@db.sqlite.db))
puts %{no connection with #{@sql_type} database established, createdb "#{@db.sqlite.db}"?}
exit
end
if @conn.is_a?(NilClass)
- db=@sql_type=='sqlite' \
+ db=@sql_type==:sqlite \
? @db.sqlite.db
: @db.psql.db
puts %{no connection with #{@sql_type} database established, createdb "#{db}"?}
@@ -95,7 +95,7 @@ module SiSU_DbSelect
file=if @opt.inspect =~/M/
if @opt.fns and not @opt.fns.empty?
@env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns
- puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on
+ puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on
@db=SiSU_Env::InfoDb.new
@job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql"
File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+')
@@ -173,8 +173,8 @@ module SiSU_DbSelect
db_exist?
@sdb_import.marshal_load
tell=case @sql_type
- when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
- when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
+ when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
+ when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
else '???'
end
tell.puts_grey if @opt.act[:verbose][:set]==:on
@@ -183,8 +183,8 @@ module SiSU_DbSelect
@sdb_remove_doc.remove
@sdb_import.marshal_load
tell=case @sql_type
- when /sqlite/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
- when /pg/ then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
+ when :sqlite then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{@db.sqlite.db} database?")
+ when :pg then SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"pgaccess or psql #{@db.psql.db} database?")
else '???'
end
tell.puts_grey if @opt.act[:verbose][:set]==:on
diff --git a/lib/sisu/v6/dbi.rb b/lib/sisu/v6/dbi.rb
index acb75e0f..7432f2f3 100644
--- a/lib/sisu/v6/dbi.rb
+++ b/lib/sisu/v6/dbi.rb
@@ -71,7 +71,6 @@ module SiSU_DBI
include SiSU_FormatShared
class SQL
def initialize(opt)
- SiSU_Env::Load.new('dbi',true).prog
@opt=opt
@db=SiSU_Env::InfoDb.new
if @opt.cmd =~/[Dd]/ \
@@ -79,22 +78,25 @@ module SiSU_DBI
@sql_type=if @opt.cmd=~/D/ \
or @opt.mod.inspect =~/--pg(?:sql)?/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'pg'
+ :pg
elsif @opt.cmd =~/d/ \
and @opt.mod.inspect =~/--(?:db[=-])?pg(?:sql)?/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'pg'
+ :pg
elsif @opt.cmd=~/d/ \
or @opt.mod.inspect =~/--(?:sq)?lite/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'sqlite'
+ :sqlite
elsif @opt.cmd =~/d/ \
and @opt.mod.inspect =~/--(?:db[=-])?(?:sq)?lite/
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'sqlite'
+ :sqlite
else
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
- 'sqlite'
+ :sqlite
+ end
+ if @sql_type==:pg then SiSU_Env::Load.new('pg',true).prog
+ elsif @sql_type==:sqlite then SiSU_Env::Load.new('sqlite3',true).prog
end
end
end
@@ -105,9 +107,10 @@ module SiSU_DBI
end
def read_psql
begin
- @conn=@db.psql.conn_dbi
+ require 'pg'
+ @conn=@db.psql.conn_pg
rescue
- if @opt.mod.inspect=~/--(createall|create)/
+ if @opt.mod.inspect=~/--(?:createall|create)/
cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX
puts <<-WOK
manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet exist
@@ -130,8 +133,8 @@ manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet
end
def connect
case @sql_type
- when /pg/ then read_psql
- when /sqlite/ then read_sqlite
+ when :pg then read_psql #read_pg
+ when :sqlite then read_sqlite
end
SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"DBI (#{@sql_type}) #{@opt.mod}",@opt.fno).dbi_title unless @opt.act[:quiet][:set]==:on
begin
diff --git a/lib/sisu/v6/dbi_discrete.rb b/lib/sisu/v6/dbi_discrete.rb
index 0ac84db4..0f534e42 100644
--- a/lib/sisu/v6/dbi_discrete.rb
+++ b/lib/sisu/v6/dbi_discrete.rb
@@ -77,13 +77,13 @@ module SiSU_DBI_Discrete #% database building
end
class SQL
def initialize(opt)
- SiSU_Env::Load.new('dbi',true).prog
+ SiSU_Env::Load.new('sqlite3',true).prog
@opt=opt
@particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
@md=@particulars.md
if @opt.cmd =~/[d]/ \
or @opt.mod.inspect =~/--((?:sq)?lite)/
- @sql_type='sqlite'
+ @sql_type=:sqlite
maintenance_check(@opt,__FILE__,__LINE__) if @opt.act[:maintenance][:set]==:on
end
@output_path=@md.file.output_path.sqlite_discrete.dir
@@ -122,8 +122,8 @@ module SiSU_DBI_Discrete #% database building
def create_and_populate
db=SiSU_Env::DbOp.new(@md)
conn=db.sqlite_discrete.conn_sqlite3
- sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,'sqlite')
- sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,'sqlite')
+ sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,:sqlite)
+ sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,:sqlite)
sdb.output_dir?
begin
SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'SQLite',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_title_hi unless @opt.act[:quiet][:set]==:on
@@ -136,7 +136,7 @@ module SiSU_DBI_Discrete #% database building
sdb.create_table.urls
sdb_index.create_indexes
db_exist?(db,conn)
- sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,'sqlite')
+ sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file_maint,:sqlite)
sdb_import.marshal_load
tell=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"sqlite3 #{db.sqlite.db} database?")
tell.puts_grey if @opt.act[:verbose][:set]==:on
@@ -174,7 +174,7 @@ module SiSU_DBI_Discrete #% database building
file=if @opt.inspect =~/M/
if @opt.fns and not @opt.fns.empty?
@env=SiSU_Env::InfoEnv.new(@opt.fns) if @opt.fns
- puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type =~/sqlite/ and @opt.act[:maintenance][:set]==:on
+ puts "\n#{@env.processing_path.sqlite}/#{@opt.fns}.sql" if @sql_type ==:sqlite and @opt.act[:maintenance][:set]==:on
@db=SiSU_Env::InfoDb.new
@job="sqlite3 #{@db.sqlite.db} < #{@env.processing_path.sqlite}/#{@opt.fns}.sql"
File.new("#{@env.processing_path.sqlite}/#{@opt.fns}.sql",'w+')
diff --git a/lib/sisu/v6/sysenv.rb b/lib/sisu/v6/sysenv.rb
index 8c819d9b..2c2a8c10 100644
--- a/lib/sisu/v6/sysenv.rb
+++ b/lib/sisu/v6/sysenv.rb
@@ -249,7 +249,9 @@ module SiSU_Env
$:.each do |reqpath|
if FileTest.exist?("#{reqpath}/#{@prog}.rb")
load_prog=true
+ #SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).ok("#{reqpath}/#{@prog}.rb loaded")
break
+ #else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).warn("#{reqpath}/#{@prog}.rb not found")
end
end
if load_prog \
@@ -2673,7 +2675,7 @@ WOK
else
(opt.mod.inspect =~/--db[=-]["']?sqlite/) \
? "#{Db[:name_prefix_db]}sqlite.cgi" \
- : "#{Db[:name_prefix_db]}pgsql.cgi"
+ : "#{Db[:name_prefix_db]}pg.cgi"
end
end
def sample_search_form_title(organised_by=:language)
@@ -4428,6 +4430,9 @@ WOK
: ''
end
def dbi
+ PG::Connection.open(:dbname => psql.db)
+ end
+ def dbi_
(psql.host =~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \
? "DBI:Pg:database=#{psql.db};host=#{psql.host};port=#{psql.port}"
: "DBI:Pg:database=#{psql.db};port=#{psql.port}"
@@ -4435,19 +4440,11 @@ WOK
def conn_dbi
DBI.connect(psql.dbi,psql.user,psql.db)
end
- self
- end
- def mysql
- def db
- #"#{Db[:name_prefix]}#{@pwd_stub}"
- end
- def port
- '**'
+ def conn_pg
+ require 'pg'
+ PG::Connection.new(dbname: psql.db, port: psql.port)
end
- def dbi
- "dbi:Mysql:database=#{mysql.db};port=#{mysql.port}"
- end
- self
+ self
end
def sqlite
def db
diff --git a/lib/sisu/v6/utils.rb b/lib/sisu/v6/utils.rb
index 8f9e17b8..5879db27 100644
--- a/lib/sisu/v6/utils.rb
+++ b/lib/sisu/v6/utils.rb
@@ -133,6 +133,18 @@ module SiSU_Utils
def mark(v=nil,x=nil)
puts set(v,x)
end
+ def ok(v=nil,x=nil)
+ if (v.is_a?(Symbol) \
+ and x.is_a?(String))
+ x= '*OK* ' + x
+ elsif v.is_a?(String)
+ v='*OK* ' + v
+ x=nil
+ else
+ v,x='*OK*',nil
+ end
+ puts set(v,x)
+ end
def warn(v=nil,x=nil)
if (v.is_a?(Symbol) \
and x.is_a?(String))
@@ -143,7 +155,7 @@ module SiSU_Utils
else
v,x='*WARN*',nil
end
- STDERR.puts set(v,x)
+ puts set(v,x)
end
def error(v=nil,x=nil)
if (v.is_a?(Symbol) \