mysql_hex_string_MySQL 5.1 英文手册 :: 21.9.3.34 mysql_hex_string()

21.9.3.34. mysql_hex_string()

unsigned long mysql_hex_string(char *to, const char

*from, unsigned long length)

Description

This function is used to create a legal SQL string that you can

use in an SQL statement. See Section 8.1.1, “Strings”.

The string in from is encoded to hexadecimal

format, with each character encoded as two hexadecimal digits.

The result is placed in to and a terminating

null byte is appended.

The string pointed to by from must be

length bytes long. You must allocate the

to buffer to be at least

length*2+1 bytes long. When

mysql_hex_string() returns, the

contents of to is a null-terminated string.

The return value is the length of the encoded string, not

including the terminating null character.

The return value can be placed into an SQL statement using

either 0xvalue or

X'value' format.

However, the return value does not include the

0x or X'...'. The caller

must supply whichever of those is desired.

Example

char query[1000],*end;

end = strmov(query,"INSERT INTO test_table values(");

end = strmov(end,"0x");

end += mysql_hex_string(end,"What is this",12);

end = strmov(end,",0x");

end += mysql_hex_string(end,"binary data: \0\r\n",16);

*end++ = ')';

if (mysql_real_query(&mysql,query,(unsigned int) (end - query)))

{

fprintf(stderr, "Failed to insert row, Error: %s\n",

mysql_error(&mysql));

}

The strmov() function used in the example is

included in the mysqlclient library and works

like strcpy() but returns a pointer to the

terminating null of the first parameter.

Return Values

The length of the value placed into to, not

including the terminating null character.

Errors

None.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值