summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bar@bar.intranet.mysql.r18.ru>2004-05-25 15:54:03 +0500
committerunknown <bar@bar.intranet.mysql.r18.ru>2004-05-25 15:54:03 +0500
commit9983aed876568891e07fbdeed402c9c7f1320c03 (patch)
tree5b89afdba70f8480882113658142e4dfd12afac7
parentf80e9e042ee33e1debdac1e46992470e495921c9 (diff)
downloadmariadb-git-9983aed876568891e07fbdeed402c9c7f1320c03.tar.gz
1. Some optimization when conversion is not needed.
2. One now must pass length argument into append(const char *str, uint length), length is not calculated internally anymore.
-rw-r--r--sql/sql_select.cc7
-rw-r--r--sql/sql_show.cc6
-rw-r--r--sql/sql_string.cc43
-rw-r--r--sql/sql_string.h3
4 files changed, 38 insertions, 21 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c3bbae1390c..8d651c00a0a 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -9261,7 +9261,9 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
{
if (tmp1.length())
tmp1.append(',');
- tmp1.append(table->key_info[j].name, 0, system_charset_info);
+ tmp1.append(table->key_info[j].name,
+ strlen(table->key_info[j].name),
+ system_charset_info);
}
}
}
@@ -9281,7 +9283,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
{
if (tmp2.length())
tmp2.append(',');
- tmp2.append((*ref)->name(), 0, system_charset_info);
+ tmp2.append((*ref)->name(), strlen((*ref)->name()),
+ system_charset_info);
}
item_list.push_back(new Item_string(tmp2.ptr(),tmp2.length(),cs));
}
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 4fb85d9bab7..a54a6fa1a4c 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1207,7 +1207,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
{
List<Item> field_list;
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], *end, *alias;
- String type(tmp, sizeof(tmp),&my_charset_bin);
+ String type(tmp, sizeof(tmp), system_charset_info);
Field **ptr,*field;
uint primary_key;
KEY *key_info;
@@ -1254,7 +1254,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
type.set(tmp, sizeof(tmp),&my_charset_bin);
field->sql_type(type);
- packet->append(type.ptr(),type.length());
+ packet->append(type.ptr(), type.length(), system_charset_info);
if (field->has_charset() && !limited_mysql_mode && !foreign_db_mode)
{
@@ -1313,7 +1313,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
else if (field->maybe_null())
packet->append("NULL", 4); // Null as default
else
- packet->append(tmp,0);
+ packet->append(tmp);
}
if (!foreign_db_mode && !limited_mysql_mode &&
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index fb2d1661357..b60aee2b5df 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -416,16 +416,18 @@ bool String::append(const String &s)
/*
- Append a latin1 string to the a string of the current character set
+ Append an ASCII string to the a string of the current character set
*/
-
bool String::append(const char *s,uint32 arg_length)
{
- if (!arg_length) // Default argument
- if (!(arg_length= (uint32) strlen(s)))
- return FALSE;
- if (str_charset->mbmaxlen > 1)
+ if (!arg_length)
+ return FALSE;
+
+ /*
+ For an ASCII incompatible string, e.g. UCS-2, we need to convert
+ */
+ if (str_charset->mbminlen > 1)
{
uint32 add_length=arg_length * str_charset->mbmaxlen;
if (realloc(str_length+ add_length))
@@ -434,6 +436,10 @@ bool String::append(const char *s,uint32 arg_length)
s, arg_length, &my_charset_latin1);
return FALSE;
}
+
+ /*
+ For an ASCII compatinble string we can just append.
+ */
if (realloc(str_length+arg_length))
return TRUE;
memcpy(Ptr+str_length,s,arg_length);
@@ -443,29 +449,36 @@ bool String::append(const char *s,uint32 arg_length)
/*
+ Append a 0-terminated ASCII string
+*/
+
+bool String::append(const char *s)
+{
+ return append(s, strlen(s));
+}
+
+
+/*
Append a string in the given charset to the string
with character set recoding
*/
-
bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs)
{
uint32 dummy_offset;
- uint32 add_length;
-
- if (!arg_length && !(arg_length= (uint32)strlen(s)))
- return FALSE;
-
- add_length= arg_length * str_charset->mbmaxlen;
- if (realloc(str_length + add_length))
- return TRUE;
+
if (needs_conversion(arg_length, cs, str_charset, &dummy_offset))
{
+ uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
+ if (realloc(str_length + add_length))
+ return TRUE;
str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
s, arg_length, cs);
}
else
{
+ if (realloc(str_length + arg_length))
+ return TRUE;
memcpy(Ptr + str_length, s, arg_length);
str_length+= arg_length;
}
diff --git a/sql/sql_string.h b/sql/sql_string.h
index c24511a9f74..d559218bcb9 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -190,7 +190,8 @@ public:
bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom,
CHARSET_INFO *csto);
bool append(const String &s);
- bool append(const char *s,uint32 arg_length=0);
+ bool append(const char *s);
+ bool append(const char *s,uint32 arg_length);
bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs);
bool append(IO_CACHE* file, uint32 arg_length);
bool append_with_prefill(const char *s, uint32 arg_length,