diff options
author | unknown <bar@mysql.com> | 2004-10-19 09:50:47 +0500 |
---|---|---|
committer | unknown <bar@mysql.com> | 2004-10-19 09:50:47 +0500 |
commit | 2428fb5c2b01aba74fb3cb49bca9d690c203b715 (patch) | |
tree | 003992759c3f0ff8c4637eb2664ed2b87b051549 /libmysql | |
parent | 38e717ea13bafb1d63865b6b326e78732b6b988b (diff) | |
download | mariadb-git-2428fb5c2b01aba74fb3cb49bca9d690c203b715.tar.gz |
libmysql.c:
New function mysql_hex_string()
libmysql/libmysql.c:
New function mysql_hex_string()
Diffstat (limited to 'libmysql')
-rw-r--r-- | libmysql/libmysql.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index a591ad9317d..9257bf0efd0 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3154,6 +3154,39 @@ void my_net_local_init(NET *net) } /* + This function is used to create HEX string that you + can use in a SQL statement in of the either ways: + INSERT INTO blob_column VALUES (0xAABBCC); (any MySQL version) + INSERT INTO blob_column VALUES (X'AABBCC'); (4.1 and higher) + + The string in "from" is encoded to a HEX string. + 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. + Each character needs two bytes, and you need room for the terminating + null byte. When mysql_hex_string() returns, the contents of "to" will + be a null-terminated string. The return value is the length of the + encoded string, not including the terminating null character. +*/ + +unsigned long +mysql_hex_string(char *to, const char *from, unsigned long length) +{ + char *to0= to; + const char *end; + static char hex[]= "0123456789ABCDEF"; + + for (end= from + length; from < end; from++) + { + *to++= hex[((unsigned char) *from) >> 4]; + *to++= hex[((unsigned char) *from) & 0x0F]; + } + *to= '\0'; + return to-to0; +} + +/* Add escape characters to a string (blob?) to make it suitable for a insert to should at least have place for length*2+1 chars Returns the length of the to string |