From bcb074af136731ff36e479090447f21dd13aa218 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 18 May 2014 08:57:10 -0400 Subject: v5 v6: cgi, sample search forms: use ruby-pg & ruby-sqlite3; remove ruby-dbi --- lib/sisu/v5/cgi_pgsql.rb | 22 +++++++++------------- lib/sisu/v5/cgi_sqlite.rb | 12 ++++++------ lib/sisu/v5/sysenv.rb | 2 +- lib/sisu/v6/cgi_pgsql.rb | 29 ++++++++++------------------- lib/sisu/v6/cgi_sqlite.rb | 12 ++++++------ lib/sisu/v6/sysenv.rb | 2 +- 6 files changed, 33 insertions(+), 46 deletions(-) (limited to 'lib') 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 %{#{sql_select_endnotes}} 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 %{#{sql_select_endnotes}} 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/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 %{#{sql_select_endnotes}} 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 %{#{sql_select_endnotes}} 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/sysenv.rb b/lib/sisu/v6/sysenv.rb index a8879e7a..2c2a8c10 100644 --- a/lib/sisu/v6/sysenv.rb +++ b/lib/sisu/v6/sysenv.rb @@ -2675,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) -- cgit v1.2.3