fgo36
asked on
Example of return value for Visual Basic stored functions
I have a Mysql 5.1.46 stored function which is working well in Mysql and C# applications.
I want to use it in Visual Basic and it cann't work (use of ODBC 5.1.8)
The function,
Mystr = Get_sw("123456", "prune")
takes 2 varchar parameters and must return a Varchar
I configure the parameters like this
With My_Obj_DB
.Queries ("Get_sw")
.DefParameter adParamReturnValue, strMsg, adVarChar
.DefParameter adParamInput, "123456", adVarChar
.DefParameter adParamInput, "prune", adVarChar
.ExecuteQueries
End With
and the following error is returned
"Error in SQL syntax"
near
'_latin1"= call Get_sw(_latin1'123456',_la tin1" at line 1
How can I do to solve this error
Thank's
I want to use it in Visual Basic and it cann't work (use of ODBC 5.1.8)
The function,
Mystr = Get_sw("123456", "prune")
takes 2 varchar parameters and must return a Varchar
I configure the parameters like this
With My_Obj_DB
.Queries ("Get_sw")
.DefParameter adParamReturnValue, strMsg, adVarChar
.DefParameter adParamInput, "123456", adVarChar
.DefParameter adParamInput, "prune", adVarChar
.ExecuteQueries
End With
and the following error is returned
"Error in SQL syntax"
near
'_latin1"= call Get_sw(_latin1'123456',_la
How can I do to solve this error
Thank's
ASKER
I have no problem for using a Stored procedure, I just need to have a response with a stored function.
I have try many possiblities but no correct answer, always error.
Hereafter my last try
' Server Win 2003 32Bits, Client Win XP SP 3
' Mysql 5.1.46,
' ODBC Connector 5.1.8
' ConnectionString
' DRIVER={MySql ODBC 5.1 Driver};SERVER=sv;DATABASE =db;UID=us ;PWD=pw;CH ARSET=UTF8 ;OPTION=27 2646155
Set Cn = New ADODB.Connection
Set lCmd = New ADODB.Command
Cn.CursorLocation = adUseClient
Cn.ConnectionString = ConnectionString
Cn.Open
lCmd.ActiveConnection = Cn
With lCmd
.CommandType = adCmdStoredProc
.CommandText = "get_embedded_software_ver sion"
.Parameters.append .CreateParameter("@result" , adVarChar, adParamReturnValue, 40)
.Parameters.append .CreateParameter("@par_eve nt_name", adVarChar, adParamInput, 100)
.Parameters.append .CreateParameter("@par_eve nt_softwar e", adVarChar, adParamInput, 100)
.Parameters.Refresh
End With
lCmd(1) = "3"
lCmd(2) = "eagle"
lCmd.Execute Options:=adExecuteNoRecord s
' ERROR: [MySQL][ODBC 5.1 Driver][mysqld-5.1.46-comm unity]You have an error in your SQL syntax;
' check the manual that corresponds to your MySQL server version for the right syntax to use
' near ''' = call get_embedded_software_vers ion('3', 'eagle')' at line 1
I have try many possiblities but no correct answer, always error.
Hereafter my last try
' Server Win 2003 32Bits, Client Win XP SP 3
' Mysql 5.1.46,
' ODBC Connector 5.1.8
' ConnectionString
' DRIVER={MySql ODBC 5.1 Driver};SERVER=sv;DATABASE
Set Cn = New ADODB.Connection
Set lCmd = New ADODB.Command
Cn.CursorLocation = adUseClient
Cn.ConnectionString = ConnectionString
Cn.Open
lCmd.ActiveConnection = Cn
With lCmd
.CommandType = adCmdStoredProc
.CommandText = "get_embedded_software_ver
.Parameters.append .CreateParameter("@result"
.Parameters.append .CreateParameter("@par_eve
.Parameters.append .CreateParameter("@par_eve
.Parameters.Refresh
End With
lCmd(1) = "3"
lCmd(2) = "eagle"
lCmd.Execute Options:=adExecuteNoRecord
' ERROR: [MySQL][ODBC 5.1 Driver][mysqld-5.1.46-comm
' check the manual that corresponds to your MySQL server version for the right syntax to use
' near ''' = call get_embedded_software_vers
it looks ok generally.
http://www.codeguru.com/forum/archive/index.php/t-182960.html is similar but doesnt use @result (ie just "result")
this appears to be the problem as MySQL seems to be trying to assign the result of the call to nothing.
'' = call get_embedded_software_vers ion('3', 'eagle')
the SP does return a varchar ? should it be char(8) or numeric ? (unlikely)
Possible bug but this was v3.5?? see http://bugs.mysql.com/bug.php?id=15635
http://forums.mysql.com/read.php?98,123762,123824#msg-123824
http://forums.mysql.com/read.php?98,373032,373057#msg-373057
http://www.codeguru.com/forum/archive/index.php/t-182960.html is similar but doesnt use @result (ie just "result")
this appears to be the problem as MySQL seems to be trying to assign the result of the call to nothing.
'' = call get_embedded_software_vers
the SP does return a varchar ? should it be char(8) or numeric ? (unlikely)
Possible bug but this was v3.5?? see http://bugs.mysql.com/bug.php?id=15635
http://forums.mysql.com/read.php?98,123762,123824#msg-123824
http://forums.mysql.com/read.php?98,373032,373057#msg-373057
ASKER
My problem is the same, the .commandText is = to { ? = call Get_emxxx(?, ?) } just before execute.
I tried with different parameters without succcess.
I use stored proc in the same program with no error but I want to use stored func.
Here a simple SQL function that I try, with no success
SHOW WARNINGS;
USE `car`;
-- -------------------------- ---------- ---------- ---------- ---------- ---------- ----
-- Routine DDL
-- -------------------------- ---------- ---------- ---------- ---------- ---------- ----
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `Get_param`(
par_event_name varchar(20)
) RETURNS varchar(100) CHARSET latin1
DETERMINISTIC
BEGIN
DECLARE result varchar(100) DEFAULT '';
SET result = '*NOT_EXIST';
SELECT description INTO result FROM customers
WHERE name = par_event_name;
RETURN result;
END
I tried with different parameters without succcess.
I use stored proc in the same program with no error but I want to use stored func.
Here a simple SQL function that I try, with no success
SHOW WARNINGS;
USE `car`;
-- --------------------------
-- Routine DDL
-- --------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
par_event_name varchar(20)
) RETURNS varchar(100) CHARSET latin1
DETERMINISTIC
BEGIN
DECLARE result varchar(100) DEFAULT '';
SET result = '*NOT_EXIST';
SELECT description INTO result FROM customers
WHERE name = par_event_name;
RETURN result;
END
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I found solution myself
then the calls to the db are a little different. for my use, the result is returned as a recordset,
Open in new window