Comparing version 1.8.1 to 1.9.0
@@ -344,3 +344,3 @@ // Generated by CoffeeScript 1.7.1 | ||
this.createTokenStreamParser(); | ||
this.transactions = []; | ||
this.inTransaction = false; | ||
this.transactionDescriptors = [new Buffer([0, 0, 0, 0, 0, 0, 0, 0])]; | ||
@@ -496,3 +496,4 @@ this.transitionTo(this.STATE.CONNECTING); | ||
return function(token) { | ||
return _this.transactionDescriptors.push(token.newValue); | ||
_this.transactionDescriptors.push(token.newValue); | ||
return _this.inTransaction = true; | ||
}; | ||
@@ -502,3 +503,4 @@ })(this)); | ||
return function(token) { | ||
return _this.transactionDescriptors.pop(); | ||
_this.transactionDescriptors.length = 1; | ||
return _this.inTransaction = false; | ||
}; | ||
@@ -508,3 +510,4 @@ })(this)); | ||
return function(token) { | ||
return _this.transactionDescriptors.pop(); | ||
_this.transactionDescriptors.length = 1; | ||
return _this.inTransaction = false; | ||
}; | ||
@@ -991,6 +994,4 @@ })(this)); | ||
var request, transaction; | ||
name || (name = ''); | ||
isolationLevel || (isolationLevel = this.config.options.isolationLevel); | ||
transaction = new Transaction(name, isolationLevel); | ||
this.transactions.push(transaction); | ||
transaction = new Transaction(name || '', isolationLevel); | ||
if (this.config.options.tdsVersion < "7_2") { | ||
@@ -1007,8 +1008,5 @@ return this.execSqlBatch(new Request("SET TRANSACTION ISOLATION LEVEL " + (transaction.isolationLevelToTSQL()) + ";BEGIN TRAN " + transaction.name, callback)); | ||
Connection.prototype.commitTransaction = function(callback) { | ||
Connection.prototype.commitTransaction = function(callback, name) { | ||
var request, transaction; | ||
if (this.transactions.length === 0) { | ||
return callback(RequestError('No transaction in progress', 'ENOTRNINPROG')); | ||
} | ||
transaction = this.transactions.pop(); | ||
transaction = new Transaction(name || ''); | ||
if (this.config.options.tdsVersion < "7_2") { | ||
@@ -1021,8 +1019,5 @@ return this.execSqlBatch(new Request("COMMIT TRAN " + transaction.name, callback)); | ||
Connection.prototype.rollbackTransaction = function(callback) { | ||
Connection.prototype.rollbackTransaction = function(callback, name) { | ||
var request, transaction; | ||
if (this.transactions.length === 0) { | ||
return callback(RequestError('No transaction in progress', 'ENOTRNINPROG')); | ||
} | ||
transaction = this.transactions.pop(); | ||
transaction = new Transaction(name || ''); | ||
if (this.config.options.tdsVersion < "7_2") { | ||
@@ -1035,2 +1030,78 @@ return this.execSqlBatch(new Request("ROLLBACK TRAN " + transaction.name, callback)); | ||
Connection.prototype.saveTransaction = function(callback, name) { | ||
var request, transaction; | ||
transaction = new Transaction(name); | ||
if (this.config.options.tdsVersion < "7_2") { | ||
return this.execSqlBatch(new Request("SAVE TRAN " + transaction.name, callback)); | ||
} | ||
request = new Request(void 0, callback); | ||
return this.makeRequest(request, TYPE.TRANSACTION_MANAGER, transaction.savePayload(this.currentTransactionDescriptor())); | ||
}; | ||
Connection.prototype.transaction = function(cb, isolationLevel) { | ||
var name, txDone, useSavepoint; | ||
if (typeof cb !== 'function') { | ||
throw new TypeError('`cb` must be a function'); | ||
} | ||
useSavepoint = this.inTransaction; | ||
name = "_tedious_" + (crypto.randomBytes(10).toString('hex')); | ||
txDone = (function(_this) { | ||
return function(err, done) { | ||
var args, i, _i, _ref1; | ||
args = []; | ||
for (i = _i = 2, _ref1 = arguments.length; 2 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 2 <= _ref1 ? ++_i : --_i) { | ||
args.push(arguments[i]); | ||
} | ||
if (err) { | ||
if (_this.inTransaction) { | ||
return _this.rollbackTransaction(function(txErr) { | ||
args.unshift(txErr || err); | ||
return done.apply(null, args); | ||
}, name); | ||
} else { | ||
return process.nextTick(function() { | ||
args.unshift(err); | ||
return done.apply(null, args); | ||
}); | ||
} | ||
} else { | ||
if (useSavepoint) { | ||
return process.nextTick(function() { | ||
args.unshift(null); | ||
return done.apply(null, args); | ||
}); | ||
} else { | ||
return _this.commitTransaction(function(txErr) { | ||
args.unshift(txErr); | ||
return done.apply(null, args); | ||
}, name); | ||
} | ||
} | ||
}; | ||
})(this); | ||
if (useSavepoint) { | ||
return this.saveTransaction((function(_this) { | ||
return function(err) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (isolationLevel) { | ||
return _this.execSqlBatch(new Request("SET transaction isolation level " + (_this.getIsolationLevelText(isolationLevel)), function(err) { | ||
return cb(err, txDone); | ||
})); | ||
} else { | ||
return cb(null, txDone); | ||
} | ||
}; | ||
})(this), name); | ||
} else { | ||
return this.beginTransaction(function(err) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
return cb(null, txDone); | ||
}, name, isolationLevel); | ||
} | ||
}; | ||
Connection.prototype.makeRequest = function(request, packetType, payload) { | ||
@@ -1037,0 +1108,0 @@ var message; |
@@ -100,2 +100,19 @@ // Generated by CoffeeScript 1.7.1 | ||
Transaction.prototype.savePayload = function(txnDescriptor) { | ||
var buffer, payload; | ||
buffer = new WritableTrackingBuffer(100, 'ascii'); | ||
writeAllHeaders(buffer, txnDescriptor, this.outstandingRequestCount); | ||
buffer.writeUShort(OPERATION_TYPE.TM_SAVE_XACT); | ||
buffer.writeUInt8(this.name.length * 2); | ||
buffer.writeString(this.name, 'ucs2'); | ||
return payload = { | ||
data: buffer.data, | ||
toString: (function(_this) { | ||
return function() { | ||
return "Save Transaction: name=" + _this.name; | ||
}; | ||
})(this) | ||
}; | ||
}; | ||
Transaction.prototype.isolationLevelToTSQL = function() { | ||
@@ -102,0 +119,0 @@ switch (this.isolationLevel) { |
@@ -33,3 +33,3 @@ { | ||
], | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"main": "./lib/tedious.js", | ||
@@ -36,0 +36,0 @@ "repository": { |
# Tedious (node implementation of TDS) | ||
[![Dependency Status](https://david-dm.org/pekim/tedious.png)](https://david-dm.org/pekim/tedious) [![NPM version](https://badge.fury.io/js/tedious.png)](http://badge.fury.io/js/tedious) [![Build Status](https://secure.travis-ci.org/pekim/tedious.png)](http://travis-ci.org/pekim/tedious) | ||
[![Dependency Status](https://david-dm.org/pekim/tedious.png)](https://david-dm.org/pekim/tedious) [![NPM version](https://badge.fury.io/js/tedious.png)](http://badge.fury.io/js/tedious) [![Build Status](https://secure.travis-ci.org/pekim/tedious.png)](http://travis-ci.org/pekim/tedious) [![Build Status](https://ci.appveyor.com/api/projects/status/ike3p58hljpyffrl?svg=true)](https://ci.appveyor.com/project/pekim/tedious) | ||
@@ -4,0 +4,0 @@ Tedious is an implementation of the [TDS protocol](http://msdn.microsoft.com/en-us/library/dd304523.aspx), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
198810
5753
4