A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

12 years ago
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. common.useTestDb(connection);
  5. var table = 'load_data_test';
  6. connection.query([
  7. 'CREATE TEMPORARY TABLE `' + table + '` (',
  8. '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
  9. '`title` varchar(255),',
  10. 'PRIMARY KEY (`id`)',
  11. ') ENGINE=InnoDB DEFAULT CHARSET=utf8'
  12. ].join('\n'));
  13. var path = common.fixtures + '/data.csv';
  14. var sql =
  15. 'LOAD DATA LOCAL INFILE ? INTO TABLE ' + table + ' ' +
  16. 'FIELDS TERMINATED BY ? (id, title)';
  17. var ok;
  18. connection.query(sql, [path, ','], function(err, _ok) {
  19. if (err) throw err;
  20. ok = _ok;
  21. });
  22. var rows;
  23. connection.query('SELECT * FROM ' + table, function(err, _rows) {
  24. if (err) throw err;
  25. rows = _rows;
  26. });
  27. // Try to load a file that does not exist to see if we handle this properly
  28. var loadErr;
  29. var loadResult;
  30. var badPath = common.fixtures + '/does_not_exist.csv';
  31. connection.query(sql, [badPath, ','], function(err, result) {
  32. loadErr = err;
  33. loadResult = result;
  34. });
  35. connection.end();
  36. process.on('exit', function() {
  37. assert.equal(ok.affectedRows, 3);
  38. assert.equal(rows.length, 3);
  39. assert.equal(rows[0].id, 1);
  40. assert.equal(rows[0].title, 'Hello World');
  41. assert.equal(loadErr.code, 'ENOENT');
  42. assert.equal(loadResult.affectedRows, 0);
  43. });