This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
node-task/node_modules/mysql2/test/integration/connection/test-transaction-rollback.js

37 lines
997 B
JavaScript
Raw Normal View History

2014-09-24 17:56:53 -04:00
var common = require('../../common');
var connection = common.createConnection();
var assert = require('assert');
common.useTestDb(connection);
var table = 'transaction_test';
connection.query([
'CREATE TEMPORARY TABLE `' + table + '` (',
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`title` varchar(255),',
'PRIMARY KEY (`id`)',
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
].join('\n'));
connection.beginTransaction(function (err) {
assert.ifError(err);
var row = {
id: 1,
title: 'Test row'
};
connection.query('INSERT INTO ' + table + ' SET ?', row, function(err) {
assert.ifError(err);
connection.rollback(function(err) {
assert.ifError(err);
connection.query('SELECT * FROM ' + table, function(err, rows) {
assert.ifError(err);
connection.end();
assert.equal(rows.length, 0);
});
});
});
});