Using TMyStoredProc gives parameter not found error
Posted: Sat 21 Mar 2020 16:53
The situation
My database is accessed remotely from an ISP's server. The DB has only one user who has GRANT ALL PRIVILIGES (but is not a super user or root). My Delphi application logs into the database using that same single user (that I also use for development). I have many stored procedures in my database. All of them have definers with an IP address in of the form '[email protected]' as the default definer is the only type I have permissions to make.
The problem
Assume I have a stored procedure defined as
If I use a TMyQuery to run it using sql such as
then it works fine running my application on my development machine (with the same IP address as in the definers) and also from a colleague running the same application from a different IP address.
It also works from both my IP and another IP if I use a TMyConnection eg
However, if I choose to use a TMyStoredProc instead and use code such as
then it still works fine when running from my IP address but when running from a different IP address I get an error
when it tries to assign a value to the parameter (and the execute fails)
What I have tried
I inserted a debug message
after PrepareSQL and before assigning the parameter value.
On my machine the message displays
but when running the application from a different IP address the message is just
with no parameters shown
Why can I call stored procedures using TMyQuery or TMyConnection from my IP address or another IP address but I can only call them using the more appropriate TMyStoredProc when running from my IP address? - and what can I do about it?
My database is accessed remotely from an ISP's server. The DB has only one user who has GRANT ALL PRIVILIGES (but is not a super user or root). My Delphi application logs into the database using that same single user (that I also use for development). I have many stored procedures in my database. All of them have definers with an IP address in of the form '[email protected]' as the default definer is the only type I have permissions to make.
The problem
Assume I have a stored procedure defined as
Code: Select all
CREATE PROCEDURE make_invoice(invoice_id INT);
Code: Select all
MyQuery1.clear;
MyQuery1.sql.add('CALL make_invoice(1234);');
MyQuery1.open;
It also works from both my IP and another IP if I use a TMyConnection eg
Code: Select all
MyConnection1.ExecSQL('CALL make_invoice(1234)');
Code: Select all
MyStoredProc1.StoredProcName := 'make_invoice';
MyStoredProc1.PrepareSQL;
MyStoredProc1.ParamByName('(invoice_id ').AsInteger := 1234;
MyStoredProc1.Execute;
Code: Select all
Parameter 'invoice_id' not found
What I have tried
I inserted a debug message
Code: Select all
Showmessage( MyStoredProc1.sql.text);
after PrepareSQL and before assigning the parameter value.
On my machine the message displays
Code: Select all
CALL make_invoice(:invoice_id);
Code: Select all
CALL make_invoice()
Why can I call stored procedures using TMyQuery or TMyConnection from my IP address or another IP address but I can only call them using the more appropriate TMyStoredProc when running from my IP address? - and what can I do about it?