Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE `mytestdb`.`getperson` (IN personid INT)
- BEGIN
- select person.person_id,
- person.person_fname,
- person.person_mi,
- person.person_lname,
- person.persongender_id,
- person.personjob_id
- from person
- where person.person_id = personid;
- END
- import mysql.connector
- cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
- cnx._open_connection()
- cursor = cnx.cursor()
- cursor.execute("select * from person where person.person_id = 1")
- people = cursor.fetchall()
- for person in people:
- print(person)
- cnx.close()
- import mysql.connector
- cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
- cnx._open_connection()
- cursor = cnx.cursor()
- cursor.callproc("getperson", [1])
- people = cursor.fetchall()
- for person in people:
- print(person)
- cnx.close()
- import mysql.connector
- cnx = mysql.connector.connect(user='root', host='127.0.0.1', database='mytestdb')
- cnx._open_connection()
- cursor = cnx.cursor()
- cursor.execute("call getperson(1)")
- people = cursor.fetchall()
- for person in people:
- print(person)
- cnx.close()
- for result in cursor.stored_results():
- people = result.fetchall()
- import mysql.connector
- cnx = mysql.connector.connect(user='me',password='pw',host='localhost',database='mydb')
- cnx._open_connection()
- cursor = cnx.cursor()
- cursor.callproc("getperson",[1])
- for result in cursor.stored_results():
- people=result.fetchall()
- for person in people:
- print person
- cnx.close()
- cursor.callproc("getperson", ['1'])
- def functionName() :
- try:
- import mysql.connector
- from mysql.connector import errorcode
- cnx = mysql.connector.connect(user=init["dbDetails"][0], password=init["dbDetails"][1], host=init["dbDetails"][2], database=init["dbDetails"][3])
- cur = cnx.cursor()
- 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.
- cur = cnx.cursor() # and this one obviously
- sqlString = 'CALL `schemaName`.`getProcedureName_sp`(1, 1, 0)'
- cur.execute(sqlString, multi=True) # tried it here without the multi=True and got the msg telling me to use it.
- getSomeDetails = curf.fetchall() # Crashes here and the exception caught below is 'No result set to fetch from.'
- 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.
- return render_template('success.html')
- except Exception as e:
- return render_template('error.html', error = str(e))
- finally:
- cur.close()
- cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement