test-insert-results.js 656 B

123456789101112131415161718192021222324252627
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. common.useTestDb(connection);
  5. var table = 'insert_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 result;
  14. connection.query('INSERT INTO ' + table + ' SET ?', {title: 'test'}, function(err, _result) {
  15. if (err) throw err;
  16. result = _result;
  17. });
  18. connection.end();
  19. process.on('exit', function() {
  20. assert.strictEqual(result.insertId, 1);
  21. });