From 8fdcf73109e81e3487e3e385cf44c9c15ff852fb Mon Sep 17 00:00:00 2001 From: "kaiwang.ckw" Date: Fri, 7 May 2021 15:12:58 +0800 Subject: [PATCH 1/2] regression tests: fix connection options for external MySQL servers --- tests/include/api_sql_common.sh | 4 +--- tests/include/mysql_common.sh | 18 +++++++++++++++++- tests/include/pgsql_common.sh | 2 ++ tests/t/api_sql_mysql.t | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/include/api_sql_common.sh b/tests/include/api_sql_common.sh index aefb1b591..903c4968e 100644 --- a/tests/include/api_sql_common.sh +++ b/tests/include/api_sql_common.sh @@ -156,9 +156,7 @@ end EOF # Reset --mysql-socket if it's specified on the command line, otherwise sysbench # will assume --mysql-host=localhost -sysbench $SB_ARGS --mysql-host="non-existing" --pgsql-host="non-existing" \ - --mysql-socket= \ - run +sysbench $SB_ARGS $DB_NON_EXISTING run # Error hooks cat >$CRAMTMP/api_sql.lua < Date: Fri, 7 May 2021 17:19:40 +0800 Subject: [PATCH 2/2] Fix client prepare with string parameter. --- src/db_driver.c | 13 +++++++++++- tests/include/api_sql_common.sh | 37 +++++++++++++++++++++++++++++++++ tests/t/api_sql_mysql.t | 8 +++++++ tests/t/api_sql_pgsql.t | 8 +++++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/db_driver.c b/src/db_driver.c index 97310a66f..658e7d18b 100644 --- a/src/db_driver.c +++ b/src/db_driver.c @@ -852,6 +852,8 @@ int db_parse_arguments(void) int db_print_value(db_bind_t *var, char *buf, int buflen) { int n; + char *p; + char *end; db_time_t *tm; if (var->is_null != NULL && *var->is_null) @@ -881,7 +883,16 @@ int db_print_value(db_bind_t *var, char *buf, int buflen) break; case DB_TYPE_CHAR: case DB_TYPE_VARCHAR: - n = snprintf(buf, buflen, "'%s'", (char *)var->buffer); + if (buflen < (int)var->max_len + 3) + return -1; + n = 0; + p = (char *)var->buffer; + end = p + var->max_len; + buf[n++] = '\''; + while (*p && p < end) + buf[n++] = *p++; + buf[n++] = '\''; + buf[n] = '\0'; break; case DB_TYPE_DATE: tm = (db_time_t *)var->buffer; diff --git a/tests/include/api_sql_common.sh b/tests/include/api_sql_common.sh index 903c4968e..6fb5d199e 100644 --- a/tests/include/api_sql_common.sh +++ b/tests/include/api_sql_common.sh @@ -272,3 +272,40 @@ end EOF sysbench $SB_ARGS + +cat <$CRAMTMP/api_sql.lua <