diff options
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/sql/field.cc b/sql/field.cc index 41b6eba695c..b1212025d30 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -524,6 +524,115 @@ Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table, return tmp; } +/* + SYNOPSIS + Field::quote_data() + unquoted_string Pointer pointing to the value of a field + + DESCRIPTION + Simple method that passes the field type to the method "type_quote" + To get a true/false value as to whether the value in string1 needs + to be enclosed with quotes. This ensures that values in the final + sql statement to be passed to the remote server will be quoted properly + + RETURN_VALUE + void Immediately - if string doesn't need quote + void Upon prepending/appending quotes on each side of variable + +*/ +bool Field::quote_data(String *unquoted_string) +{ + char escaped_string[IO_SIZE]; + char *unquoted_string_buffer= (char *)(unquoted_string->ptr()); + uint need_quotes; + + DBUG_ENTER("Field::quote_data"); + // this is the same call that mysql_real_escape_string() calls + escape_string_for_mysql(&my_charset_bin, (char *)escaped_string, + unquoted_string->ptr(), unquoted_string->length()); + + + if (is_null()) + DBUG_RETURN(0); + + need_quotes= needs_quotes(); + + if (need_quotes == 0) + { + DBUG_RETURN(0); + } + else + { + // reset string, then re-append with quotes and escaped values + unquoted_string->length(0); + if (unquoted_string->append("'")) + DBUG_RETURN(1); + if (unquoted_string->append((char *)escaped_string)) + DBUG_RETURN(1); + if (unquoted_string->append("'")) + DBUG_RETURN(1); + } + //DBUG_PRINT("Field::quote_data", + // ("FINAL quote_flag %d unquoted_string %s escaped_string %s", + //needs_quotes, unquoted_string->c_ptr_quick(), escaped_string)); + DBUG_RETURN(0); +} + +/* + Quote a field type if needed + + SYNOPSIS + Field::type_quote + + DESCRIPTION + Simple method to give true/false whether a field should be quoted. + Used when constructing INSERT and UPDATE queries to the remote server + see write_row and update_row + + RETURN VALUE + 0 if value is of type NOT needing quotes + 1 if value is of type needing quotes +*/ +bool Field::needs_quotes(void) +{ + DBUG_ENTER("Field::type_quote"); + + switch(type()) { + //FIX this when kernel is fixed + case MYSQL_TYPE_VARCHAR : + case FIELD_TYPE_STRING : + case FIELD_TYPE_VAR_STRING : + case FIELD_TYPE_YEAR : + case FIELD_TYPE_NEWDATE : + case FIELD_TYPE_TIME : + case FIELD_TYPE_TIMESTAMP : + case FIELD_TYPE_DATE : + case FIELD_TYPE_DATETIME : + case FIELD_TYPE_TINY_BLOB : + case FIELD_TYPE_BLOB : + case FIELD_TYPE_MEDIUM_BLOB : + case FIELD_TYPE_LONG_BLOB : + case FIELD_TYPE_GEOMETRY : + DBUG_RETURN(1); + + case FIELD_TYPE_DECIMAL : + case FIELD_TYPE_TINY : + case FIELD_TYPE_SHORT : + case FIELD_TYPE_INT24 : + case FIELD_TYPE_LONG : + case FIELD_TYPE_FLOAT : + case FIELD_TYPE_DOUBLE : + case FIELD_TYPE_LONGLONG : + case FIELD_TYPE_NULL : + case FIELD_TYPE_SET : + case FIELD_TYPE_ENUM : + DBUG_RETURN(0); + + default: DBUG_RETURN(0); + } + DBUG_RETURN(0); + +} /**************************************************************************** Field_null, a field that always return NULL |