Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function test_promise_returns() {
// Methods return a promises if the callback is omitted.
var connection: sql.ConnectionPool = new sql.ConnectionPool(config);
connection.connect().then(() => { });
connection.close().then(() => { });
connection.query('SELECT 1').then((recordset) => { });
connection.query('SELECT 1 as value').then(res => { });
connection.query`SELECT ${1}`.then((recordset) => { });
connection.batch('create procedure #temporary as select * from table').then((recordset) => { });
connection.batch('create procedure #temporary as select * from table;select 1 as value').then((recordset) => { });
connection.batch`create procedure #temporary as select ${1} from table`.then((recordset) => { });
connection.batch`create procedure #temporary as select ${1} from table`.then((recordset) => { });
var preparedStatment = new sql.PreparedStatement(connection);
preparedStatment.prepare("SELECT @myValue").then(() => { });
preparedStatment.execute({ myValue: 1 }).then((recordSet) => { });
preparedStatment.unprepare().then(() => { });
var transaction = new sql.Transaction(connection);
transaction.begin().then(() => { });
transaction.commit().then(() => { });
transaction.rollback().then(() => { });
var request = new sql.Request();
request.batch('create procedure #temporary as select * from table;select 1 as value').then((recordset) => { });
request.batch('create procedure #temporary as select * from table;select 1 as value').then((recordset) => { });
request.batch`create procedure #temporary as select * from table;select ${1} as value`.then((recordset) => { });
request.batch`create procedure #temporary as select * from table;select ${1} as value`.then((recordset) => { });
request.bulk(new sql.Table("table_name")).then(() => { });
request.query('SELECT 1').then((recordset) => { });
function test_prepared_statement_constructor() {
// Request can be constructed with a connection, preparedStatment, transaction or no arguments
var connection: sql.ConnectionPool = new sql.ConnectionPool(config);
var preparedStatment = new sql.PreparedStatement(connection);
var transaction = new sql.Transaction(connection);
var preparedSatement1 = new sql.PreparedStatement(connection);
var preparedSatement2 = new sql.PreparedStatement(transaction);
}
function test_prepared_statement_constructor() {
// Request can be constructed with a connection, preparedStatment, transaction or no arguments
var connection: sql.ConnectionPool = new sql.ConnectionPool(config);
var preparedStatment = new sql.PreparedStatement(connection);
var transaction = new sql.Transaction(connection);
var preparedSatement1 = new sql.PreparedStatement(connection);
var preparedSatement2 = new sql.PreparedStatement(transaction);
}
function test_prepared_statement_constructor() {
// Request can be constructed with a connection, preparedStatment, transaction or no arguments
var connection: sql.ConnectionPool = new sql.ConnectionPool(config);
var preparedStatment = new sql.PreparedStatement(connection);
var transaction = new sql.Transaction(connection);
var preparedSatement1 = new sql.PreparedStatement(connection);
var preparedSatement2 = new sql.PreparedStatement(transaction);
}
function test_request_constructor() {
// Request can be constructed with a connection, preparedStatment, transaction or no arguments
var connection: sql.ConnectionPool = new sql.ConnectionPool(config);
var preparedStatment = new sql.PreparedStatement(connection);
var transaction = new sql.Transaction(connection);
var request1 = new sql.Request(connection);
var request2 = new sql.Request(preparedStatment);
var request3 = new sql.Request(transaction);
var request4 = new sql.Request();
}
.then(function() {
preparedStatementGlobal = new sql.PreparedStatement();
preparedStatementGlobal.input('username', sql.NVarChar(40));
preparedStatementGlobal.input('email', sql.NVarChar(40));
return preparedStatementGlobal.prepare('INSERT INTO UserTable (name, email) VALUES (@username, @email)');
})
.then(function() {
app.post('/insert-prepared-error-promise', function(req, res) {
var ps = new sql.PreparedStatement();
ps.input('username', sql.NVarChar(40));
ps.input('email', sql.NVarChar(40));
var results;
return ps
.prepare('INSERT INTO UserTable (name, email) VALUES (@username, @email)')
.then(function() {
return ps.execute({
username: 'nero',
email: 'nero@julioclaudian.com_lets_make_this_longer_than_40_chars'
});
})
.then(function(_results) {
results = _results;
return ps.unprepare();
})
.then(function() {
app.post('/insert-prepared-error-callback', function(req, res) {
var ps = new sql.PreparedStatement();
ps.input('username', sql.NVarChar(40));
ps.input('email', sql.NVarChar(40));
ps.prepare('INSERT INTO UserTable (name, email) VALUES (@username, @email)', function(err1) {
if (err1) {
log('Failed to prepare statement.', err1);
return res.status(500).json(err1);
}
ps.execute(
{
username: 'claudius',
email: 'claudius@claudius.com_lets_make_this_longer_than_40_chars'
},
function(err2, results) {
ps.unprepare(function(err3) {
if (err3) {
log('Failed to unprepare statement.', err3);
function preparedSql( state, name, options ) {
var cmd = new sql.PreparedStatement( state.transaction || state.connection );
cmd.multiple = options.hasOwnProperty( "multiple" ) ? options.multiple : false;
var params = createParameters( options.params );
var paramKeyValues = {};
params.forEach( function( param ) {
cmd.input( param.key, param.type );
paramKeyValues[ param.key ] = param.value;
} );
var prepare = lift( cmd.prepare ).bind( cmd );
var execute = lift( cmd.execute ).bind( cmd );
var unprepare = lift( cmd.unprepare ).bind( cmd );
var statement = transformQuery( options.params, options.preparedSql );
return instrument( state, name, function() {
SqlContext.prototype.execPrepared = function(sql, done, params) {
var ps;
if (this.transaction) {
ps = new nodemssql.PreparedStatement(this.transaction);
} else {
ps = new nodemssql.PreparedStatement(this.connection);
}
var idSql = sql + '; select SCOPE_IDENTITY();';
var paramVals = addPsInputs(ps, params);
ps.prepare(idSql, function(err) {
if (err) {
done(err);
} else {
ps.execute(paramVals, function(err, recordset) {
if (err) {
done(err);
} else {
ps.unprepare(function(err) {