diff options
Diffstat (limited to 'lib/sisu/v6/db_create.rb')
-rw-r--r-- | lib/sisu/v6/db_create.rb | 43 |
1 files changed, 28 insertions, 15 deletions
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 |