test-transaction-rollback.js 876 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. common.useTestDb(connection);
  5. var table = 'transaction_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. connection.query('START TRANSACTION');
  14. var rowCount = 10;
  15. for (var i = 1; i <= rowCount; i++) {
  16. var row = {
  17. id: i,
  18. title: 'Row #' + i,
  19. };
  20. connection.query('INSERT INTO ' + table + ' SET ?', row);
  21. }
  22. connection.query('ROLLBACK');
  23. var rows;
  24. var query = connection.query('SELECT * FROM ' + table, function(err, _rows) {
  25. if (err) throw err;
  26. rows = _rows;
  27. });
  28. connection.end();
  29. process.on('exit', function() {
  30. assert.equal(rows.length, 0);
  31. });