[regression-test](prepared statement) Fix connection error when test framework used lower jdbc version (#18665)
This commit is contained in:
@ -212,6 +212,12 @@ public class ConnectProcessor {
|
||||
packetBuf.getInt();
|
||||
LOG.debug("execute prepared statement {}", stmtId);
|
||||
PrepareStmtContext prepareCtx = ctx.getPreparedStmt(String.valueOf(stmtId));
|
||||
if (prepareCtx == null) {
|
||||
LOG.debug("No such statement in context, stmtId:{}", stmtId);
|
||||
ctx.getState().setError(ErrorCode.ERR_UNKNOWN_COM_ERROR,
|
||||
"msg: Not supported such prepared statement");
|
||||
return;
|
||||
}
|
||||
int paramCount = prepareCtx.stmt.getParmCount();
|
||||
// null bitmap
|
||||
byte[] nullbitmapData = new byte[(paramCount + 7) / 8];
|
||||
|
||||
@ -19,7 +19,10 @@ import org.codehaus.groovy.runtime.IOGroovyMethods
|
||||
|
||||
|
||||
suite("test_compaction_uniq_keys_row_store") {
|
||||
def tableName = "compaction_uniq_keys_row_store_regression_test"
|
||||
def realDb = "regression_test_serving_p0"
|
||||
def tableName = realDb + ".compaction_uniq_keys_row_store_regression_test"
|
||||
sql "CREATE DATABASE IF NOT EXISTS ${realDb}"
|
||||
|
||||
def setPrepareStmtArgs = {stmt, user_id, date, datev2, datetimev2_1, datetimev2_2, city, age, sex ->
|
||||
java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
|
||||
stmt.setInt(1, user_id)
|
||||
@ -73,7 +76,20 @@ suite("test_compaction_uniq_keys_row_store") {
|
||||
def checkValue = { ->
|
||||
def user = context.config.jdbcUser
|
||||
def password = context.config.jdbcPassword
|
||||
def url = context.config.jdbcUrl + "&useServerPrepStmts=true"
|
||||
// Parse url
|
||||
String jdbcUrl = context.config.jdbcUrl
|
||||
String urlWithoutSchema = jdbcUrl.substring(jdbcUrl.indexOf("://") + 3)
|
||||
def sql_ip = urlWithoutSchema.substring(0, urlWithoutSchema.indexOf(":"))
|
||||
def sql_port
|
||||
if (urlWithoutSchema.indexOf("/") >= 0) {
|
||||
// e.g: jdbc:mysql://locahost:8080/?a=b
|
||||
sql_port = urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 1, urlWithoutSchema.indexOf("/"))
|
||||
} else {
|
||||
// e.g: jdbc:mysql://locahost:8080
|
||||
sql_port = urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 1)
|
||||
}
|
||||
// set server side prepared statment url
|
||||
def url="jdbc:mysql://" + sql_ip + ":" + sql_port + "/" + realDb + "?&useServerPrepStmts=true"
|
||||
def result1 = connect(user=user, password=password, url=url) {
|
||||
def stmt = prepareStatement """ SELECT * FROM ${tableName} t where user_id = ? and date = ? and datev2 = ? and datetimev2_1 = ? and datetimev2_2 = ? and city = ? and age = ? and sex = ?; """
|
||||
setPrepareStmtArgs stmt, 1, '2017-10-01', '2017-10-01', '2017-10-01 11:11:11.21', '2017-10-01 11:11:11.11', 'Beijing', 10, 1
|
||||
@ -97,10 +113,7 @@ suite("test_compaction_uniq_keys_row_store") {
|
||||
|
||||
def user = context.config.jdbcUser
|
||||
def password = context.config.jdbcPassword
|
||||
def url = context.config.jdbcUrl + "&useServerPrepStmts=true"
|
||||
def tablets = null
|
||||
def result1 = connect(user=user, password=password, url=url) {
|
||||
|
||||
sql """ DROP TABLE IF EXISTS ${tableName} """
|
||||
sql """
|
||||
CREATE TABLE IF NOT EXISTS ${tableName} (
|
||||
@ -157,11 +170,9 @@ suite("test_compaction_uniq_keys_row_store") {
|
||||
"""
|
||||
//TabletId,ReplicaIdBackendId,SchemaHash,Version,LstSuccessVersion,LstFailedVersion,LstFailedTime,LocalDataSize,RemoteDataSize,RowCount,State,LstConsistencyCheckTime,CheckVersion,VersionCount,PathHash,MetaUrl,CompactionStatus
|
||||
tablets = sql """ show tablets from ${tableName}; """
|
||||
}
|
||||
|
||||
checkValue()
|
||||
|
||||
|
||||
// trigger compactions for all tablets in ${tableName}
|
||||
for (String[] tablet in tablets) {
|
||||
String tablet_id = tablet[0]
|
||||
|
||||
@ -18,10 +18,26 @@
|
||||
import java.math.BigDecimal;
|
||||
|
||||
suite("test_point_query") {
|
||||
def tableName = "tbl_point_query"
|
||||
def user = context.config.jdbcUser
|
||||
def password = context.config.jdbcPassword
|
||||
def url = context.config.jdbcUrl + "&useServerPrepStmts=true"
|
||||
def realDb = "regression_test_serving_p0"
|
||||
def tableName = realDb + ".tbl_point_query"
|
||||
sql "CREATE DATABASE IF NOT EXISTS ${realDb}"
|
||||
|
||||
// Parse url
|
||||
String jdbcUrl = context.config.jdbcUrl
|
||||
String urlWithoutSchema = jdbcUrl.substring(jdbcUrl.indexOf("://") + 3)
|
||||
def sql_ip = urlWithoutSchema.substring(0, urlWithoutSchema.indexOf(":"))
|
||||
def sql_port
|
||||
if (urlWithoutSchema.indexOf("/") >= 0) {
|
||||
// e.g: jdbc:mysql://locahost:8080/?a=b
|
||||
sql_port = urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 1, urlWithoutSchema.indexOf("/"))
|
||||
} else {
|
||||
// e.g: jdbc:mysql://locahost:8080
|
||||
sql_port = urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 1)
|
||||
}
|
||||
// set server side prepared statment url
|
||||
def url="jdbc:mysql://" + sql_ip + ":" + sql_port + "/" + realDb + "?&useServerPrepStmts=true"
|
||||
|
||||
def generateString = {len ->
|
||||
def str = ""
|
||||
@ -31,8 +47,6 @@ suite("test_point_query") {
|
||||
return str
|
||||
}
|
||||
|
||||
// def url = context.config.jdbcUrl
|
||||
def result1 = connect(user=user, password=password, url=url) {
|
||||
sql """DROP TABLE IF EXISTS ${tableName}"""
|
||||
test {
|
||||
// abnormal case
|
||||
@ -82,6 +96,14 @@ suite("test_point_query") {
|
||||
sql """ INSERT INTO ${tableName} VALUES(252, 120939.11130, "${generateString(252)}", "laooq", "2030-01-02", "2020-01-01 12:36:38", 252, "7022-01-01 11:30:38") """
|
||||
sql """ INSERT INTO ${tableName} VALUES(298, 120939.11130, "${generateString(298)}", "laooq", "2030-01-02", "2020-01-01 12:36:38", 298, "7022-01-01 11:30:38") """
|
||||
|
||||
def nprep_sql = {sql_str->
|
||||
def url_without_prep ="jdbc:mysql://" + sql_ip + ":" + sql_port + "/" + realDb
|
||||
connect(user=user, password=password, url=url_without_prep) {
|
||||
sql sql_str
|
||||
}
|
||||
}
|
||||
// def url = context.config.jdbcUrl
|
||||
def result1 = connect(user=user, password=password, url=url) {
|
||||
def stmt = prepareStatement "select * from ${tableName} where k1 = ? and k2 = ? and k3 = ?"
|
||||
assertEquals(stmt.class, com.mysql.cj.jdbc.ServerPreparedStatement);
|
||||
stmt.setInt(1, 1231)
|
||||
@ -125,26 +147,26 @@ suite("test_point_query") {
|
||||
qe_point_select stmt_fn
|
||||
qe_point_select stmt_fn
|
||||
|
||||
sql """
|
||||
nprep_sql """
|
||||
ALTER table ${tableName} ADD COLUMN new_column0 INT default "0";
|
||||
"""
|
||||
sleep(1);
|
||||
sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a ddd", "laooq", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 11:30:38", 123) """
|
||||
nprep_sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a ddd", "laooq", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 11:30:38", 123) """
|
||||
stmt.setBigDecimal(1, new BigDecimal("120939.11130"))
|
||||
stmt.setString(2, "a ddd")
|
||||
qe_point_select stmt
|
||||
qe_point_select stmt
|
||||
// invalidate cache
|
||||
sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a ddd", "xxxxxx", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 11:30:38", 123) """
|
||||
nprep_sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a ddd", "xxxxxx", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 11:30:38", 123) """
|
||||
qe_point_select stmt
|
||||
qe_point_select stmt
|
||||
qe_point_select stmt
|
||||
sql """
|
||||
nprep_sql """
|
||||
ALTER table ${tableName} ADD COLUMN new_column1 INT default "0";
|
||||
"""
|
||||
qe_point_select stmt
|
||||
qe_point_select stmt
|
||||
sql """
|
||||
nprep_sql """
|
||||
ALTER table ${tableName} DROP COLUMN new_column1;
|
||||
"""
|
||||
qe_point_select stmt
|
||||
|
||||
Reference in New Issue
Block a user