Float value error when using binary protocol in mysql-connector-c
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
1. Download [mysql-connector-c](https://downloads.mysql.com/archives/c-c/) (v6.1.11)
2. Build and Run the current master branch TiDB
3. Run the test case `test_bug4172` in mysql-connector-c with args: `-h 127.0.0.1 -P 4001 -u root`
### 2. What did you expect to see? (Required)
```
#####################################
125 of (1/1): test_bug4172
#####################################
Binary protocol: float=12345.123, double=123456.123456, decimal(10,4)=123456.1234
Text protocol: float=12345.123, double=123456.123456, decimal(10,4)=123456.1234
```
### 3. What did you see instead (Required)
```
#####################################
125 of (1/1): test_bug4172
#####################################
Binary protocol: float=12345.1, double=123456.123456, decimal(10,4)=123456.1234
Text protocol: float=12345.123, double=123456.123456, decimal(10,4)=123456.1234
/Users/cheese/Src/CSrc/mysql-connector-c-6.1.11-src/testclients/mysql_client_test.c:12537: check failed: '!strcmp(f, row[0]) && !strcmp(d, row[1]) && !strcmp(e, row[2])'
```
### 4. What is your TiDB version? (Required)
Master branch code.
```sql
+------------------+
| VERSION() |
+------------------+
| 5.7.25-TiDB-None |
+------------------+
```
### 5. The last part TiDB log
```
[2022/07/19 14:00:03.654 +08:00] [INFO] [session.go:3148] ["CRUCIAL OPERATION"] [conn=2199023256479] [schemaVersion=15402] [cur_db=client_test_db] [sql="DROP TABLE IF EXISTS t1"] [user=root@%]
[2022/07/19 14:00:03.654 +08:00] [INFO] [session.go:3148] ["CRUCIAL OPERATION"] [conn=2199023256479] [schemaVersion=15402] [cur_db=client_test_db] [sql="CREATE TABLE t1 (f float, d double, e decimal(10,4))"] [user=root@%]
[2022/07/19 14:00:03.654 +08:00] [INFO] [ddl_worker.go:332] ["[ddl] add DDL jobs"] ["batch count"=1] [jobs="ID:11590, Type:create table, State:queueing, SchemaState:none, SchemaID:69, TableID:11589, RowCount:0, ArgLen:1, start time: 2022-07-19 14:00:03.654 +0800 CST, Err:, ErrCount:0, SnapshotVersion:0; "]
[2022/07/19 14:00:03.654 +08:00] [INFO] [ddl.go:765] ["[ddl] start DDL job"] [job="ID:11590, Type:create table, State:queueing, SchemaState:none, SchemaID:69, TableID:11589, RowCount:0, ArgLen:1, start time: 2022-07-19 14:00:03.654 +0800 CST, Err:, ErrCount:0, SnapshotVersion:0"] [query="CREATE TABLE t1 (f float, d double, e decimal(10,4))"]
[2022/07/19 14:00:03.654 +08:00] [INFO] [ddl_worker.go:881] ["[ddl] run DDL job"] [worker="worker 3, tp general"] [job="ID:11590, Type:create table, State:queueing, SchemaState:none, SchemaID:69, TableID:11589, RowCount:0, ArgLen:0, start time: 2022-07-19 14:00:03.654 +0800 CST, Err:, ErrCount:0, SnapshotVersion:0"]
[2022/07/19 14:00:03.654 +08:00] [INFO] [delete_range.go:245] ["[ddl] delRange emulator complete task"] [jobID=11588] [elementID=1] [startKey=748000000000002d42] [endKey=748000000000002d43]
[2022/07/19 14:00:03.654 +08:00] [INFO] [ddl_worker.go:512] ["[ddl] finish DDL job"] [worker="worker 3, tp general"] [job="ID:11590, Type:create table, State:synced, SchemaState:public, SchemaID:69, TableID:11589, RowCount:0, ArgLen:0, start time: 2022-07-19 14:00:03.654 +0800 CST, Err:, ErrCount:0, SnapshotVersion:0"]
[2022/07/19 14:00:03.654 +08:00] [INFO] [ddl.go:852] ["[ddl] DDL job is finished"] [jobID=11590]
[2022/07/19 14:00:03.654 +08:00] [INFO] [callback.go:107] ["performing DDL change, must reload"]
[2022/07/19 14:00:03.654 +08:00] [INFO] [split_region.go:85] ["split batch regions request"] ["split key count"=1] ["batch count"=1] ["first batch, region ID"=7726] ["first split key"=748000000000002d45]
[2022/07/19 14:00:03.654 +08:00] [INFO] [domain.go:153] ["diff load InfoSchema success"] [currentSchemaVersion=15402] [neededSchemaVersion=15403] ["start time"=47.542µs] [phyTblIDs="[11589]"] [actionTypes="[8]"]
[2022/07/19 14:00:03.654 +08:00] [INFO] [schema_validator.go:293] ["the schema validator enqueue, queue is too long"] ["delta max count"=1024] ["remove schema version"=13341]
[2022/07/19 14:00:03.654 +08:00] [INFO] [split_region.go:187] ["batch split regions complete"] ["batch region ID"=7726] ["first at"=748000000000002d45] ["first new region left"="{Id:7726 StartKey:748000000000002dff4200000000000000f8 EndKey:748000000000002dff4500000000000000f8 RegionEpoch:{ConfVer:1 Version:2} Peers:[id:7727 store_id:1 ] EncryptionMeta:}"] ["new region count"=1]
[2022/07/19 14:00:03.654 +08:00] [INFO] [split_region.go:236] ["split regions complete"] ["region count"=1] ["region IDs"="[7726]"]
[2022/07/19 14:00:03.655 +08:00] [WARN] [2pc.go:1808] ["schemaLeaseChecker is not set for this transaction"] [sessionID=2199023256479] [startTS=434689908055736321] [checkTS=434689908055736322]
```
### 6. `test_bug4172` Code
```c
static void test_bug4172()
{
MYSQL_STMT *stmt;
MYSQL_BIND my_bind[3];
const char *stmt_text;
MYSQL_RES *res;
MYSQL_ROW row;
int rc;
char f[100], d[100], e[100];
ulong f_len, d_len, e_len;
myheader("test_bug4172");
mysql_query(mysql, "DROP TABLE IF EXISTS t1");
mysql_query(mysql, "CREATE TABLE t1 (f float, d double, e decimal(10,4))");
mysql_query(mysql, "INSERT INTO t1 VALUES (12345.1234, 123456.123456, "
"123456.1234)");
stmt= mysql_stmt_init(mysql);
stmt_text= "SELECT f, d, e FROM t1";
rc= mysql_stmt_prepare(stmt, stmt_text, (ulong)strlen(stmt_text));
check_execute(stmt, rc);
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
memset(my_bind, 0, sizeof(my_bind));
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
my_bind[0].buffer= f;
my_bind[0].buffer_length= (ulong)sizeof(f);
my_bind[0].length= &f_len;
my_bind[1].buffer_type= MYSQL_TYPE_STRING;
my_bind[1].buffer= d;
my_bind[1].buffer_length= (ulong)sizeof(d);
my_bind[1].length= &d_len;
my_bind[2].buffer_type= MYSQL_TYPE_STRING;
my_bind[2].buffer= e;
my_bind[2].buffer_length= (ulong)sizeof(e);
my_bind[2].length= &e_len;
mysql_stmt_bind_result(stmt, my_bind);
mysql_stmt_store_result(stmt);
rc= mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
rc= mysql_real_query(mysql, stmt_text, (ulong)strlen(stmt_text));
myquery(rc);
res= mysql_store_result(mysql);
row= mysql_fetch_row(res);
if (!opt_silent)
{
printf("Binary protocol: float=%s, double=%s, decimal(10,4)=%s\n",
f, d, e);
printf("Text protocol: float=%s, double=%s, decimal(10,4)=%s\n",
row[0], row[1], row[2]);
}
DIE_UNLESS(!strcmp(f, row[0]) && !strcmp(d, row[1]) && !strcmp(e, row[2]));
mysql_free_result(res);
mysql_stmt_close(stmt);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.