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 --- data/doc/sisu/CHANGELOG_v5 | 5 +++++ data/doc/sisu/CHANGELOG_v6 | 5 +++++ data/doc/sisu/sisu.org | 16 +++++++++----- data/sisu/conf/cgi-bin/sisu_search_pgsql.cgi | 19 ++++++++-------- data/sisu/conf/cgi-bin/sisu_search_sqlite.cgi | 32 +++++++++++++-------------- 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 +- 11 files changed, 79 insertions(+), 77 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index 1e958203..08796bbe 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -44,6 +44,11 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.3.6.orig.tar.xz * for pg: require 'pg' (use ruby-pg directly) * for sqlite: require 'sqlite3' (use ruby-sqlite3 directly) [already the case] +* cgi, sample search form generator + * remove require 'dbi' (ruby-dbi) + * for pg: require 'pg' (use ruby-pg directly) + * for sqlite: require 'sqlite3' (use ruby-sqlite3 directly) + %% 5.3.5.orig.tar.xz (2014-05-12:19/1) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/sisu_5.3.5 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/debian/sisu_5.3.5-1 diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6 index 0c533432..b39da757 100644 --- a/data/doc/sisu/CHANGELOG_v6 +++ b/data/doc/sisu/CHANGELOG_v6 @@ -34,6 +34,11 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.0.6.orig.tar.xz * for pg: require 'pg' (use ruby-pg directly) * for sqlite: require 'sqlite3' (use ruby-sqlite3 directly) [already the case] +* cgi, sample search form generator + * remove require 'dbi' (ruby-dbi) + * for pg: require 'pg' (use ruby-pg directly) + * for sqlite: require 'sqlite3' (use ruby-sqlite3 directly) + %% 6.0.5.orig.tar.xz (2014-05-12:19/1) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/sisu_6.0.5 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/debian/sisu_6.0.5-1 diff --git a/data/doc/sisu/sisu.org b/data/doc/sisu/sisu.org index 0e4b0bf6..f8817e68 100644 --- a/data/doc/sisu/sisu.org +++ b/data/doc/sisu/sisu.org @@ -1179,7 +1179,7 @@ revisit, *** DBT Outstanding bugs -- sisu caught by removal of ruby-dbi -**** TODO [#B] sisu 5.3.4-1 marked for autoremoval from debian testing on 2014-06-10, for depending on ruby-dbi +**** DONE (pending acceptance) [#B] sisu 5.3.4-1 marked for autoremoval from debian testing on 2014-06-10, for depending on ruby-dbi sisu 5.3.4-1 is marked for autoremoval from testing on 2014-06-10 It (build-)depends on packages with these RC bugs: @@ -1221,7 +1221,7 @@ http://lists.sisudoc.org/pipermail/sisu/2014-May/000818.html * code tests passed (create tables, populate db etc. work fine) (closes) -***** TODO [#B] sample cgi search forms +***** DONE [#B] sample cgi search forms there is a sample cgi search form facility within sisu that uses ruby-dbi to query sqlite3 or pg databases. @@ -1239,7 +1239,12 @@ http://lists.sisudoc.org/pipermail/sisu/2014-May/000818.html > eventually using ruby-sqlite3 and ruby-pg directly). Solution Implemented: - (pending) + * sample cgi search froms (cgi database query forms) fixed :) + * pg sample uses 'pg' (dbi dropped) + generate sample form using: sisu --sample-search-form --db-pg + * sqlite sample uses 'sqlite3' (dbi dropped) + generate sample form using: sisu --sample-search-form --db-sqlite + (closes) ***** NOTES/COMMENTS @@ -1248,8 +1253,9 @@ debian/control, remove dependency on ruby-dbi, contained in sisu-postgresql and Current status * sisu-sqlite ok, uses 'sqlite3' (superflous dbi loading dropped) * sisu-postgresql ok, uses 'pg' (dbi dropped) - * sample cgi search froms (cgi database query forms) are broken till they work - off ruby-pg & ruby-sqlite3 respectively instead of ruby-dbi + * sample cgi search froms (cgi database query forms) ok :) + * pg sample uses 'pg' (dbi dropped) + * sqlite sample uses 'sqlite3' (dbi dropped) *** DBT Outstanding bugs -- Normal bugs; Unclassified (2 bugs) :debian:dbt:normal: diff --git a/data/sisu/conf/cgi-bin/sisu_search_pgsql.cgi b/data/sisu/conf/cgi-bin/sisu_search_pgsql.cgi index 2f6f93e4..704ea154 100644 --- a/data/sisu/conf/cgi-bin/sisu_search_pgsql.cgi +++ b/data/sisu/conf/cgi-bin/sisu_search_pgsql.cgi @@ -60,7 +60,7 @@ begin require 'cgi' require 'fcgi' - require 'dbi' + require 'pg' rescue LoadError puts 'cgi, fcgi or dbi NOT FOUND (LoadError)' end @@ -71,7 +71,7 @@ @output_dir_structure_by='language' @lingual='multi' @port='5432' - @db_name_prefix='SiSUv6a_' + @db_name_prefix='SiSUv6b_' @user='ralph' # check user name for access to pg database: e.g. www-data or 'ralph' @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" #Common TOP @@ -141,9 +141,9 @@
index @@ -520,10 +520,10 @@ %{#{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 def tail @@ -547,7 +547,7 @@

Generated by - SiSU 6.0.3 2014-02-06 (2014w05/4) + SiSU 6.0.6 2014-05-18 (2014w19/7)
SiSU © Ralph Amissah @@ -679,8 +679,7 @@ checked_searched=checked_tip=checked_case=checked_sql='' end selected_db=%{} - dbi="dbi:Pg:database=#{@db};port=#{@port}" - @conn=DBI.connect(dbi,@user) + @conn=PG::Connection.open(dbname: @db, port: @port, user: @user) search_field=cgi['find'] if cgi['find'] # =~/\S+/ @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for #% searches diff --git a/data/sisu/conf/cgi-bin/sisu_search_sqlite.cgi b/data/sisu/conf/cgi-bin/sisu_search_sqlite.cgi index 2bd9c09a..526ac974 100644 --- a/data/sisu/conf/cgi-bin/sisu_search_sqlite.cgi +++ b/data/sisu/conf/cgi-bin/sisu_search_sqlite.cgi @@ -60,9 +60,9 @@ 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="http://#{ENV['HTTP_HOST']}/_sisu/image_sys" @@ -70,7 +70,7 @@ @hosturl_files="http://#{ENV['HTTP_HOST']}" @output_dir_structure_by='language' @lingual='multi' - @db_name_prefix='SiSUv6a_' + @db_name_prefix='SiSUv6b_' @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" #Common TOP @@offset=0 @@ -118,7 +118,7 @@ - +

@@ -139,8 +139,8 @@
index @@ -511,10 +511,10 @@ %{#{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 def tail @@ -538,7 +538,7 @@

Generated by - SiSU 6.0.3 2014-02-06 (2014w05/4) + SiSU 6.0.6 2014-05-18 (2014w19/7)
SiSU © Ralph Amissah @@ -670,17 +670,17 @@ checked_searched=checked_tip=checked_case=checked_sql='' end selected_db=case cgi['db'] - when /SiSUv6a_manual/ then '' - when /SiSUv6a_sisu/ then '' + when /SiSUv6b_manual/ then '' + when /SiSUv6b_sisu/ then '' end db_name='sisu_sqlite.db' db_sqlite=case cgi['db'] - when /SiSUv6a_manual/ then "/srv/www/manual/#{db_name}" - when /SiSUv6a_sisu/ then "/srv/www/sisu/#{db_name}" - else '/srv/www/manual/#{db_name}' + when /SiSUv6b_manual/ then "/srv/www/manual/#{db_name}" + when /SiSUv6b_sisu/ then "/srv/www/sisu/#{db_name}" + else '/srv/www/sisu/#{db_name}' end - @dbi="DBI:SQLite3:#{db_sqlite}" #sqlite3 ? - @conn=DBI.connect(@dbi) + @conn=SQLite3::Database.new(db_sqlite) + @conn.results_as_hash=true search_field=cgi['find'] if cgi['find'] # =~/\S+/ @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for #% searches 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