-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest-load-data-infile-disable.js
48 lines (41 loc) · 1.54 KB
/
test-load-data-infile-disable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var assert = require('assert');
var common = require('../../common');
var path = common.fixtures + '/data.csv';
var table = 'load_data_test';
var newline = common.detectNewline(path);
common.getTestConnection({localInfile: false}, function (err, connection) {
assert.ifError(err);
common.useTestDb(connection);
// only test result if server permits local infile
connection.query('SELECT @@local_infile', function (err, rows) {
assert.ifError(err);
if (rows[0]['@@local_infile'] === 1) {
connection.query([
'CREATE TEMPORARY TABLE ?? (',
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`title` varchar(400),',
'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 ? ' +
'LINES TERMINATED BY ? ' +
'(id, title)';
connection.query(sql, [path, table, ',', newline], function (err) {
assert.ok(err);
if (common.isMariaDB(connection) && common.minVersion(connection, 10, 5, 0)) {
// mariadb specific error ER_LOAD_INFILE_CAPABILITY_DISABLED
assert.equal(err.errno, 4166);
} else {
assert.equal(err.code, 'ER_NOT_ALLOWED_COMMAND');
}
});
connection.query('SELECT * FROM ??', [table], function (err, rows) {
assert.ifError(err);
assert.equal(rows.length, 0);
});
}
connection.end(assert.ifError);
});
});