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.

Python3: MariaDB のデータを削除 (Delete)

Posted at

プログラム

フォルダー構造

$ tree -a
.
├── .env
├── config_mariadb.py
└── maria_delete.py

.env
config_mariadb.py
はこちら
Python3: MariaDB のバージョンを表示

maria_delete.py
#! /usr/bin/python
#
#	maria_delete.py
#
#					Feb/22/2023
#
# --------------------------------------------------------
import	os
import	sys
import	mariadb
#
from config_mariadb import config_mariadb_proc
# --------------------------------------------------------
def	sql_delete_proc(cursor_aa,key_in):
	print("*** sql_delete_proc ***")
#
	sql_str = sql_delete_string_gen_proc(key_in)
	cursor_aa.execute(sql_str)
# --------------------------------------------------------
def	sql_delete_string_gen_proc(key_in):
	sql_str="delete from cities where id = '%s'" % key_in
	print(sql_str)
#
	return	sql_str
# --------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
key_in = sys.argv[1]
print ("%s" % key_in)
#
host,user,password,data_base = config_mariadb_proc()
conn = mariadb.connect(user=user, password=password, \
                              host=host,database=data_base)
#
cursor = conn.cursor()
#
sql_delete_proc(cursor,key_in)
conn.commit()
#
cursor.close()
conn.close()
sys.stderr.write("*** 終了 ***\n")
#
# --------------------------------------------------------

実行結果

$ ./maria_delete.py t3327
*** 開始 ***
t3327
*** sql_delete_proc ***
delete from cities where id = 't3327'
*** 終了 ***
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?