diff options
author | Sreeharsha Ramanavarapu <sreeharsha.ramanavarapu@oracle.com> | 2015-07-16 07:56:39 +0530 |
---|---|---|
committer | Sreeharsha Ramanavarapu <sreeharsha.ramanavarapu@oracle.com> | 2015-07-16 07:56:39 +0530 |
commit | 888fabd6909237f55ed9b9cf7a0c852c2e5f0beb (patch) | |
tree | 9fcc3de2a441a39fc7c368f2a58ce1ebe5520711 /sql/field_conv.cc | |
parent | e57e1b235ea0d0cc2e43017ebdccac34db369200 (diff) | |
download | mariadb-git-888fabd6909237f55ed9b9cf7a0c852c2e5f0beb.tar.gz |
Bug #21143080: UPDATE ON VARCHAR AND TEXT COLUMNS PRODUCE
INCORRECT RESULTS
Issue:
-----
Updating varchar and text fields in the same update
statement can produce incorrect results. When a varchar
field is assigned to the text field and the varchar field
is then set to a different value, the text field's result
contains the varchar field's new value.
SOLUTION:
---------
Currently the blob type does not allocate space for the
string to be stored. Instead it contains a pointer to the
varchar string. So when the varchar field is changed as
part of the update statement, the value contained in the
blob also changes.
The fix would be to actually store the value by allocating
space for the blob's string. We can avoid allocating this
space when the varchar field is not being written into.
Diffstat (limited to 'sql/field_conv.cc')
-rw-r--r-- | sql/field_conv.cc | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 17b0d34557a..14c4fd257fe 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -800,15 +800,10 @@ int field_conv(Field *to,Field *from) { // Be sure the value is stored Field_blob *blob=(Field_blob*) to; from->val_str(&blob->value); - /* - Copy value if copy_blobs is set, or source is not a string and - we have a pointer to its internal string conversion buffer. - */ - if (to->table->copy_blobs || - (!blob->value.is_alloced() && - from->real_type() != MYSQL_TYPE_STRING && - from->real_type() != MYSQL_TYPE_VARCHAR)) + + if (!blob->value.is_alloced() && from->is_updatable()) blob->value.copy(); + return blob->store(blob->value.ptr(),blob->value.length(),from->charset()); } if (from->real_type() == MYSQL_TYPE_ENUM && |