mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
Bug #21284: Add Field::needs_quote() method and use it in Federated
The fix for bug 17608 removed the behavior of only adding quotes to values that needed it when constructing the queries sent by the federated storage engine. This restores that behavior, but using a new virtual Field method. (The old one had a hardcoded list of field types.) No test included. The behavior can be verified by inspecting the query log on the slave in the federated test.
This commit is contained in:
parent
a9a345d9a5
commit
faebd5a17e
2 changed files with 28 additions and 9 deletions
|
@ -118,6 +118,11 @@ public:
|
|||
*/
|
||||
virtual String *val_str(String*,String *)=0;
|
||||
String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
|
||||
/*
|
||||
str_needs_quotes() returns TRUE if the value returned by val_str() needs
|
||||
to be quoted when used in constructing an SQL query.
|
||||
*/
|
||||
virtual bool str_needs_quotes() { return FALSE; }
|
||||
virtual Item_result result_type () const=0;
|
||||
virtual Item_result cmp_type () const { return result_type(); }
|
||||
virtual Item_result cast_to_int_type () const { return result_type(); }
|
||||
|
@ -386,6 +391,7 @@ public:
|
|||
uint32 max_length() { return field_length; }
|
||||
friend class create_field;
|
||||
my_decimal *val_decimal(my_decimal *);
|
||||
virtual bool str_needs_quotes() { return TRUE; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -1330,6 +1336,7 @@ public:
|
|||
double val_real(void);
|
||||
longlong val_int(void);
|
||||
String *val_str(String*, String *);
|
||||
virtual bool str_needs_quotes() { return TRUE; }
|
||||
my_decimal *val_decimal(my_decimal *);
|
||||
int cmp(const char *a, const char *b)
|
||||
{ return cmp_binary(a, b); }
|
||||
|
|
|
@ -1136,7 +1136,7 @@ bool ha_federated::create_where_from_key(String *to,
|
|||
Field *field= key_part->field;
|
||||
uint store_length= key_part->store_length;
|
||||
uint part_length= min(store_length, length);
|
||||
needs_quotes= 1;
|
||||
needs_quotes= field->str_needs_quotes();
|
||||
DBUG_DUMP("key, start of loop", (char *) ptr, length);
|
||||
|
||||
if (key_part->null_bit)
|
||||
|
@ -1588,10 +1588,13 @@ int ha_federated::write_row(byte *buf)
|
|||
insert_field_value_string.append(FEDERATED_NULL);
|
||||
else
|
||||
{
|
||||
bool needs_quote= (*field)->str_needs_quotes();
|
||||
(*field)->val_str(&insert_field_value_string);
|
||||
values_string.append('\'');
|
||||
if (needs_quote)
|
||||
values_string.append('\'');
|
||||
insert_field_value_string.print(&values_string);
|
||||
values_string.append('\'');
|
||||
if (needs_quote)
|
||||
values_string.append('\'');
|
||||
|
||||
insert_field_value_string.length(0);
|
||||
}
|
||||
|
@ -1804,11 +1807,14 @@ int ha_federated::update_row(const byte *old_data, byte *new_data)
|
|||
update_string.append(FEDERATED_NULL);
|
||||
else
|
||||
{
|
||||
bool needs_quote= (*field)->str_needs_quotes();
|
||||
/* otherwise = */
|
||||
(*field)->val_str(&field_value);
|
||||
update_string.append('\'');
|
||||
if (needs_quote)
|
||||
update_string.append('\'');
|
||||
field_value.print(&update_string);
|
||||
update_string.append('\'');
|
||||
if (needs_quote)
|
||||
update_string.append('\'');
|
||||
field_value.length(0);
|
||||
}
|
||||
|
||||
|
@ -1816,12 +1822,15 @@ int ha_federated::update_row(const byte *old_data, byte *new_data)
|
|||
where_string.append(FEDERATED_ISNULL);
|
||||
else
|
||||
{
|
||||
bool needs_quote= (*field)->str_needs_quotes();
|
||||
where_string.append(FEDERATED_EQ);
|
||||
(*field)->val_str(&field_value,
|
||||
(char*) (old_data + (*field)->offset()));
|
||||
where_string.append('\'');
|
||||
if (needs_quote)
|
||||
where_string.append('\'');
|
||||
field_value.print(&where_string);
|
||||
where_string.append('\'');
|
||||
if (needs_quote)
|
||||
where_string.append('\'');
|
||||
field_value.length(0);
|
||||
}
|
||||
|
||||
|
@ -1895,11 +1904,14 @@ int ha_federated::delete_row(const byte *buf)
|
|||
}
|
||||
else
|
||||
{
|
||||
bool needs_quote= cur_field->str_needs_quotes();
|
||||
delete_string.append(FEDERATED_EQ);
|
||||
cur_field->val_str(&data_string);
|
||||
delete_string.append('\'');
|
||||
if (needs_quote)
|
||||
delete_string.append('\'');
|
||||
data_string.print(&delete_string);
|
||||
delete_string.append('\'');
|
||||
if (needs_quote)
|
||||
delete_string.append('\'');
|
||||
}
|
||||
|
||||
delete_string.append(FEDERATED_AND);
|
||||
|
|
Loading…
Reference in a new issue