callproc()

Overview

Executes a stored procedure.

See also: MariaDB Connector/Python 1.1 and in 1.0

DETAILS

Executes a stored procedure. The args sequence must contain an entry for each parameter the procedure expects. Input/Output or Output parameters have to be retrieved by fetch methods. Checking the sp_outparams attribute will indicate if the current result set contains the output parameters.

EXAMPLES

import mariadb

conn = mariadb.connect(
    host = 'localhost',
    user = 'root',
    password = 'secret',
    )

cursor = conn.cursor()

cursor.execute("""
    CREATE PROCEDURE p1(IN i1 VARCHAR(20), OUT o2 VARCHAR(40))
    BEGIN
      SELECT 'hello';
      SET o2 = 'test';
    END
    """)

cursor.callproc('p1', ('foo', 0))
print(cursor.sp_outparams) # Prints: False
print(cursor.fetchone()) # Prints: ('hello',)

cursor.nextset()

print(cursor.sp_outparams) # Prints: True
print(cursor.fetchone()) # Prints: ('test',)

cursor.execute("DROP PROCEDURE p1")

CHANGE HISTORY

Release Series

History

1.1

  • Present starting in MariaDB Connector/Python 1.1.2.

1.0

  • Present starting in MariaDB Connector/Python 1.0.0.