summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc34
1 files changed, 16 insertions, 18 deletions
diff --git a/sql/table.cc b/sql/table.cc
index a90eb2eee15..f7dddd92553 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -3442,18 +3442,23 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
{
char buff[MAX_FIELD_WIDTH], *to;
String str(buff,sizeof(buff),&my_charset_bin);
- uint length;
+ bool rc;
+ THD *thd= field->get_thd();
+ ulonglong sql_mode_backup= thd->variables.sql_mode;
+ thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
field->val_str(&str);
- if (!(length= str.length()))
+ if ((rc= !str.length() ||
+ !(to= strmake_root(mem, str.ptr(), str.length()))))
{
res->length(0);
- return 1;
+ goto ex;
}
- if (!(to= strmake_root(mem, str.ptr(), length)))
- length= 0; // Safety fix
- res->set(to, length, field->charset());
- return 0;
+ res->set(to, str.length(), field->charset());
+
+ex:
+ thd->variables.sql_mode= sql_mode_backup;
+ return rc;
}
@@ -3472,17 +3477,10 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
char *get_field(MEM_ROOT *mem, Field *field)
{
- char buff[MAX_FIELD_WIDTH], *to;
- String str(buff,sizeof(buff),&my_charset_bin);
- uint length;
-
- field->val_str(&str);
- length= str.length();
- if (!length || !(to= (char*) alloc_root(mem,length+1)))
- return NullS;
- memcpy(to,str.ptr(),(uint) length);
- to[length]=0;
- return to;
+ String str;
+ bool rc= get_field(mem, field, &str);
+ DBUG_ASSERT(rc || str.ptr()[str.length()] == '\0');
+ return rc ? NullS : (char *) str.ptr();
}
/*