You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Fix for CONC-525: Support LOAD * LOCAL INFILE statements in binary protocol
With implementation of MDEV-16708 (support all commands in binary protocol) we need to check for local infile in text and binary protocol. Therefore the local infile relevant part from ma_simple_command was moved to mthd_my_send_cmd method.
This commit is contained in:
@@ -388,6 +388,18 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg,
|
|||||||
|
|
||||||
CLEAR_CLIENT_ERROR(mysql);
|
CLEAR_CLIENT_ERROR(mysql);
|
||||||
|
|
||||||
|
if (command == COM_QUERY ||
|
||||||
|
command == COM_STMT_PREPARE)
|
||||||
|
{
|
||||||
|
if ((mysql->options.client_flag & CLIENT_LOCAL_FILES) &&
|
||||||
|
mysql->options.extension && mysql->extension->auto_local_infile == WAIT_FOR_QUERY &&
|
||||||
|
arg && (*arg == 'l' || *arg == 'L'))
|
||||||
|
{
|
||||||
|
if (strncasecmp(arg, "load", 4) == 0)
|
||||||
|
mysql->extension->auto_local_infile= ACCEPT_FILE_REQUEST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mysql->info=0;
|
mysql->info=0;
|
||||||
mysql->affected_rows= ~(unsigned long long) 0;
|
mysql->affected_rows= ~(unsigned long long) 0;
|
||||||
ma_net_clear(net); /* Clear receive buffer */
|
ma_net_clear(net); /* Clear receive buffer */
|
||||||
@@ -435,14 +447,6 @@ int
|
|||||||
ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
|
ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
|
||||||
size_t length, my_bool skipp_check, void *opt_arg)
|
size_t length, my_bool skipp_check, void *opt_arg)
|
||||||
{
|
{
|
||||||
if ((mysql->options.client_flag & CLIENT_LOCAL_FILES) &&
|
|
||||||
mysql->options.extension && mysql->extension->auto_local_infile == WAIT_FOR_QUERY &&
|
|
||||||
arg && (*arg == 'l' || *arg == 'L') &&
|
|
||||||
command == COM_QUERY)
|
|
||||||
{
|
|
||||||
if (strncasecmp(arg, "load", 4) == 0)
|
|
||||||
mysql->extension->auto_local_infile= ACCEPT_FILE_REQUEST;
|
|
||||||
}
|
|
||||||
return mysql->methods->db_command(mysql, command, arg, length, skipp_check, opt_arg);
|
return mysql->methods->db_command(mysql, command, arg, length, skipp_check, opt_arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5316,7 +5316,72 @@ static int test_conc512(MYSQL *mysql)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_conc525(MYSQL *mysql)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
MYSQL_STMT *stmt;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "create temporary table t1 (a blob)");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
/* create a dummy import file */
|
||||||
|
if (!(fp= fopen("./test.csv", "w")))
|
||||||
|
{
|
||||||
|
diag("couldn't create file './test.csv'");
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
fprintf(fp, "1\n2\n");
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
/* Test: prepare and execute
|
||||||
|
should fail due to non existing file */
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
|
||||||
|
rc= mysql_stmt_prepare(stmt, SL("LOAD DATA LOCAL INFILE './test.notexist' INTO table t1"));
|
||||||
|
|
||||||
|
if (rc && mysql_stmt_errno(stmt) == ER_UNSUPPORTED_PS)
|
||||||
|
{
|
||||||
|
diag("Server doesn't support LOAD LOCAL INFILE in binary protocol.");
|
||||||
|
return SKIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
FAIL_IF(!rc, "Error expected (file does not exist)");
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
/* Test: prepare and execute
|
||||||
|
2 rows should be inserted */
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
|
||||||
|
rc= mysql_stmt_prepare(stmt, SL("LOAD DATA LOCAL INFILE './test.csv' INTO table t1"));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
FAIL_IF(mysql_stmt_affected_rows(stmt) != 2, "Expected 2 inserted rows");
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
|
||||||
|
/* Test: execute_direct
|
||||||
|
2 rows should be inserted */
|
||||||
|
rc= mariadb_stmt_execute_direct(stmt, SL("LOAD DATA LOCAL INFILE './test.csv' INTO table t1"));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
FAIL_IF(mysql_stmt_affected_rows(stmt) != 2, "Expected 2 inserted rows");
|
||||||
|
|
||||||
|
/* Cleanup */
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
unlink("./test.csv");
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
struct my_tests_st my_tests[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
|
{"test_conc525", test_conc525, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc512", test_conc512, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc512", test_conc512, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc504", test_conc504, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc504", test_conc504, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_returning", test_returning, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_returning", test_returning, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
|
Reference in New Issue
Block a user