0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ruby: MariaDB のデータを更新 (Update)

Posted at

プログラム

フォルダー構造

$ 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
*** 終了 ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?