From 307ecb4df591aa675b71839014debf6e81d462e1 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 18 May 2014 08:49:03 -0400 Subject: v5 v6: db, use symbols to identify sql engine --- lib/sisu/v6/db_create.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/sisu/v6/db_create.rb') diff --git a/lib/sisu/v6/db_create.rb b/lib/sisu/v6/db_create.rb index 661059a1..105f089c 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('') @@ -105,7 +105,7 @@ module SiSU_DbCreate 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 @@ -343,7 +343,7 @@ module SiSU_DbCreate 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 @@ -377,9 +377,9 @@ module SiSU_DbCreate 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 -- cgit v1.2.3 From 7bfd567154b9fd468e5df53901c3d8c383cc25f8 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 18 May 2014 08:53:33 -0400 Subject: v5 v6: db, remove ruby-dbi, for: pg ruby-pg, sqlite ruby-sqlite3 (already uses) * ruby-pg require for postgresql * ruby-sqlite3 require for sqlite3 (done previously: already using ruby-sqlite3 rather than ruby-dbi) * ruby-dbi remove calls (in any common files & sisu pg and sisu sqlite3) * separate pg and sqlite db actions --- lib/sisu/v6/db_create.rb | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'lib/sisu/v6/db_create.rb') diff --git a/lib/sisu/v6/db_create.rb b/lib/sisu/v6/db_create.rb index 105f089c..01fc1935 100644 --- a/lib/sisu/v6/db_create.rb +++ b/lib/sisu/v6/db_create.rb @@ -101,6 +101,19 @@ 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) @@ -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,7 +349,7 @@ 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 @@ -370,7 +383,7 @@ module SiSU_DbCreate sisupod varchar(512) ); } - @conn.execute(create_urls) + conn_exec(create_urls) @comment.psql.urls if @comment end self @@ -386,7 +399,7 @@ module SiSU_DbCreate 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 -- cgit v1.2.3