summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <vva@eagle.mysql.r18.ru>2003-04-22 18:41:47 -0400
committerunknown <vva@eagle.mysql.r18.ru>2003-04-22 18:41:47 -0400
commit5ab46afca6cf1e0ad7a298db54f3971234cb8f6c (patch)
tree82a6ee88ce718a01374afecdb2710ee9c420cd6e /sql
parent7c87a3f140ac801c0922b3a24e59381f627f105a (diff)
downloadmariadb-git-5ab46afca6cf1e0ad7a298db54f3971234cb8f6c.tar.gz
small compress/uncompress modification after monty's review
Diffstat (limited to 'sql')
-rw-r--r--sql/item_create.cc8
-rw-r--r--sql/item_create.h2
-rw-r--r--sql/item_func.cc3
-rw-r--r--sql/item_strfunc.cc39
-rw-r--r--sql/lex.h4
5 files changed, 24 insertions, 32 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 2fb753912eb..23e4ce1d2b4 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -646,7 +646,13 @@ Item *create_func_point(Item *a, Item *b)
return new Item_func_point(a, b);
}
-#ifdef HAVE_COMPRESS
+#if !defined(HAVE_COMPRESS)
+
+Item *create_func_compress (Item*a __attribute__((unused))){return 0;}
+Item *create_func_uncompress (Item*a __attribute__((unused))){return 0;}
+Item *create_func_uncompressed_length(Item*a __attribute__((unused))){return 0;}
+
+#else
Item *create_func_compress(Item* a)
{
diff --git a/sql/item_create.h b/sql/item_create.h
index 90595859bcc..c79fe07b8d4 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -142,9 +142,7 @@ Item *create_func_numgeometries(Item *a);
Item *create_func_point(Item *a, Item *b);
-#ifdef HAVE_COMPRESS
Item *create_func_compress(Item *a);
Item *create_func_uncompress(Item *a);
Item *create_func_uncompressed_length(Item *a);
-#endif
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 7a01ea898bb..d427e3c5a3a 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -993,7 +993,8 @@ longlong Item_func_uncompressed_length::val_int()
return 0; /* purecov: inspected */
}
null_value=0;
- return uint4korr(res->c_ptr());
+ if (res->is_empty()) return 0;
+ return uint4korr(res->c_ptr()) & 0x3FFFFFFF;
}
#endif /* HAVE_COMPRESS */
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 5fb6af958fb..56e3eb2cb5f 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2924,6 +2924,8 @@ ret:
String *Item_func_compress::val_str(String *str)
{
String *res= args[0]->val_str(str);
+ if (res->is_empty()) return res;
+
int err= Z_OK;
int code;
@@ -2939,14 +2941,13 @@ String *Item_func_compress::val_str(String *str)
compress(compress(compress(...)))
I.e. zlib give number 'at least'..
*/
- uLongf new_size= (uLongf)((res->length()*120)/100)+12;
-
- buffer.realloc((uint32)new_size+sizeof(int32)+sizeof(char));
+ ulong new_size= (ulong)((res->length()*120)/100)+12;
- Byte *body= ((Byte*)buffer.c_ptr())+sizeof(int32);
- err= compress(body, &new_size,(const Bytef*)res->c_ptr(), res->length());
+ buffer.realloc((uint32)new_size + 4);
+ Byte *body= ((Byte*)buffer.c_ptr()) + 4;
- if (err != Z_OK)
+ if ((err= compress(body, &new_size,
+ (const Bytef*)res->c_ptr(), res->length())) != Z_OK)
{
code= err==Z_MEM_ERROR ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_BUF_ERROR;
push_warning(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,code,ER(code));
@@ -2954,18 +2955,8 @@ String *Item_func_compress::val_str(String *str)
return 0;
}
- int4store(buffer.c_ptr(),res->length());
- buffer.length((uint32)new_size+sizeof(int32));
-
- /* This is for the stupid char fields which trimm ' ': */
- char *last_char= ((char*)body)+new_size-1;
- if (*last_char == ' ')
- {
- *++last_char= '.';
- new_size++;
- }
-
- buffer.length((uint32)new_size+sizeof(int32));
+ int4store(buffer.c_ptr(),res->length() & 0x3FFFFFFF);
+ buffer.length((uint32)new_size + 4);
return &buffer;
}
@@ -2973,7 +2964,9 @@ String *Item_func_compress::val_str(String *str)
String *Item_func_uncompress::val_str(String *str)
{
String *res= args[0]->val_str(str);
- uLongf new_size= uint4korr(res->c_ptr());
+ if (res->is_empty()) return res;
+
+ ulong new_size= uint4korr(res->c_ptr()) & 0x3FFFFFFF;
int err= Z_OK;
uint code;
@@ -2982,16 +2975,14 @@ String *Item_func_uncompress::val_str(String *str)
push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_TOO_BIG_FOR_UNCOMPRESS,
ER(ER_TOO_BIG_FOR_UNCOMPRESS),MAX_BLOB_WIDTH);
- null_value= 1;
+ null_value= 0;
return 0;
}
buffer.realloc((uint32)new_size);
- err= uncompress((Byte*)buffer.c_ptr(), &new_size,
- ((const Bytef*)res->c_ptr())+sizeof(int32),res->length());
-
- if (err == Z_OK)
+ if ((err= uncompress((Byte*)buffer.c_ptr(), &new_size,
+ ((const Bytef*)res->c_ptr())+4,res->length())) == Z_OK)
{
buffer.length((uint32)new_size);
return &buffer;
diff --git a/sql/lex.h b/sql/lex.h
index b5a81a30991..e51b3efff87 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -448,9 +448,7 @@ static SYMBOL sql_functions[] = {
{ "CHARACTER_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
{ "COALESCE", SYM(COALESCE),0,0},
{ "COERCIBILITY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_coercibility)},
-#ifdef HAVE_COMPRESS
{ "COMPRESS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_compress)},
-#endif
{ "CONCAT", SYM(CONCAT),0,0},
{ "CONCAT_WS", SYM(CONCAT_WS),0,0},
{ "CONNECTION_ID", SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_connection_id)},
@@ -627,10 +625,8 @@ static SYMBOL sql_functions[] = {
{ "TOUCHES", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_touches)},
{ "TRIM", SYM(TRIM),0,0},
{ "UCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ucase)},
-#ifdef HAVE_COMPRESS
{ "UNCOMPRESS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_uncompress)},
{ "UNCOMPRESSED_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_uncompressed_length)},
-#endif
{ "UNIQUE_USERS", SYM(UNIQUE_USERS),0,0},
{ "UNIX_TIMESTAMP", SYM(UNIX_TIMESTAMP),0,0},
{ "UPPER", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ucase)},