3
私はpython
スクリプトを使用して、MySQL
データベースに約10個のINSERTs
を作成しています。これは、現在の構造である:MySQLdbを使用した複数の実行
conn = MySQLdb.connect (host = DB_HOST,
port = DB_PORT,
user = DB_USER,
passwd = DB_PASSWORD,
db = DB_NAME)
cursor = conn.cursor()
cursor.execute("INSERT INTO...")
# do some stuff, then another INSERT
cursor.execute("INSERT INTO...")
# do some other stuff, then another INSERT
cursor.execute("INSERT INTO...")
etc...
conn.commit()
cursor.close()
conn.close()
は、複数の挿入を行うための正しい方法を上回っている、または私は各INSERT
の後にカーソルをクローズする必要がありますか?それぞれの後にcommit
を実行する必要がありますか?