yanyanqing / learngit

Other
0 stars 0 forks source link

for title #227

Closed yanyanqing closed 6 years ago

yanyanqing commented 6 years ago
  1. What did you do?

When I use Server Prepared Statements, that is set useServerPrepStmts=true, if the select statement's field list contains the Enum type, the client will report an error.

CREATE TABLE shirts (
    name VARCHAR(40),
    size ENUM('small', 'medium', 'large')
);

INSERT INTO shirts (name, size) VALUES ('dress shirt','large'), ('t-shirt','medium'),('polo shirt','small');

mysql> desc shirts;
+-------+--------------------------------+------+------+---------+-------+
| Field | Type                           | Null | Key  | Default | Extra |
+-------+--------------------------------+------+------+---------+-------+
| name  | varchar(40)                    | YES  |      | NULL    |       |
| size  | enum('small','medium','large') | YES  |      | NULL    |       |
+-------+--------------------------------+------+------+---------+-------+

Java Code snippet:

    String DB_URL = "jdbc:mysql://xxx.xxx.xxxx.xxx:4000/test";
    Properties info = new Properties();
    info.setProperty("user", "root");
    info.setProperty("password", "");
    info.setProperty("useServerPrepStmts", "true");
    Connection conn = DriverManager.getConnection(DB_URL, info);

    String sql = "SELECT name, size FROM shirts WHERE name = ?";

    PreparedStatement preparedStatement = conn.prepareStatement(sql);
    preparedStatement.setString(1, "t-shirt");
    ResultSet resultSet = preparedStatement.executeQuery();

    while (resultSet.next()) {
        String name = resultSet.getString("name");
        String size = resultSet.getString("size");
        System.out.println(name + ", " + size );
    }

MySQL Connector/J version:

<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>6.0.6</version>
</dependency>
  1. What did you expect to see?

I expect the TiDB to return the correct query result.

  1. What did you see instead?

The client reported the following error message:

Exception in thread "main" java.sql.SQLException: Unknown type '247' in column '1' of '2' in binary-encoded result set.
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115)
    at com.mysql.cj.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1299)
    at com.mysql.cj.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:701)
    at com.mysql.cj.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1923)
    at com.apusic.test.CursorExample.main(CursorExample.java:27)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

----------------------------------------------------------------------------------------------------------------+ | Release Version: v2.1.0-alpha-75-g41f8ac195 Git Commit Hash: 41f8ac19523386d0eb6ca871397f49f834958169 Git Branch: master UTC Build Time: 2018-06-26 07:08:04 GoVersion: go version go1.10.1 darwin/amd64 Race Enabled: false TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e | +------------------------------------------------------------------------------------

yanyanqing commented 6 years ago

teststt ``

1111

222

dsafsdfsd
yanyanqing commented 6 years ago

teststt ``

1111

222

dsafsdfsd