Reputation: 53
I am developing a flask app, would like to know, how to call stored procedures in DB by using flask_sqlalchemy.
Upvotes: 0
Views: 1826
Reputation: 41
Assuming your app starts with something like this:
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.sql import text as SQLQuery
Let's say you have a stored procedure called CustomerStatus_CheckList_sp with integer parameters
parameter1 = 100
parameter2 = 200
querystring = 'EXEC CustomerStatus_CheckList_sp ' + str(parameter1) + ',' + str(parameter2)
sql = SQLQuery(querystring)
result = db.engine.execute(sql)
rows = []
for row in result:
print(row)
The rows will come back in a format something like this:
(1, 'John', 'Smith', 'Area 42')
(2, 'Dr', 'Who', 'Gallifrey')
Upvotes: 1