Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(tests): Add more things to test in LOAD DATA INFILE tests #1438

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/fixtures/data.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1,Hello World
2,This is a test
3,For loading data from a file
4,中文内容
1,Hello World,123.456,test1,test5,2016-06-07T10:56:14,2016-06-07T10:56:14
2,This is a test,789.012,test2,test6,2016-06-07T10:56:14,2016-06-07T10:56:14
3,For loading data from a file,345.678,test3,test7,2016-06-07T10:56:14,2016-06-07T10:56:14
4,中文内容,901.234,test4,test8,2016-06-07T10:56:14,2016-06-07T10:56:14
20 changes: 19 additions & 1 deletion test/integration/connection/test-load-data-infile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ common.getTestConnection(function (err, connection) {
'CREATE TEMPORARY TABLE ?? (',
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`title` varchar(255),',
'`num` varchar(255),',
'`test_col_1` varchar(255) DEFAULT NULL,',
'`test_col_2` varchar(255) NOT NULL,',
'`test_col_3` datetime NOT NULL,',
'`test_col_4` datetime NOT NULL,',
'PRIMARY KEY (`id`)',
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
].join('\n'), [table], assert.ifError);

var sql =
'LOAD DATA LOCAL INFILE ? INTO TABLE ?? CHARACTER SET utf8 ' +
'FIELDS TERMINATED BY ? (id, title)';
'FIELDS TERMINATED BY ? (id, title, num, test_col_1, test_col_2, test_col_3, test_col_4)';

connection.query(sql, [path, table, ','], function (err, result) {
assert.ifError(err);
Expand All @@ -33,8 +38,21 @@ common.getTestConnection(function (err, connection) {
assert.equal(rows.length, 4);
assert.equal(rows[0].id, 1);
assert.equal(rows[0].title, 'Hello World');
assert.equal(rows[0].num, 123.456);
assert.equal(rows[0].test_col_1, 'test1');
assert.equal(rows[0].test_col_2, 'test5');

var testTime = (new Date(2016, 5, 7, 10, 56, 14)).getTime();
assert.equal(rows[0].test_col_3.getTime(), testTime);
assert.equal(rows[0].test_col_4.getTime(), testTime);

assert.equal(rows[3].id, 4);
assert.equal(rows[3].title, '中文内容');
assert.equal(rows[3].num, 901.234);
assert.equal(rows[3].test_col_1, 'test4');
assert.equal(rows[3].test_col_2, 'test8');
assert.equal(rows[3].test_col_3.getTime(), testTime);
assert.equal(rows[3].test_col_4.getTime(), testTime);
});

connection.query(sql, [badPath, table, ','], function (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ common.getTestConnection({multipleStatements: true}, function (err, connection)
'CREATE TEMPORARY TABLE ?? (',
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`title` varchar(255),',
'`num` varchar(255),',
'`test_col_1` varchar(255) DEFAULT NULL,',
'`test_col_2` varchar(255) NOT NULL,',
'`test_col_3` datetime NOT NULL,',
'`test_col_4` datetime NOT NULL,',
'PRIMARY KEY (`id`)',
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
].join('\n'), [table], assert.ifError);

var stmt =
'LOAD DATA LOCAL INFILE ? INTO TABLE ?? CHARACTER SET utf8 ' +
'FIELDS TERMINATED BY ? (id, title)';
'FIELDS TERMINATED BY ? (id, title, num, test_col_1, test_col_2, test_col_3, test_col_4)';

var sql =
connection.format(stmt, [path, table, ',']) + ';' +
Expand All @@ -38,8 +43,21 @@ common.getTestConnection({multipleStatements: true}, function (err, connection)
assert.equal(rows.length, 4);
assert.equal(rows[0].id, 1);
assert.equal(rows[0].title, 'Hello World');
assert.equal(rows[0].num, 123.456);
assert.equal(rows[0].test_col_1, 'test1');
assert.equal(rows[0].test_col_2, 'test5');

var testTime = (new Date(2016, 5, 7, 10, 56, 14)).getTime();
assert.equal(rows[0].test_col_3.getTime(), testTime);
assert.equal(rows[0].test_col_4.getTime(), testTime);

assert.equal(rows[3].id, 4);
assert.equal(rows[3].title, '中文内容');
assert.equal(rows[3].num, 901.234);
assert.equal(rows[3].test_col_1, 'test4');
assert.equal(rows[3].test_col_2, 'test8');
assert.equal(rows[3].test_col_3.getTime(), testTime);
assert.equal(rows[3].test_col_4.getTime(), testTime);
});

connection.end(assert.ifError);
Expand Down