import mysql.connector
import json
from argparse import ArgumentParser
# import scripts.testing.Credentials as db_credentials
#from .Credentials import *
#from .constants import *
import Credentials as db_credentials
import constants

def readImportStatements(fileName):
    inFile = open(fileName, 'r')
    # resultText = inFile.read()

    result = inFile.readlines()

    inFile.close()

    return result

parser = ArgumentParser(description="Execute a list of sql statements")
parser.add_argument('-f', '--file', nargs=1, help="SQL File(s)", required=True)
args = parser.parse_args()


# print(dict(user=db_credentials.user, host=db_credentials.host, database=db_credentials.database, password=db_credentials.password))


db = mysql.connector.connect(user=db_credentials.user, host=db_credentials.host, database=db_credentials.database, password=db_credentials.password)
cursor = db.cursor()

stmts = readImportStatements(args.file[0])


for stmt in stmts:
    cursor.execute(stmt)


# cursor.execute(stmts, multi=True)

db.commit()
db.close()








