diff --git a/libmariadb/my_loaddata.c b/libmariadb/my_loaddata.c index 036ec983..fd279121 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/my_loaddata.c @@ -76,9 +76,9 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) if (info->fd < 0) { + info->error_no = my_errno; my_snprintf((char *)info->error_msg, sizeof(info->error_msg), - "Can't open file '%-.64s'.", filename); - info->error_no = EE_FILENOTFOUND; + EE(EE_FILENOTFOUND), filename, info->error_no); DBUG_RETURN(1); } DBUG_RETURN(0); @@ -136,11 +136,8 @@ void mysql_local_infile_end(void *ptr) if (info) { - if (info->fd) - { + if (info->fd >= 0) my_close(info->fd, MYF(0)); - info->fd= 0; - } my_free(ptr, MYF(0)); } DBUG_VOID_RETURN; diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index a3cbfed0..0de29c90 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -813,6 +813,31 @@ static int test_bug49694(MYSQL *mysql) return OK; } +static int test_ldi_path(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int)"); + check_mysql_rc(rc, mysql); + +#ifdef _WIN32 + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'X:/non_existing_path/data.csv' INTO TABLE t1 " + "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'"); +#else + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE '/non_existing_path/data.csv' INTO TABLE t1 " + "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'"); +#endif + FAIL_IF(rc== 0, "Error expected"); + FAIL_IF(mysql_errno(mysql) != 2, "Error code 2 expected"); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + struct my_tests_st my_tests[] = { {"test_bug28075", test_bug28075, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_bug28505", test_bug28505, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, @@ -827,6 +852,7 @@ struct my_tests_st my_tests[] = { {"test_wl4166_4", test_wl4166_4, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_wl4284_1", test_wl4284_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_bug49694", test_bug49694, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_ldi_path", test_ldi_path, TEST_CONNECTION_NEW, 0, NULL, NULL}, {NULL, NULL, 0, 0, NULL, 0} };