Bug #7095 Compress/Uncompress function support Blob type
Submitted: 8 Dec 2004 5:45 Modified: 14 Sep 2005 9:54
Reporter: TAT LIM CHIN Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.15-BK OS:Linux (Linux)
Assigned to: Jim Winstead CPU Architecture:Any

[8 Dec 2004 5:45] TAT LIM CHIN
Description:
Becuase application software use report designer to generate
report. If application software store data to database include blob
filed type like image file, i hope can compress blob data after
store in database. This method has big advantage that always take
small size  in database, also improve speed when using MYISAM table type.

I know MySQL ver 4.1 added COMPRESS/UNCOMPRESS function,
but only limit for string. I already try to compress and uncompress blob
data, can be succeed. But if i try to get this blob field using report
designer, cannot detect this is blob field.
    
We can return result but IMAGEDATA filed type already change to
TEXT field, not a blob field type. In this case, report designer cannot
detect it is blob field, so never display image in report.

I use delphi 7, MYDAC V3.1, ReportBuilder v7(report designer).

Thanks.

How to repeat:
   Create Table ImageFile (
      ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
      IMAGEDATA MEDIUMBLOB,
      PRIMARY KEY(ID)
    );

    /* insert some image files using compress function */
    Insert Into ImageFile Values(Null, COMPRESS(/* Image Data */));

    /* after insert, get data using Select */
    Select ID, UNCOMPRESS(IMAGEDATA) IMAGEDATA From ImageFile;
[31 Aug 2005 10:22] Valeriy Kravchuk
Test file. Shows incorrect data type VAR_STRING (253)  istead of BLOB (252)

Attachment: 7095.c (text/x-csrc), 1.29 KiB.

[31 Aug 2005 10:31] Valeriy Kravchuk
See the attached test case. The table used is the following:

mysql> desc ImageFile;
+-----------+---------------------+------+-----+---------+----------------+
| Field     | Type                | Null | Key | Default | Extra          |
+-----------+---------------------+------+-----+---------+----------------+
| ID        | bigint(20) unsigned |      | PRI | NULL    | auto_increment |
| IMAGEDATA | mediumblob          | YES  |     | NULL    |                |
+-----------+---------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

According to the manual (http://dev.mysql.com/doc/mysql/en/string-functions.html):

"(Use of CHAR or VARCHAR to store compressed strings is not recommended. It is better to use a BLOB column instead.)"

We used it in just such a way, and, as original reporter described, will get the result as string, not as a blob, thus making it impossible to use the results of uncomression as blobs directly. The result of Uncompress(BLOB) should be of a BLOB type really.
[31 Aug 2005 10:33] Valeriy Kravchuk
The results of test:

[openxs@Fedora 4.1]$ ./7095
Client info: 4.1.15
Server info: 4.1.15
type=8
length=20
decimals=0
type=253
length=8192
decimals=31
[14 Sep 2005 9:54] Sergei Golubchik
VAR_STRING is correct for the result of the string function.
What matters is the character set. The result of the UNCOMPRESS() has 'binary' character set and BINARY flag set. It means the result is binary data, not a text.