mysql_hex_string

mysql_hex_string是一個函式,該函式用於創建可用在SQL語句中的合法SQL字元串。

基本介紹

  • 中文名:mysql_hex_string
  • 頭檔案:#include<mysql.h>
  • 函式原型:unsigned long mysql_hex_string
  • 字元串:合法SQL字元串
頭檔案,函式原型,說明,範例,

頭檔案

#include<mysql.h>

函式原型

unsigned long mysql_hex_string(char *to, const char *from, unsigned long length);

說明

該字元串從形式上編碼為十六進制格式,每個字元編碼為2個十六進制數。結果被置入其中,並添加1個終結Null位元組。"from”所指向的字元串必須是長度位元組“long”。必須為“to”分配緩衝區,緩衝區至少為length*2+1位元組長。當mysql_hex_string()返回時,“to”的內容為由Null終結的字元串。返回值是編碼字元串的長度,不包括終結用Null字元。可採用0xvalue或X'value'格式將返回值置於SQL語句中。但是,返回值不包括0x或X'...'。調用者必須提供所希望的格式是何種。
返回置於“to”中的值的長度,不包括終結用Null字元。

範例

char query[1000],*end;
end = strmov(query,"INSERT INTO test_table values(");
end = strmov(end,"0x");
end += mysql_hex_string(end,"What's this",11);
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));
}
示例中所使用的strmov()函式包含在mysqlclient庫中,它的工作方式類似於strcpy(),但返回指向第1個參數終結Null的指針

相關詞條

熱門詞條

聯絡我們