Jump to content

MTA-MySQL and Stored Procedures


churchill

Recommended Posts

has anyone tried to call an SP from mta that does a SELECT statement and returns a mysql query result? it works fine with SPs that have INSERTs or UPDATEs, but it seems SELECT statements have to be inline ? :(

I can't remember the error message it gives but it seems like a common problem with php/mysql systems as well, with the answer being to use mysqli instead of mysql, but that's probably not an option here.

I've not tested whether you can return OUT parameters so perhaps that could be a solution in some cases?

Link to comment
has anyone tried to call an SP from mta that does a SELECT statement and returns a mysql query result? it works fine with SPs that have INSERTs or UPDATEs, but it seems SELECT statements have to be inline ? :(

I can't remember the error message it gives but it seems like a common problem with php/mysql systems as well, with the answer being to use mysqli instead of mysql, but that's probably not an option here.

I've not tested whether you can return OUT parameters so perhaps that could be a solution in some cases?

Eh... I don't understand what you're saying... =/

Anyway, I use MTA-MySQL, and it works fine. Even select works fine.

You might need mysql_fetch_rows perhaps?

Link to comment
has anyone tried to call an SP from mta that does a SELECT statement and returns a mysql query result? it works fine with SPs that have INSERTs or UPDATEs, but it seems SELECT statements have to be inline ? :(

I can't remember the error message it gives but it seems like a common problem with php/mysql systems as well, with the answer being to use mysqli instead of mysql, but that's probably not an option here.

I've not tested whether you can return OUT parameters so perhaps that could be a solution in some cases?

Eh... I don't understand what you're saying... =/

Anyway, I use MTA-MySQL, and it works fine. Even select works fine.

You might need mysql_fetch_rows perhaps?

Ok, I'll explain it another way:

This works:

MySQLResult mysql_query (handler, "SELECT someColumn FROM someTable WHERE someOtherColumn = " .. someValue) 

And this works:

MySQLResult mysql_query (handler, "INSERT INTO someTable (someColumn, someOtherColumn) VALUES (" .. someValue .. "," .. someOtherValue .. ")") 

And this also works:

MySQLResult mysql_query (handler, "call AddSomething(" .. someValue .. "," .. someOtherValue .. ")") 

where AddSomething is the name of a Stored Procedure on the MySQL DB server, that does goes something like:

CREATE PROCEDURE AddSomething (IN someValue INT, in someOtherValue INT) 
BEGIN  
INSERT INTO someTable (someColumn, someOtherColumn) VALUES (someValue, someOtherValue); 
END 

However, this does not work:

MySQLResult mysql_query (handler, "call GetSomething(" .. someValue .. ")") 

where GetSomething is an SP like:

CREATE PROCEDURE GetSomething(IN someValue INT) 
BEGIN  
SELECT someColumn FROM someTable WHERE somOtherColumn = someValue 
END 

You get me? I would have expected mySQLResult to still contain a valid sql result, but instead you get an error. In order to understand the question, you need to understand what Stored Procedures are :)

Link to comment

Well that's what I was hoping, I thought maybe there is another way to call it, but from what i've read, it's a symptom of using the original mysql library, rather than the improved mysqli, so I think I just have to accept it can't be done, or create my own MTA-MySQLi module - and that AIN'T gonna happen :)

Link to comment
Well that's what I was hoping, I thought maybe there is another way to call it, but from what i've read, it's a symptom of using the original mysql library, rather than the improved mysqli, so I think I just have to accept it can't be done, or create my own MTA-MySQLi module - and that AIN'T gonna happen :)

Speaking of bugs...

CREATE PROCEDURE GetSomething(IN someValue INT)

BEGIN

SELECT someColumn FROM someTable WHERE somOtherColumn = someValue

END

somOtherColumn

I think you're missing something there... =/

EDIT: In case you still don't see it, compare it to:

CREATE PROCEDURE AddSomething (IN someValue INT, in someOtherValue INT)

BEGIN

INSERT INTO someTable (someColumn, someOtherColumn) VALUES (someValue, someOtherValue);

END

Or...

someOtherColumn
Link to comment
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...