I try to call a procedure with binary parameter in a prepared statement. But it fails in all cases.
All the exemples I could find on web, relate to output binary value , never when input value.
How can I do ?
thanks in advance.
A very simple procedure :
CREATE PROCEDURE `testVarsGet2` (
IN i_ulv BINARY(12),
OUT o_cnt INT(11),
OUT o_errno INT(11))
testVarsGet2:BEGIN
DECLARE t_ulv BINARY(12);
select `ulv` into t_ulv from `testVars` where `ulv` =i_ulv;
IF ROW_COUNT() = 0 THEN
SET o_errno = -1002;
LEAVE testVarsGet2;
END IF;
select `cnt` into o_cnt from `testVars` where `ulv` = i_ulv;
SET o_errno = 0;
LEAVE testVarsGet2;
END;
If ulv is ok, o_errno = 0 , if not o_errno =- 1002
command line :
mysql> call testVarsGet2 (0x7124A57EF08100010000DF3F,@cnt , @err); select @cnt, @err;
Query OK, 1 row affected (0.00 sec)
+------+------+
| @cnt | @err |
+------+------+
| 1 | 0 |
+------+------+
1 row in set (0.00 sec)
or
mysql> call testVarsGet2 (unhex('7124A57EF08100010000DF3F'),@cnt , @err); select @cnt, @err;
Query OK, 1 row affected (0.00 sec)
+------+------+
| @cnt | @err |
+------+------+
| 1 | 0 |
+------+------+
1 row in set (0.00 sec)
but in a C/C++ program , if I use statement , it fails
mysql_stmt_prepare(stmt, "call testVarsGet2 ( unhex(?), ? , ?)", strlen(..));
with
const char * value = "7124A57EF08100010000DF3F"
len = 24;
bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[0].buffer = (char *)value;
bind[0].buffer_length = 32;
bind[0].is_null= 0;
bind[0].length= &len;
or
mysql_stmt_prepare(stmt, "call testVarsGet2 ( ?, ? , ?)", strlen(..));
value = "0x7124A57EF08100010000DF3F"
or with a binary value
const char * value = "7124A57EF08100010000DF3F"
len = 12
unsigned char * value_bin = hex2bin (value );
bind[0].buffer_type = MYSQL_TYPE_BLOB;
bind[0].buffer = (char *)value_bin;
bind[0].buffer_length = 12;
bind[0].is_null= 0;
bind[0].length= &len;
In all cases I get o_errno = -1002
How to pass a binary value ????
Thank you in advance.
CREATE PROCEDUREtestVarsGet3` (IN i_ulv BINARY(12)) BEGIN select hex(i_ulv) END ` I finally found the problem in my code the good method is buffer_type = MYSQL_TYPE_BLOB with buffer = value_bin = hex2bin ("7124A57EF08100010000DF3F");