Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据库表字段使用smallInt情况下返回的数据出错 #3175

Closed
TommyZC opened this issue Mar 10, 2022 · 4 comments
Closed

数据库表字段使用smallInt情况下返回的数据出错 #3175

TommyZC opened this issue Mar 10, 2022 · 4 comments
Assignees
Labels
community issue from community
Milestone

Comments

@TommyZC
Copy link

TommyZC commented Mar 10, 2022

  • dble version:2.19.03\lts and later
  • **preconditions :
CREATE TABLE `test3` (
  `id` int(10) NOT NULL,
  `userid` smallint(3) DEFAULT NULL,
  `name` char(5) DEFAULT NULL,
  `nn` year(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB

insert into test3 values('1','105','name',2022),('2','105','name2',2023);
  • configs:
    none

  • steps:

        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:8066/test?
useServerPrepStmts=true", "root", "123456");

        PreparedStatement stmt = conn.prepareStatement("select id,userid,nn from test3 where id=?");
        stmt.setInt(1, 1);

        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getString(1));
            System.out.println(rs.getShort(2));
            System.out.println(rs.getShort(3));
        }
  • expect result:
1
105
2022
  • real result:
1
12337
12338
  • supplements:
    1. 目前定位到问题在com.actiontech.dble.net.mysql.BinaryRowDataPacket.java中的read()函数,从rowDataPk中获取到的values值是49和50,在convert中按getShort()方法对byte数组(长度为1)做按位与操作得到的结果也是49和50,最终返回结果是49和50
@yanhuqing666 yanhuqing666 added the community issue from community label Mar 10, 2022
@yanhuqing666
Copy link
Member

You need to use 105 not '105' to avoid. It is a number but not a string.
And we will try to reproduce and fix

@TommyZC
Copy link
Author

TommyZC commented Mar 11, 2022

这是分析的最新进展:

  1. 修改com.actiontech.dble.util.ByteUtil.java中的getShort()方法,当byte数组长度为1时,使用parseShort()方法对byte数组做转换,发现返回的结果是正确的,判断是getShort()方法中对长度为1的byte数组的解析有误。
  2. 当数据库的表字段是smallInt unsigned情况下,存在返回的byte数组长度大于2的情况,在getShort()方法中没有实现,因此返回数据错误。

@TommyZC
Copy link
Author

TommyZC commented Mar 11, 2022

尝试了一下,使用insert into test6 values(4,105,'name4');插入数据,返回结果还是出错

yanhuqing666 added a commit that referenced this issue Mar 11, 2022
yanhuqing666 added a commit that referenced this issue Mar 11, 2022
…rotocol (#3181)

* #3175 - short value of row data protocol fails to convert to  binary protocol

* 

Co-authored-by: Huqing Yan <yanhuqing666@gmail.com>
@yanhuqing666 yanhuqing666 added this to the 3.22.01.0 milestone Mar 17, 2022
@jndxcaiwei
Copy link
Member

Verified version:5.7.21-dble-9.9.9.9-3d3612c9b31c2798b782b07066bc4615253920d4-20220321060316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community issue from community
Projects
None yet
Development

No branches or pull requests

4 participants