From 5d3afe225e618b66cdcc216984d9bd67086d93b6 Mon Sep 17 00:00:00 2001 From: Om Date: Fri, 21 Oct 2022 22:00:44 +0530 Subject: [PATCH 1/3] account type, table setup initialisation --- accounttype.py | 32 ++++++++++++++++++++++++++++++++ setup.py | 2 ++ sqltables.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 accounttype.py create mode 100644 sqltables.py diff --git a/accounttype.py b/accounttype.py new file mode 100644 index 0000000..7ba0e27 --- /dev/null +++ b/accounttype.py @@ -0,0 +1,32 @@ +def acctype(): + while True: + print("--------------Account Selector Menu--------------") + print("1.Admin.") + print("2.Employee.") + print("3.Client.") + print("Enter 0 to end process.") + a=int(input("\nEnter your account type:")) + + if a==1: + b=input("\nEnter admin password:") + if b=="admin123": + return 1 + else: + print("\nWrong password!\n") + + elif a==2: + b=input("\nEnter employee password:") + if b=="emp123": + return 2 + else: + print("\nWrong password!\n") + + elif a==3: + return 3 + + elif a==0: + print("\nShutting down the program.") + break + + else: + print("\nWrong input!") \ No newline at end of file diff --git a/setup.py b/setup.py index c5ad103..3261920 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ import check +import sqltables import pickle import mysql.connector @@ -42,6 +43,7 @@ def querycheck(): print("Connection established successfully.") with open("firsttime.txt","w") as f: f.write("False") + sqltables.tables() ans=True if not ans: diff --git a/sqltables.py b/sqltables.py new file mode 100644 index 0000000..8a3e93c --- /dev/null +++ b/sqltables.py @@ -0,0 +1,36 @@ +import setup +import mysql.connector +from mysql.connector import errorcode +conn=setup.setup() +cursor=conn.cursor() + +DB_NAME = setup.sqldb() + +TABLES = {} +TABLES['employees'] = ( + "CREATE TABLE `employees` (" + " `emp_no` int(5) NOT NULL AUTO_INCREMENT," + " `birth_date` date NOT NULL," + " `first_name` varchar(15) NOT NULL," + " `last_name` varchar(15) NOT NULL," + " `gender` enum('M','F') NOT NULL," + " `hire_date` date NOT NULL," + " `age` int(2) NOT NULL" + " PRIMARY KEY (`emp_no`)" + ") ") + +TABLES['client'] = ( + "CREATE TABLE `clients` (" + " `acc_no` int(5) NOT NULL AUTO_INCREMENT," + " `acc_type` enum('S','C') NOT NULL" + " `first_name` varchar(15) NOT NULL," + " `last_name` varchar(15) NOT NULL," + " `gender` enum('M','F') NOT NULL," + " `birth_date` date NOT NULL," + " `acc_creation_date` date NOT NULL," + " PRIMARY KEY (`acc_no`)" +) + +#https://education.github.com/git-cheat-sheet-education.pdf +#https://dev.mysql.com/doc/connector-python/en/connector-python-example-ddl.html + \ No newline at end of file From 7dcd017500fb73d3ffc9c279580092171d7b515f Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 22 Oct 2022 00:04:29 +0530 Subject: [PATCH 2/3] Added method to create tables in sql --- setup.py | 120 ++++++++++++++++++++++++++++++++++++++++++++++++--- sqltables.py | 67 ++++++++++++++++++++++++++-- 2 files changed, 177 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 3261920..1155cf2 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,83 @@ import check -import sqltables import pickle import mysql.connector +from mysql.connector import errorcode +TABLES = {} +TABLES['employees'] = ( + "CREATE TABLE `employees` (" + " `emp_no` int(5) NOT NULL AUTO_INCREMENT," + " `birth_date` date NOT NULL," + " `first_name` varchar(15) NOT NULL," + " `last_name` varchar(15) NOT NULL," + " `gender` enum('M','F') NOT NULL," + " `hire_date` date NOT NULL," + " `age` int(2) NOT NULL," + " PRIMARY KEY (`emp_no`)" + ") ") + +TABLES['clients'] = ( + "CREATE TABLE `clients` (" + " `acc_no` int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY," + " `acc_type` enum('S','C') NOT NULL," + " `first_name` varchar(15) NOT NULL," + " `last_name` varchar(15) NOT NULL," + " `gender` enum('M','F') NOT NULL," + " `birth_date` date NOT NULL," + " `acc_creation_date` date NOT NULL," + " `mobile_no` int(10) NOT NULL," + " `email_id` varchar(25) NOT NULL" + ") " +) + +TABLES['savings'] = ( + "CREATE TABLE `savings` (" + " `acc_no` int(5) NOT NULL," + " `balance` int NOT NULL," + " `loan` enum('YES','NO') NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['current'] = ( + "CREATE TABLE `current` (" + " `acc_no` int(5) NOT NULL," + " `balance` int NOT NULL," + " `overdraft` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['loan'] = ( + "CREATE TABLE `loan` (" + " `acc_no` int(5) NOT NULL," + " `loan_type` enum('PL','HL','EL','TL','BL') NOT NULL," + " `loan_amt` int NOT NULL," + " `time_period_months` int NOT NULL," + " `iterest_perc_per_annum` int(1) NOT NULL," + " `amt-per-month` int NOT NULL," + " `remaining_amt` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['overdraft']=( + "CREATE TABLE `overdraft` (" + " `acc_no` int(5) NOT NULL," + " `overdraft_amt` int NOT NULL," + " `od_with_interest_remaining` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + + +############################################################################################ query="" Password="" Database="" @@ -41,10 +114,24 @@ def querycheck(): if conn!="": if conn.is_connected: print("Connection established successfully.") - with open("firsttime.txt","w") as f: - f.write("False") - sqltables.tables() - ans=True + if check.check()==True: + cursor=conn.cursor() + #Table creation + for table_name in TABLES: + table_description = TABLES[table_name] + try: + print("Creating table {}: ".format(table_name), end='') + cursor.execute(table_description) + except mysql.connector.Error as err: + if err.errno == errorcode.ER_TABLE_EXISTS_ERROR: + print("already exists.") + else: + print(err.msg) + else: + print("OK") + with open("firsttime.txt","w") as f: + f.write("False") + ans=True if not ans: print("There was a problem in connection") @@ -83,4 +170,25 @@ def setup(): else: if querycheck(): connectionquery() -setup() + +"""def tables(): + conn=setup() + cursor=conn.cursor() + for table_name in TABLES: + table_description = TABLES[table_name] + try: + print("Creating table {}: ".format(table_name), end='') + cursor.execute(table_description) + except mysql.connector.Error as err: + if err.errno == errorcode.ER_TABLE_EXISTS_ERROR: + print("already exists.") + else: + print(err.msg) + else: + print("OK")""" + + +################################################################################################## +#Links +#https://education.github.com/git-cheat-sheet-education.pdf +#https://dev.mysql.com/doc/connector-python/en/connector-python-example-ddl.html diff --git a/sqltables.py b/sqltables.py index 8a3e93c..add9a72 100644 --- a/sqltables.py +++ b/sqltables.py @@ -15,22 +15,81 @@ " `last_name` varchar(15) NOT NULL," " `gender` enum('M','F') NOT NULL," " `hire_date` date NOT NULL," - " `age` int(2) NOT NULL" + " `age` int(2) NOT NULL," " PRIMARY KEY (`emp_no`)" ") ") -TABLES['client'] = ( +TABLES['clients'] = ( "CREATE TABLE `clients` (" " `acc_no` int(5) NOT NULL AUTO_INCREMENT," - " `acc_type` enum('S','C') NOT NULL" + " `acc_type` enum('S','C') NOT NULL," " `first_name` varchar(15) NOT NULL," " `last_name` varchar(15) NOT NULL," " `gender` enum('M','F') NOT NULL," " `birth_date` date NOT NULL," " `acc_creation_date` date NOT NULL," + " `mobile_no int(10) NOT NULL`," + " `email_id varchar(25) NOT NULL`," " PRIMARY KEY (`acc_no`)" + ") " ) +TABLES['savings'] = ( + "CREATE TABLE `savings` (" + " `acc_no` int(5) NOT NULL," + " `balance` int NOT NULL," + " `loan` enum('YES','NO') NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['current'] = ( + "CREATE TABLE `current` (" + " `acc_no` int(5) NOT NULL," + " `balance` int NOT NULL," + " `overdraft` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['loan'] = ( + "CREATE TABLE `loan` (" + " `acc_no` int(5) NOT NULL," + " `loan_type` enum('PL','HL','EL','TL','BL') NOT NULL," + " `loan_amt` int NOT NULL," + " `time_period_months` int NOT NULL," + " `iterest_perc_per_annum` int(1) NOT NULL," + " `amt-per-month` int NOT NULL," + " `remaining_amt` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['overdraft']=( + "CREATE TABLE `overdraft` (" + " `acc_no` int(5) NOT NULL," + " `overdraft_amt` int NOT NULL," + " `od_with_interest_remaining int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) +def tables(): + for table_name in TABLES: + table_description = TABLES[table_name] + try: + print("Creating table {}: ".format(table_name), end='') + cursor.execute(table_description) + except mysql.connector.Error as err: + if err.errno == errorcode.ER_TABLE_EXISTS_ERROR: + print("already exists.") + else: + print(err.msg) + else: + print("OK") +#Credits #https://education.github.com/git-cheat-sheet-education.pdf #https://dev.mysql.com/doc/connector-python/en/connector-python-example-ddl.html - \ No newline at end of file From d6b3f72907e41c5ada41a9a8133b22caad5f7705 Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 22 Oct 2022 00:09:09 +0530 Subject: [PATCH 3/3] Removed unnecessary comments --- .gitignore | 3 +- setup.py | 22 ------------ sqltables.py | 95 ---------------------------------------------------- 3 files changed, 2 insertions(+), 118 deletions(-) delete mode 100644 sqltables.py diff --git a/.gitignore b/.gitignore index 4572c76..e0acd6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ firsttime.txt -cred.dat \ No newline at end of file +cred.dat +links.txt \ No newline at end of file diff --git a/setup.py b/setup.py index 1155cf2..a7ccb56 100644 --- a/setup.py +++ b/setup.py @@ -170,25 +170,3 @@ def setup(): else: if querycheck(): connectionquery() - -"""def tables(): - conn=setup() - cursor=conn.cursor() - for table_name in TABLES: - table_description = TABLES[table_name] - try: - print("Creating table {}: ".format(table_name), end='') - cursor.execute(table_description) - except mysql.connector.Error as err: - if err.errno == errorcode.ER_TABLE_EXISTS_ERROR: - print("already exists.") - else: - print(err.msg) - else: - print("OK")""" - - -################################################################################################## -#Links -#https://education.github.com/git-cheat-sheet-education.pdf -#https://dev.mysql.com/doc/connector-python/en/connector-python-example-ddl.html diff --git a/sqltables.py b/sqltables.py deleted file mode 100644 index add9a72..0000000 --- a/sqltables.py +++ /dev/null @@ -1,95 +0,0 @@ -import setup -import mysql.connector -from mysql.connector import errorcode -conn=setup.setup() -cursor=conn.cursor() - -DB_NAME = setup.sqldb() - -TABLES = {} -TABLES['employees'] = ( - "CREATE TABLE `employees` (" - " `emp_no` int(5) NOT NULL AUTO_INCREMENT," - " `birth_date` date NOT NULL," - " `first_name` varchar(15) NOT NULL," - " `last_name` varchar(15) NOT NULL," - " `gender` enum('M','F') NOT NULL," - " `hire_date` date NOT NULL," - " `age` int(2) NOT NULL," - " PRIMARY KEY (`emp_no`)" - ") ") - -TABLES['clients'] = ( - "CREATE TABLE `clients` (" - " `acc_no` int(5) NOT NULL AUTO_INCREMENT," - " `acc_type` enum('S','C') NOT NULL," - " `first_name` varchar(15) NOT NULL," - " `last_name` varchar(15) NOT NULL," - " `gender` enum('M','F') NOT NULL," - " `birth_date` date NOT NULL," - " `acc_creation_date` date NOT NULL," - " `mobile_no int(10) NOT NULL`," - " `email_id varchar(25) NOT NULL`," - " PRIMARY KEY (`acc_no`)" - ") " -) - -TABLES['savings'] = ( - "CREATE TABLE `savings` (" - " `acc_no` int(5) NOT NULL," - " `balance` int NOT NULL," - " `loan` enum('YES','NO') NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" - ") " -) - -TABLES['current'] = ( - "CREATE TABLE `current` (" - " `acc_no` int(5) NOT NULL," - " `balance` int NOT NULL," - " `overdraft` int NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" - ") " -) - -TABLES['loan'] = ( - "CREATE TABLE `loan` (" - " `acc_no` int(5) NOT NULL," - " `loan_type` enum('PL','HL','EL','TL','BL') NOT NULL," - " `loan_amt` int NOT NULL," - " `time_period_months` int NOT NULL," - " `iterest_perc_per_annum` int(1) NOT NULL," - " `amt-per-month` int NOT NULL," - " `remaining_amt` int NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" - ") " -) - -TABLES['overdraft']=( - "CREATE TABLE `overdraft` (" - " `acc_no` int(5) NOT NULL," - " `overdraft_amt` int NOT NULL," - " `od_with_interest_remaining int NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" - ") " -) -def tables(): - for table_name in TABLES: - table_description = TABLES[table_name] - try: - print("Creating table {}: ".format(table_name), end='') - cursor.execute(table_description) - except mysql.connector.Error as err: - if err.errno == errorcode.ER_TABLE_EXISTS_ERROR: - print("already exists.") - else: - print(err.msg) - else: - print("OK") -#Credits -#https://education.github.com/git-cheat-sheet-education.pdf -#https://dev.mysql.com/doc/connector-python/en/connector-python-example-ddl.html