PDF (美式信紙) - 1.4Mb
PDF (A4) - 1.4Mb
unsigned long
mysql_hex_string(char *to,
const char *from,
unsigned long length)
此函式會建立合法的 SQL 字串,以便在 SQL 陳述式中使用。請參閱字串常值。
from
引數中的字串會以十六進位格式編碼,每個字元會編碼為兩個十六進位數字。結果會放在 to
引數中,後面接著一個終止空位元組。
由 from
所指向的字串長度必須為 length
個位元組。您必須將 to
緩衝區配置為至少 length*2+1
個位元組長。當mysql_hex_string()
傳回時,to
的內容會是空值終止的字串。傳回值為已編碼字串的長度,不包括終止空位元組。
傳回值可以使用 X'
或 value
'0x
格式放入 SQL 陳述式中。但是,傳回值不包括 value
X'...'
或 0x
。呼叫者必須提供所需的任一格式。
char query[1000],*end;
end = strmov(query,"INSERT INTO test_table values(");
end = strmov(end,"X'");
end += mysql_hex_string(end,"What is this",12);
end = strmov(end,"',X'");
end += mysql_hex_string(end,"binary data: \0\r\n",16);
end = strmov(end,"')");
if (mysql_real_query(&mysql,query,(unsigned int) (end - query)))
{
fprintf(stderr, "Failed to insert row, Error: %s\n",
mysql_error(&mysql));
}
範例中使用的 strmov()
函式包含在 libmysqlclient
程式庫中,其運作方式類似於 strcpy()
,但會傳回第一個參數的終止空位元組的指標。