From aacffe62d64a36d876fbee0e1ce30e9f16bff100 Mon Sep 17 00:00:00 2001 From: "holzboote@googlemail.com" <> Date: Wed, 4 Sep 2013 18:45:54 +0200 Subject: [PATCH] Fix for conc-49: local_infile_init didn't open files with binary flag --- libmariadb/my_loaddata.c | 4 ++-- unittest/libmariadb/misc.c | 21 +++++++++++++++++++++ unittest/libmariadb/sample.csv | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 unittest/libmariadb/sample.csv diff --git a/libmariadb/my_loaddata.c b/libmariadb/my_loaddata.c index 38b5b47e..9174c8b0 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/my_loaddata.c @@ -88,7 +88,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) if (CodePage == -1) { #ifdef _WIN32 - info->fd= sopen(info->filename, _O_RDONLY, _SH_DENYNO , _S_IREAD | _S_IWRITE); + info->fd= sopen(info->filename, _O_RDONLY | _O_BINARY, _SH_DENYNO , _S_IREAD | _S_IWRITE); #else info->fd = open(info->filename, O_RDONLY | O_BINARY, my_umask); #endif @@ -116,7 +116,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) "Character conversion error: %d", GetLastError()); DBUG_RETURN(1); } - info->fd= _wsopen(w_filename, _O_RDONLY, _SH_DENYNO , _S_IREAD | _S_IWRITE); + info->fd= _wsopen(w_filename, _O_RDONLY | _O_BINARY, _SH_DENYNO , _S_IREAD | _S_IWRITE); my_errno= errno; my_free((gptr)w_filename, MYF(0)); } diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index 5fbc3d87..71a0a11e 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -813,6 +813,26 @@ static int test_bug49694(MYSQL *mysql) return OK; } +static int test_conc49(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc49"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE conc49 (a int, b int, c int) Engine=InnoDB DEFAULT CHARSET=latin1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE './sample.csv' INTO TABLE conc49 FIELDS ESCAPED BY ' ' TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n'"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT a FROM conc49"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 3, "3 rows expected"); + return OK; +} + static int test_ldi_path(MYSQL *mysql) { int rc; @@ -885,6 +905,7 @@ static int test_conc44(MYSQL *mysql) #endif struct my_tests_st my_tests[] = { + {"test_conc49", test_conc49, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_bug28075", test_bug28075, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_bug28505", test_bug28505, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_debug_example", test_debug_example, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, diff --git a/unittest/libmariadb/sample.csv b/unittest/libmariadb/sample.csv new file mode 100644 index 00000000..7606df1b --- /dev/null +++ b/unittest/libmariadb/sample.csv @@ -0,0 +1,3 @@ +"1","1","1" +"2","2","2" +"3","3","3"