diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index 7c7fc9f3..c0582862 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -388,6 +388,18 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, 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->affected_rows= ~(unsigned long long) 0; 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, 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); } diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index aafb507f..d4bc1aa9 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -5316,7 +5316,72 @@ static int test_conc512(MYSQL *mysql) 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[] = { + {"test_conc525", test_conc525, 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_returning", test_returning, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},