import mysql.connector as mysql
import sys



db = mysql.connect(
	host = "127.0.0.1",
	user = "w3_admin",
    passwd = "$a7!1BoHVa7#GEAYs1",
	database = "worship"
)

if len(sys.argv) == 1:
	print("Please provide a record id")
	exit()
	
print("start")

for arg in sys.argv[1:]:

	cursor = db.cursor(buffered=True)

	query = "delete from songs where id = " + str(arg)
	cursor.execute(query)
	db.commit()
	
	query = "delete from song_artist where song_id = " + str(arg)
	cursor.execute(query)
	db.commit()
	
	query = "delete from song_category where song_id = " + str(arg)
	cursor.execute(query)
	db.commit()
	
	
	query = "delete from song_resource where song_id = " + str(arg)
	cursor.execute(query)
	db.commit()
	
	query = "delete from song_theme where song_id = " + str(arg)
	cursor.execute(query)
	db.commit()
	
	query = "select related_id from related where song_id = " + str(arg)
	cursor.execute(query)
	r  = cursor.fetchall()
	
	if (cursor.rowcount > 0):
		query = "delete from related where related_id = " + str(r[0][0])
		cursor.execute(query)
		db.commit()
	

	cursor.close()

	db.close()
	

