Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. CREATE PROCEDURE `mytestdb`.`getperson` (IN personid INT)
  2. BEGIN
  3. select person.person_id,
  4. person.person_fname,
  5. person.person_mi,
  6. person.person_lname,
  7. person.persongender_id,
  8. person.personjob_id
  9. from person
  10. where person.person_id = personid;
  11. END
  12.  
  13. import mysql.connector
  14.  
  15. cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
  16. cnx._open_connection()
  17. cursor = cnx.cursor()
  18.  
  19. cursor.execute("select * from person where person.person_id = 1")
  20. people = cursor.fetchall()
  21.  
  22. for person in people:
  23. print(person)
  24.  
  25. cnx.close()
  26.  
  27. import mysql.connector
  28.  
  29. cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
  30. cnx._open_connection()
  31. cursor = cnx.cursor()
  32.  
  33. cursor.callproc("getperson", [1])
  34. people = cursor.fetchall()
  35.  
  36. for person in people:
  37. print(person)
  38.  
  39. cnx.close()
  40.  
  41. import mysql.connector
  42.  
  43. cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
  44. cnx._open_connection()
  45. cursor = cnx.cursor()
  46.  
  47. cursor.execute("call getperson(1)")
  48. people = cursor.fetchall()
  49.  
  50. for person in people:
  51. print(person)
  52.  
  53. cnx.close()
  54.  
  55. for result in cursor.stored_results():
  56. people = result.fetchall()
  57.  
  58. import mysql.connector
  59.  
  60. cnx = mysql.connector.connect(user='me',password='pw',host='localhost',database='mydb')
  61. cnx._open_connection()
  62. cursor = cnx.cursor()
  63.  
  64. cursor.callproc("getperson",[1])
  65.  
  66. for result in cursor.stored_results():
  67. people=result.fetchall()
  68.  
  69. for person in people:
  70. print person
  71.  
  72. cnx.close()
  73.  
  74. cursor.callproc("getperson", ['1'])
  75.  
  76. def functionName() :
  77. try:
  78. import mysql.connector
  79. from mysql.connector import errorcode
  80.  
  81. cnx = mysql.connector.connect(user=init["dbDetails"][0], password=init["dbDetails"][1], host=init["dbDetails"][2], database=init["dbDetails"][3])
  82. cur = cnx.cursor()
  83. cur.close() #I deffo don't need the two lines below but they were added for a sanity check, just to make sure the cur was not being read from any other code.
  84. cur = cnx.cursor() # and this one obviously
  85.  
  86. sqlString = 'CALL `schemaName`.`getProcedureName_sp`(1, 1, 0)'
  87. cur.execute(sqlString, multi=True) # tried it here without the multi=True and got the msg telling me to use it.
  88.  
  89. getSomeDetails = curf.fetchall() # Crashes here and the exception caught below is 'No result set to fetch from.'
  90.  
  91. cnx.commit() # probably don't need to commit here I am just reading from the dB but I am trying anything as I have no idea what my issue might be.
  92.  
  93. return render_template('success.html')
  94.  
  95. except Exception as e:
  96. return render_template('error.html', error = str(e))
  97. finally:
  98. cur.close()
  99. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement