Advertisement
Guest User

Untitled

a guest
Nov 29th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import pymssql #import python ms sql library
  2.  
  3. def main():
  4. conn = pymssql.connect(host='cypress.csil.sfu.ca', user='s_hoalvinh', password='hY37m6A67L3Qb7h6', database='hoalvinh354')
  5. insert = False
  6. while not insert:
  7. print('Adding a Song Record')
  8. try:
  9. isrc = raw_input('Enter ISRC: ')
  10. except Exception:
  11. print('Invalid Input: Try entering ISRC again.')
  12. isrc = raw_input('Enter ISRC: ')
  13. try:
  14. title = raw_input('Enter Title: ')
  15. except Exception:
  16. print('Invalid Input: Try entering title again')
  17. title = raw_input('Enter Title: ')
  18. try:
  19. year = input('Enter Year: ')
  20. except Exception:
  21. print('Invalid Input: Try entering year again')
  22. year = input('Enter Year: ')
  23. try:
  24. artistName = raw_input("Enter Artist's Name: ")
  25. except Exception:
  26. print('Invalid Input: Try entering artist\'s name again')
  27. artistName = raw_input('Enter Artist\'s Name: ')
  28. mycursor = conn.cursor()
  29. try:
  30. mycursor.execute("INSERT INTO Song VALUES (%s, %s, %d, %s)", (isrc, title, year, artistName))
  31. insert = True
  32. mycursor.close()
  33. except Exception as e:
  34. print "Insertion failed: ", e
  35. print artistName
  36. mycursor = conn.cursor()
  37. print("ISRC: \t\t Title: ")
  38. mycursor.execute("SELECT s.isrc, s.title FROM Song s WHERE s.artistname = %s", artistName)
  39. print("ISRC: \t\t Title: ")
  40. row = mycursor.fetchone()
  41. print("ISRC: \t\t Title: ")
  42. while row:
  43. print row
  44. row = mycursor.fetchone()
  45. mycursor.close()
  46. conn.commit()
  47. if __name__ == "__main__":
  48. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement