Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readFile(sqlFile, 'utf8', (err, script) => {
const request = new mssql.Request(pool);
request.query(script, (err, rec) => {
if (err) {
const sqlerror = sqldevops.getSqlError(err);
res.render('error', {
message: sqlerror.message,
error: sqlerror
});
}
else {
// for debugging
// console.log(rec.recordset);
res.render(viewName, {
title: title,
description: description,
nav: nav,
recordset: rec.recordset,
router.get('/', (req, res, next) => {
const request = new mssql.Request(pool);
fs.readFile(tablespaceSqlFile, 'utf8', (err, script) => {
const request = new mssql.Request(pool);
request.query(script, (err, rec) => {
if (err) {
const sqlerror = sqldevops.getSqlError(err);
res.render('error', {
message: sqlerror.message,
error: sqlerror
});
}
else {
// for debugging
//console.log(rec.recordset);
res.render('tablespacedetail', {
title: 'Table Space Usage Detail',
tablespaces: rec.recordset,
pool.connect((err) => {
const request = new mssql.Request(pool);
request.query(script, (err, rec) => {
if (err) {
const sqlerror = sqldevops.getSqlError(err);
res.render('error', {
message: sqlerror.message,
error: sqlerror
});
}
else {
// for debugging
//console.log(rec.recordset);
res.render('index', {
title: 'Insights',
nav: nav,
tablespaces: rec.recordset,
server: dbconfig.server,
(err) => {
if (err) {
return reject(this.buildError(err));
}
// Query
var request = new sql.Request(connection);
request.multiple = true;
if (onQueryToken)
onQueryToken(request);
request.query(query,
(err, recordset) => {
if (err) {
return reject(this.buildError(err));
}
resolve(this.translateResults(recordset));
}
);
}
);
_.forEach( options.bulkLoadTable.columns, function( column, columnName ) {
table.columns.add( columnName, column.type, { nullable: column.nullable === undefined ? true : column.nullable } );
} );
var columnNames = Object.keys( options.bulkLoadTable.columns );
options.bulkLoadTable.rows.forEach( function( row ) {
var values = columnNames.map( function( columnName ) {
return row[ columnName ];
} );
table.rows.add.apply( table.rows, values );
} );
var req = new sql.Request( state.transaction || state.connection );
return when.resolve()
.then( function() {
if ( !isTempTableName( options.bulkLoadTable.name ) ) {
return;
}
var dropSql = "IF OBJECT_ID('tempdb.." + options.bulkLoadTable.name + "') IS NOT NULL DROP TABLE " + options.bulkLoadTable.name + ";";
if ( !options.bulkLoadTable.useExisting ) {
// Make sure we're not adding to an existing temp table
nonPreparedSql( state, name + "-pre-drop", { query: dropSql } );
}
// Accumulate list of tables on state, which is the transaction object, to enforce appropriate scope
// Keep this list to avoid double-dropping tables when we bulk load the same temp table more than once using `useExisting`
self.results[current.name] = rows;
self.emit('data', current.name, self.results);
}
self.last = item.name;
next();
};
if (item.type !== 'begin' && item.type !== 'end') {
if (!current.first)
current.first = isFIRST(current.query);
if (Agent.debug)
console.log(self.debugname, current.name, current.query);
self.emit('query', current.name, current.query, current.params);
var request = new database.Request(self.$transaction ? self.$transaction : self.db);
if (current.params)
prepare_params_request(request, current.params);
request.query(current.query, query);
return;
}
if (item.type === 'begin') {
if (Agent.debug)
console.log(self.debugname, 'begin transaction');
self.$transaction = new database.Transaction(self.db);
self.$transaction.begin(function(err) {
if (err) {
self.errors.push(err.message);
self.command.length = 0;
transaction.begin(function (err) {
var request;
if (err) {
return callback(err);
}
request = new sql.Request(transaction);
request.query(query, function (err, recordset) {
if (err) {
return callback(err);
}
callback(null, recordset);
transaction.commit(function () {
console.log("Transaction committed.");
});
});
});
return cb(err)
}
var schema = sql.schema(collection, definition)
var schemaName = getSchemaName(connection, collection)
var tableName = '[' + schemaName + ']' + '.[' + collection + ']'
var statement = 'CREATE TABLE ' + tableName + ' (' + schema + ')'
uniqId = uniqId || false
var mssqlConnect
if (!uniqId) {
mssqlConnect = connections[connection].mssqlConnection
} else {
mssqlConnect = connections[connection].mssqlConnection[uniqId]
}
var request = new mssql.Request(mssqlConnect)
request.query(statement, function (err, recordset) {
if (err) {
console.error('Error during query', err)
return cb(err)
}
if (!connections[connection].persistent) {
mssqlConnect && mssqlConnect.close()
}
cb(null, {})
})
})
},
const query = async () => {
let result = false
if (redisKey) {
try {
const redisResult = await redisCacheService.get(redisKey)
result = JSON.parse(redisResult)
} catch (e) {}
}
if (!result) {
const request = new mssql.Request(readonlyPool)
addParamsToRequestSimple(params, request)
result = await request.query(sql)
if (redisKey) {
await redisCacheService.set(redisKey, result)
}
}
return sqlService.transformResult(result)
}
public async CreateDB(dbName: string) {
const request = new MSSQL.Request(this.Connection);
await request.query(`CREATE DATABASE ${dbName}; `);
}