def computeFutureValue(self): numberOfYears = int(self.numberOfYearsVar.get()) investmentAmount = float(self.investmentAmountVar.get()) annualInterestRate = float(self.annualInterestRateVar.get()) monthlyInterestRate = annualInterestRate/12 monthlyInterestRate /= 100 futureValue = investmentAmount * ( 1 + monthlyInterestRate ) ** (numberOfYears * 12) self.futureValueVar.set(format(futureValue,"10.2f")) try: dbParam = read_db_config() db = pymysql.connect(**dbParam) cursor = db.cursor() sql = "INSERT INTO investmentcalculator(InvestmentAmount, NumberOfYears, AnnualInterestRate, FutureValue) \ VALUES ('%f', '%d', '%f', '%f')" % (investmentAmount, numberOfYears,annualInterestRate, futureValue) cursor.execute(sql) db.commit() print("Record added to investment calculator table successfully.") db.close() except ValueError: print("one of your inputs is invalid") except Exception as err: print("Error:{0}".format(err))
def addAddress(self): dbParam = read_db_config() db = pymysql.connect(**dbParam) cursor = db.cursor() print("Name: {0}, Street: {1}, City: {2}, State: {3}, Zip: {4}".format( self.nameVar.get(), self.streetVar.get(), self.cityVar.get(), self.stateVar.get(), self.zipVar.get())) #cursor.execute('INSERT INTO addressBook (Name, Street, City, State, Zip) VALUES("Ria", "0001", "Redmond", "WA", "98007")') sql = "INSERT INTO addressBook (Name, Street, City, State, Zip) VALUES('%s', '%s', '%s', '%s', '%s')" % ( self.nameVar.get(), self.streetVar.get(), self.cityVar.get(), self.stateVar.get(), self.zipVar.get()) cursor.execute(sql) db.commit() cursor.execute('SELECT * FROM addressBook') data = cursor.fetchall() print(data) print("Sucessfuly created an address in address book") self.messageVar.set( "Message: Sucessfuly created an address in address book") cursor.execute('SELECT * FROM employeedb.addressBook ' 'ORDER BY Id DESC ' 'LIMIT 1') data = cursor.fetchone() self.__currentID = data[0] db.close()
def getPrevious(self): dbParam = read_db_config() db = pymysql.connect(**dbParam) cursor = db.cursor() sql = 'SELECT * FROM employeedb.addressBook WHERE Id = (%d)' % ( self.__currentID - 1) cursor.execute(sql) data = cursor.fetchone() if data != None: self.__currentID = data[0] self.nameVar.set(data[1]) self.streetVar.set(data[2]) self.cityVar.set(data[3]) self.stateVar.set(data[4]) self.zipVar.set(data[5]) print(data) self.messageVar.set( "Message: Sucessfuly pulled previous address from address book" ) # print("Sucessfuly pulled first address from address book") else: print("No Data") self.__currentID -= 1 self.messageVar.set("Message: No Data") db.close()
def write2db(self): sql = "INSERT INTO Information (First_Name, Last_Name, Race, Gender, Age, Titles, Description, History)" \ "VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % (self.fnameVar.get(), self.lnameVar.get(), self.raceVar.get(), self.genderVar.get(), self.ageVar.get(), self.titleVar.get(), self.retrieve_Tinput(), self.retrieve_Hinput()) dbParam = read_db_config() db = pymysql.connect(**dbParam) # ** is reference to dictionary cursor = db.cursor() cursor.execute(sql) db.commit() if db != None: db.close() print("Entry added!")
def getFirst(self): dbParam = read_db_config() db = pymysql.connect(**dbParam) cursor = db.cursor() sql = 'SELECT * FROM employeedb.addressBook LIMIT 1' cursor.execute(sql) data = cursor.fetchone() self.__currentID = data[0] self.nameVar.set(data[1]) self.streetVar.set(data[2]) self.cityVar.set(data[3]) self.stateVar.set(data[4]) self.zipVar.set(data[5]) print(data) print("Sucessfuly pulled first address from address book") self.messageVar.set( "Message: Sucessfuly pulled first address from address book") db.close()
def buttonClick(self): """ handle button click event and output text from entry area""" try: dbParam = read_db_config() db = pymysql.connect(**dbParam) cursor = db.cursor() sql = "INSERT INTO addressbook(Name, Street, City, State, Zip) \ VALUES ('%s', '%s', '%s', '%s','%s')" % ( self.nameVar.get(), self.streetVar.get(), self.cityVar.get(), self.stateVar.get(), self.zipVar.get()) cursor.execute(sql) db.commit() print("Name added to addressbook successfully.") db.close() except ValueError: print("one of your inputs is invalid") except Exception as err: print("Error:{0}".format(err))
def buttonFirst(self): """ handle button click event and output text from entry area""" try: dbParam = read_db_config() db = pymysql.connect(**dbParam) cursor = db.cursor() self.id = 1 sql = "SELECT * from addressbook where Id= %s" cursor.execute(sql, self.id) records = cursor.fetchall() row = records[0] self.nameVar.set(row[1]) self.streetVar.set(row[2]) self.cityVar.set(row[3]) self.stateVar.set(row[4]) self.zipVar.set(row[5]) db.close() except ValueError: print("one of your inputs is invalid") except Exception as err: print("Error:{0}".format(err))
import pymysql from ReadConfig import read_db_config db = None try: dbParam = read_db_config() db = pymysql.connect(**dbParam) cursor = db.cursor() f_name = input("enter your first name:") l_name = input("enter your last name:") age = int(input("enter your age:")) gender = input("enter your gender:") income = eval(input("enter your income:")) sql = "INSERT INTO employees(FirstName, LastName, Age, Income) \ VALUES ('%s', '%s', '%d', '%d')" % (f_name, l_name, age, income) cursor.execute(sql) db.commit() print("Employee added successfully.") db.close() except ValueError: print("one of your inputs is invalid") except Exception as err: print("Error:{0}".format(err))