プログラム
フォルダー構造
$ tree -a
.
├── .env
├── config_mariadb.rb
└── maria_update.rb
.env
config_mariadb.rb
はこちら
Ruby: MariaDB のバージョンを表示
maria_update.rb
#! /usr/bin/ruby
#
# maria_update.rb
#
# Feb/24/2023
#
require 'mysql2'
require 'date'
#
load 'config_mariadb.rb'
# ------------------------------------------------------------
def update_proc (client,id,population)
date_mod=Date.today
sql_str="UPDATE cities SET population='#{population}', DATE_MOD='#{date_mod}' where ID = '#{id}'"
client.query(sql_str)
end
# ------------------------------------------------------------
STDERR.puts "*** 開始 ***"
#
id_in = ARGV[0]
population_in = ARGV[1].to_i
#
puts id_in,population_in
#
host,user,password,data_base = config_mariadb_proc()
client = Mysql2::Client.new(host: host, username: user, password: password, database: data_base)
#
update_proc(client,id_in,population_in)
#
client.close
#
STDERR.puts "*** 終了 ***"
# ------------------------------------------------------------
実行結果
$ ./maria_update.rb t3324 91762800
*** 開始 ***
t3324
91762800
*** 終了 ***