Bug #94503 getString() fails for large text
Submitted: 28 Feb 1:56 Modified: 2 Apr 13:21
Reporter: More More Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / C++ Severity:S2 (Serious)
Version:1.1.9-4+b1 OS:Debian (buster)
Assigned to: CPU Architecture:x86 (amd64)

[28 Feb 1:56] More More
Description:
I find if the text content is large (seems over 64), getString() will always return a wrong content (seems after 64 bytes). I use Debian buster latest upgrade as blow:

ii  libmysqlcppconn-dev:amd64             1.1.9-4+b1                           amd64        MySQL Connector for C++ (development files)
ii  libmysqlcppconn7v5:amd64              1.1.9-4+b1                           amd64        MySQL Connector for C++ (library)
ii  mariadb-server                        1:10.1.37-3                          all          MariaDB database server (metapackage depending on the latest version)
ii  mariadb-server-10.1                   1:10.1.37-3                          amd64        MariaDB database server binaries

How to repeat:
My test result:

vault@sam30:~/More/Test$ ./sam-test -t database/archive
Running 1 test case...
/home/vault/More/SAM1.3/Test/DatabaseTest.cpp(71): fatal error: in "database/archive": critical check exclusion == GetProperty("policy.1.exclusion.list") has failed [d://folder|e:log|f:abc.txt//|f:folder/abc.txt|e:.txt|e:*.pdf|e:folder/*.txt != d://folder|e:log|f:abc.txt//|f:folder/abc.txt|e:.txt|e:*.pdf|e:f
= ?;?]

My test code is blow (it will fail at the last line always):

string exclusion = string("d://folder|e:log|f:abc.txt//")                                                                            
    + "|f:folder/abc.txt|e:.txt|e:*.pdf"                                                                                         
    + "|e:folder/*.txt";
InsertProperity("policy.1.exclusion.list", exclusion);                                                                               
string exclusionDb = GetProperty("policy.1.exclusion.list");                                                                         
BOOST_REQUIRE_EQUAL(
    exclusion.size(), GetProperty("policy.1.exclusion.list").size());                                                            
BOOST_REQUIRE_EQUAL(exclusion, GetProperty("policy.1.exclusion.list"));                                                              

Some functions:

void InsertProperity(const string & key, const string & value)
{
    shared_ptr<Connection> connection = GetConnection();
    unique_ptr<PreparedStatement> preStmt;
    string strSQL = "INSERT INTO properties (k, v) VALUES (?,?);";
    preStmt.reset(connection->prepareStatement(strSQL));
    preStmt->setString(1, key);
    preStmt->setString(2, value);
    preStmt->executeUpdate();
}

string GetProperty(const string & key)
{
    shared_ptr<Connection> connection = GetConnection();
    unique_ptr<PreparedStatement> preStmt;
    unique_ptr<ResultSet> rs;
    string strSQL = "SELECT v from properties WHERE k=?;";
    preStmt.reset(connection->prepareStatement(strSQL));
    preStmt->setString(1, key);
    rs.reset(preStmt->executeQuery());
    if (! rs->next())
    {
        return "";
    }
    return rs->getString("v");
}
[28 Feb 1:58] More More
I also tried to use getBlob(), while the result is the same
[28 Feb 2:15] More More
The table properties is as blow:

MariaDB [SAM]> show create table properties;
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| Table      | Create Table                                                                                                                                       |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| properties | CREATE TABLE `properties` (
  `k` mediumtext NOT NULL,
  `v` mediumtext NOT NULL,
  PRIMARY KEY (`k`(100))
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
[28 Feb 2:23] More More
For clarification, this test case is simpler.

Test result:

vault@sam30:~/More/Test$ ./sam-test -t database/archive
Running 1 test case...
/home/vault/More/SAM1.3/Test/DatabaseTest.cpp(69): fatal error: in "database/archive": critical check value == valueDb has failed [01234567890123456789012345678901234567890123456789012345678901234567890123456789 != 0123456789012345678901234567890123456789012345678901234567890123
= ?;?]

*** 1 failure is detected in the test module "Main"

Test code (it will fail always at line 69):

 63     string key = "abc";
 64     string value = "0123456789012345678901234567890123456789";
 65     value += "0123456789012345678901234567890123456789";
 66     InsertProperity(key, value);
 67     string valueDb = GetProperty(key);
 68     BOOST_REQUIRE_EQUAL(value.size(), valueDb.size());
 69     BOOST_REQUIRE_EQUAL(value, valueDb);
[28 Feb 2:34] More More
While I use mysql (client tool) to connect and I will find the database is correct:

MariaDB [SAM]> select * from properties where k='abc';
+-----+----------------------------------------------------------------------------------+
| k   | v                                                                                |
+-----+----------------------------------------------------------------------------------+
| abc | 01234567890123456789012345678901234567890123456789012345678901234567890123456789 |
+-----+----------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [SAM]>
[28 Feb 18:06] Sinisa Milivojevic
Hi,

Thank you for your bug report.

Since we are supporting MySQL server, can you please try to reproduce this problem with our 8.0 server and 8.0 Connector/C++.

Thanks in advance.
[1 Mar 3:27] More More
It is not easy for me to setup and test mysql 8.
While I built mysqlcppconn 1.1.12, and it seems this bug is resolved already.
[1 Mar 13:40] Sinisa Milivojevic
Hi,

Take your time.

We shall patiently wait for your MySQL 8.0 test case and results.
[2 Apr 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".