MySql Connector prepared statement only transfers 64 bytes

后端 未结 1 1170
粉色の甜心
粉色の甜心 2021-01-24 02:11

I am using the MySql Connector C++ to store a JPEG image from a file into the database. I am using the prepared statement. After execution of the prepared statement, only the

相关标签:
1条回答
  • 2021-01-24 02:57

    The issue lies in the constructor of the image file:

    std::ifstream   blob_file(filename.c_str());
    

    This should have the binary mode attribute:

    std::ifstream   blob_file(filename.c_str(), std::ios_base::binary);
    

    The file, a JPEG image, is binary data.

    Also, the hex dump at byte 65 shows 1a, which is the Windows OS end of file character:
    0000040 1a14 1115 1811 1821 1d1a 1f1d 1f1f 1713

    After fixing the constructor, the MySql shows the data size:

    mysql> SELECT ID_Picture, LENGTH(Image_Data)
        -> FROM picture_image_data
        -> WHERE ID_Picture = 1;
    +------------+--------------------+
    | ID_Picture | LENGTH(Image_Data) |
    +------------+--------------------+
    |          1 |              18453 |
    +------------+--------------------+
    1 row in set (0.00 sec)
    
    0 讨论(0)
提交回复
热议问题