mysql_affected_rows()
mysql_change_user()
mysql_character_set_name()
mysql_close()
mysql_connect()
mysql_create_db()
mysql_data_seek()
mysql_debug()
mysql_drop_db()
mysql_dump_debug_info()
mysql_eof()
mysql_errno()
mysql_error()
mysql_escape_string()
mysql_fetch_field()
mysql_fetch_field_direct()
mysql_fetch_fields()
mysql_fetch_lengths()
mysql_fetch_row()
mysql_field_count()
mysql_field_seek()
mysql_field_tell()
mysql_free_result()
mysql_get_client_info()
mysql_get_host_info()
mysql_get_proto_info()
mysql_get_server_info()
mysql_info()
mysql_init()
mysql_insert_id()
mysql_kill()
mysql_list_dbs()
mysql_list_fields()
mysql_list_processes()
mysql_list_tables()
mysql_num_fields()
mysql_num_rows()
mysql_options()
mysql_ping()
mysql_query()
mysql_real_connect()
mysql_real_escape_string()
mysql_real_query()
mysql_reload()
mysql_row_seek()
mysql_row_tell()
mysql_select_db()
mysql_shutdown()
mysql_stat()
mysql_store_result()
mysql_thread_id()
mysql_use_result()
Buy this Reference Manual in softcover from Barnes & Noble!
mysql_real_escape_string()
unsigned long mysql_real_escape_string(MYSQL *mysql, char *to, const char *from, unsigned long length)
Эта функция используется для создания допустимой SQL- строки, которую можно использовать в команде SQL. See section 6.1.1.1 Cтроки.
Строка из секции from
кодируется в экранированную SQL-строку, принимая во внимание текущую кодировку данного соединения. Результат помещается в секцию to с добавлением концевого нулевого байта. Кодируются следующие символы: NUL
(ASCII 0), `\n', `\r', `\', `'', `"' и Ctrl-Z (see section 6.1.1 Литералы: представление строк и чисел).
Строка, указанная в секции from
, должна быть длиной length
байтов. Необходимо выделить для секции to буфер величиной по меньшей мере length*2+1
байтов (в наихудшем случае каждый символ может потребовать кодировки с использованием двух байтов и, кроме того, необходимо место для концевого нулевого байта). При возврате функции mysql_escape_string()
содержимое секции to будет представлять собой строку с нулевым окончанием. Возвращаемая величина представляет собой длину данной кодированной строки, не включая концевой нулевой символ.
char query[1000],*end; end = strmov(query,"INSERT INTO test_table values("); *end++ = '\''; end += mysql_real_escape_string(&mysql, end,"What's this",11); *end++ = '\''; *end++ = ','; *end++ = '\''; end += mysql_real_escape_string(&mysql, end,"binary data: \0\r\n",16); *end++ = '\''; *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()
, но возвращает указатель на концевой нуль первого параметра.
Длина величины, помещенной в секции to, не включая концевой нулевой символ.
Нет.
Posted by on Monday January 20 2003, @1:12am | [Delete] [Edit] |
Documentation is unclear (at least to me):
> taking into account the current character
> set of the connection
What does this mean? How is mysql_real_escape_string affected by the character set?
To test the feature, I run the mysql server with default-character-set=usa7
Then I used mysql_real_escape_string on a string containing german special characters (ДЖЭъ), which should be illegal for the usa7 charset; nothing happened, i.e. mysql_real_escape_string neither removed nor changed these characters.
Thus, I experienced no change compared to mysql_escape_string.
Posted by Gerard Boor on Wednesday March 5 2003, @3:13am | [Delete] [Edit] |
This doesn't work when using the VC++ APIs for Win32 (and maybe also not in the BCB APIs), you get an unresolved external, even with all libs included.
Here is a solution that does the same. Buffer1 is your binary data, Buffer 2 is the data you put into the query;
char Buffer1[100]
char Buffer2[201]
for(int x = 0; x < 100; x++)
{
switch(Buffer[x])
{
case '\0':
Picture += "\\0";
break;
case '\n':
Picture += "\\n";
break;
case '\r':
Picture += "\\r";
break;
case '\'':
Picture += "\\'";
break;
case '"':
Picture += "\\\"";
break;
case '\\':
Picture += "\\\\";
break;
default:
Picture += Buffer[y];
break;
}
Posted by Gerard Boor on Wednesday March 5 2003, @3:14am | [Delete] [Edit] |
Errata: of course the 'Picture' should be 'Buffer2', sorry for the inconvenience.
Add your own comment.