Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymssql #import python ms sql library
- def main():
- conn = pymssql.connect(host='cypress.csil.sfu.ca', user='s_hoalvinh', password='hY37m6A67L3Qb7h6', database='hoalvinh354')
- insert = False
- while not insert:
- print('Adding a Song Record')
- try:
- isrc = raw_input('Enter ISRC: ')
- except Exception:
- print('Invalid Input: Try entering ISRC again.')
- isrc = raw_input('Enter ISRC: ')
- try:
- title = raw_input('Enter Title: ')
- except Exception:
- print('Invalid Input: Try entering title again')
- title = raw_input('Enter Title: ')
- try:
- year = input('Enter Year: ')
- except Exception:
- print('Invalid Input: Try entering year again')
- year = input('Enter Year: ')
- try:
- artistName = raw_input("Enter Artist's Name: ")
- except Exception:
- print('Invalid Input: Try entering artist\'s name again')
- artistName = raw_input('Enter Artist\'s Name: ')
- mycursor = conn.cursor()
- try:
- mycursor.execute("INSERT INTO Song VALUES (%s, %s, %d, %s)", (isrc, title, year, artistName))
- insert = True
- mycursor.close()
- except Exception as e:
- print "Insertion failed: ", e
- print artistName
- mycursor = conn.cursor()
- print("ISRC: \t\t Title: ")
- mycursor.execute("SELECT s.isrc, s.title FROM Song s WHERE s.artistname = %s", artistName)
- print("ISRC: \t\t Title: ")
- row = mycursor.fetchone()
- print("ISRC: \t\t Title: ")
- while row:
- print row
- row = mycursor.fetchone()
- mycursor.close()
- conn.commit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement