Julia: MariaDB のデータを作成 (Create)

## プログラム

フォルダー構造

```text
$ tree -a
.
├── .env
├── config_mariadb.jl
└── maria_create.jl
```

```julia:maria_create.jl
#! /usr/bin/julia
#
#	maria_create.jl
#
#					Feb/24/2023
# --------------------------------------------------------------------
using MySQL
#
include("config_mariadb.jl")
# --------------------------------------------------------------------
function dict_append_proc(dict_aa,key,name,population,date_mod)
#	K = ["name","population","date_mod"]
#	V = [name,population,date_mod]
#
	unit_aa = Dict("name" => name,"population" => population, "date_mod" => date_mod)
	dict_aa[key] = unit_aa
#
	return	dict_aa
end
# --------------------------------------------------------------------
function data_prepare_proc()
	dict_aa = Dict()
#
	dict_aa = dict_append_proc(dict_aa,"t3321","岡山",52761,"2013-2-22")
	dict_aa = dict_append_proc(dict_aa,"t3322","倉敷",17295,"2013-3-15")
	dict_aa = dict_append_proc(dict_aa,"t3323","津山",31674,"2013-8-14")
	dict_aa = dict_append_proc(dict_aa,"t3324","玉野",43612,"2013-6-9")
	dict_aa = dict_append_proc(dict_aa,"t3325","笠岡",72391,"2013-9-4")
	dict_aa = dict_append_proc(dict_aa,"t3326","井原",25187,"2013-2-21")
	dict_aa = dict_append_proc(dict_aa,"t3327","総社",81246,"2013-1-23")
	dict_aa = dict_append_proc(dict_aa,"t3328","高梁",45791,"2013-10-26")
	dict_aa = dict_append_proc(dict_aa,"t3329","新見",74132,"2013-12-19")
#
	
	return	dict_aa
end
# --------------------------------------------------------------------
function drop_table_proc(conn)
	sql_str = "drop table if exists city.cities"
	println(sql_str)
	results = DBInterface.execute(conn,sql_str)
	println(results)
#
end
# --------------------------------------------------------------------
function create_table_proc(conn)
	sql_str = "create table city.cities (id varchar(10) primary key, name text, population int, date_mod date)"
	println(sql_str)
	results = DBInterface.execute(conn,sql_str)
	println(results)
#
end
# --------------------------------------------------------------------
function insert_proc(conn,dict_aa)
	for key in sort(collect(keys(dict_aa)))
		print(key, '\t', dict_aa[key]["name"])
		print('\t', dict_aa[key]["population"])
		println('\t', dict_aa[key]["date_mod"])
		ft_aa = "insert into " * data_base * ".cities (id,name,population,date_mod) values ("
		ft_bb = "'" * key * "','" * dict_aa[key]["name"] * "',"
		ft_cc = "'" * string(dict_aa[key]["population"]) * "',"
		ft_dd = "'" * dict_aa[key]["date_mod"] * "')"
		sql_str = ft_aa * ft_bb * ft_cc * ft_dd
		println(sql_str)
		results = DBInterface.execute(conn,sql_str)
		println(results)
	end
#
end
# --------------------------------------------------------------------
println(stderr,"*** 開始 ***")
#
dict_aa = data_prepare_proc()
#
host, user, password, data_base = config_mariadb_proc()
conn =DBInterface.connect(MySQL.Connection, host, user, password)
drop_table_proc(conn)
create_table_proc(conn)
insert_proc(conn,dict_aa)
#
DBInterface.close!(conn)
#
println(stderr,"*** 終了 ***")
# --------------------------------------------------------------------
```

.env
config_mariadb.jl
はこちら
[Julia: MariaDB のバージョンを表示](https://qiita.com/ekzemplaro/items/dd01c569d386c44213b3)


## 確認したバージョン

```text
$ julia -v
julia version 1.8.5
```