Monday, August 27, 2012

Error when I call a stored procedure on Cloud SQL in python2.7


Hi,
We're trying to call a stored procedure on Cloud SQL in python2.7.
Here's our simple code:

# stored procedure
CREATE PROCEDURE Test_Procedure (_nmbr INT)
BEGIN
INSERT INTO TEST(AA) VALUES(_nmbr);
SELECT * FROM TEST;
END;

# code in python
conn = rdbms.connect(instance = _INSTANCE_NAME, database = _DATABASE_NAME)
cursor = conn.cursor()

cursor.execute("call Test_Procedure(%s)", (50))
results = cursor.fetchall()
for row in results :
self.response.out.write(str(row[0]))

conn.close()

When I executed the procedure on SQL Prompt, it worked very well, but when I tried to execute it by python code, I've gotten this error message.
InternalError: fetchall() called before execute

Do I have to do something else when I execute a stored procedure in python code??

No comments:

Post a Comment