question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mysql page limit Long parameter type error

See original GitHub issue

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

4.0.0-RC2-SNAPSHOT(clone from dev branch)

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

sql execute success

Actual behavior

Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

Reason analyze (If you can)

my code below: public List<User> findUsersByPageIntType(Integer begin, Integer end){ String sql = "select id,name,age,email from user limit ?,? "; Object[] params = new Object[] {begin, end}; List<User> userList = jdbcTemplate.query(sql, params, getUserMapper()); return userList; } public List<User> findUsersByPageLongType(Long begin, Long end){ String sql = "select id,name,age,email from user limit ?,? "; Object[] params = new Object[] {begin, end}; List<User> userList = jdbcTemplate.query(sql, params, getUserMapper()); return userList; }

first, call findUsersByPageIntType method, it’s ok but call findUsersByPageLongType method there was an error -> Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

1.application.properties spring.shardingsphere.datasource.names=ds0 spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://127.0.0.1:3306/ttx_util?useUnicode=true&useSSL=false&characterEncoding=utf8 spring.shardingsphere.datasource.ds0.username=test spring.shardingsphere.datasource.ds0.password=test

spring.shardingsphere.sharding.tables.user.actual-data-nodes=ds0.user_$->{0…1} spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=erp_id spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=user_$->{erp_id % 2} spring.shardingsphere.sharding.tables.user.key-generator.column=id spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE #是否开启SQL显示,默认值: false spring.shardingsphere.props.sql.show=true 2.table create sql: CREATE TABLE user_0 ( id bigint(20) NOT NULL COMMENT ‘主键ID’, erp_id int(11) NOT NULL COMMENT ‘分表erpId’, name varchar(30) DEFAULT NULL COMMENT ‘姓名’, age int(11) DEFAULT NULL COMMENT ‘年龄’, email varchar(50) DEFAULT NULL COMMENT ‘邮箱’, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE user_1 ( id bigint(20) NOT NULL COMMENT ‘主键ID’, erp_id int(11) NOT NULL COMMENT ‘分表erpId’, name varchar(30) DEFAULT NULL COMMENT ‘姓名’, age int(11) DEFAULT NULL COMMENT ‘年龄’, email varchar(50) DEFAULT NULL COMMENT ‘邮箱’, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Example codes for reproduce this issue (such as a github link).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
KomachiSioncommented, Sep 3, 2019

I test in mysql 5.7.21, offset and row count of limit can be over INTEGER.MAX.

sql> select * from t_order limit 0, 9999999999
[2019-09-03 09:21:48] 5 rows retrieved starting from 1 in 28ms (execution: 17ms, fetching: 11ms)
sql> select * from t_order limit 9999999999, 9999999999
[2019-09-03 09:22:27] 0 rows retrieved in 37ms (execution: 21ms, fetching: 16ms)

So, I think Pagination in ShardingSphere should use type Long instead of Integer for offset and row count to solve this exception.

0reactions
sunbufucommented, Sep 19, 2019

Yes, you can clone dev branch and try with 4.0.0-RC3-SNAPSHOT again. And the new version is coming, please just wait.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SP does not accept variables in LIMIT clause - MySQL Bugs
SPs don't accept variables in the LIMIT clause. If such a SP is created, the error message ERROR 1064 (42000): You have an...
Read more >
Row size too large error in mysql create table query
The total size of all fields in the table is more than the limit, 65535, that's why you are getting this error. You...
Read more >
Known issues and limitations for Amazon RDS for MySQL
Learn about known issues and limitations for working with Amazon RDS for MySQL.
Read more >
Server System Variables - MariaDB Knowledge Base
The full list of server variables are listed in the contents on this page, ... connection to MySQL server at 'X', system error:...
Read more >
MySQL LIMIT & OFFSET with Examples - Guru99
The limit keyword is used to limit the number of rows returned in a query result. It can be used in conjunction with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found