Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sqlColumns = this._sqlHelper.generateSqlColumns( columnRow.cells, sqlTypes );
const createCommand = this._sqlHelper.generateCreateWithTypes( table.internalName, sqlColumns );
try {
// console.log( 'TABLE CREATION COMMAND: ', createCommand );
dbConnection.exec( createCommand ); // Creates the table if it does not exist
} catch ( e ) {
const msg = `Error creating the table "${table.name}": ${e.message}`;
throw new RuntimeException( msg, table.location );
}
// Prepares a parameterized insert
const insertCommand = this._sqlHelper.generateParameterizedInsert(
table.internalName, columnRow.cells );
// @ts-ignore
let insert = alasql.compile( insertCommand );
if ( ! isDefined( insert ) ) {
const msg = `Error compiling the insert command at the table "${table.name}".`;
throw new RuntimeException( msg, table.location );
}
// Inserts the values
for ( let i = 1; i < rowCount; ++i ) { // starts at the second row
const row = table.rows[ i ];
try {
// console.log( 'row', row );
let params = this.normalizeValues( row.cells, valTypes );
// console.log( 'params', params );
insert( params );
} catch ( e ) {
const msg = `Error inserting values in the table "${table.name}": ${e.message}`;
const sqlColumns = this._sqlHelper.generateSqlColumns( row.cells, sqlTypes );
//console.log( sqlColumns );
const createCommand = this._sqlHelper.generateCreateWithTypes( table.name, sqlColumns );
try {
// Create the table if it does not exist
db.exec( createCommand );
// Prepare a parameterized insert
const insertCommand = this._sqlHelper.generateParameterizedInsert(
table.name, row.cells );
//console.log( insertCommand );
// @ts-ignore
insert = alasql.compile( insertCommand );
} catch ( e ) {
return reject( e );
}
} else {
// Create the table if it does not exist
const createCommand = this._sqlHelper.generateCreate( table.name, row.cells );
//console.log( createCommand );
try {
db.exec( createCommand );
} catch ( e ) {
return reject( e );
}
}
} else {
const valTypes = this.detectTableColumnTypes(table);
const sqlTypes = valTypes.map(v => this._sqlHelper.convertToSQLType(v));
const sqlColumns = this._sqlHelper.generateSqlColumns(columnRow.cells, sqlTypes);
const createCommand = this._sqlHelper.generateCreateWithTypes(table.internalName, sqlColumns);
try {
// console.log( 'TABLE CREATION COMMAND: ', createCommand );
dbConnection.exec(createCommand); // Creates the table if it does not exist
}
catch (e) {
const msg = `Error creating the table "${table.name}": ${e.message}`;
throw new error_1.RuntimeException(msg, table.location);
}
// Prepares a parameterized insert
const insertCommand = this._sqlHelper.generateParameterizedInsert(table.internalName, columnRow.cells);
// @ts-ignore
let insert = alasql.compile(insertCommand);
if (!util_1.isDefined(insert)) {
const msg = `Error compiling the insert command at the table "${table.name}".`;
throw new error_1.RuntimeException(msg, table.location);
}
// Inserts the values
for (let i = 1; i < rowCount; ++i) { // starts at the second row
const row = table.rows[i];
try {
// console.log( 'row', row );
let params = this.normalizeValues(row.cells, valTypes);
// console.log( 'params', params );
insert(params);
}
catch (e) {
const msg = `Error inserting values in the table "${table.name}": ${e.message}`;
throw new error_1.RuntimeException(msg, table.location);
if (!config.buffer) {
config.buffer = {}
if (config.debug) {
eventEmitter.on('error', console.error)
}
}
if (!config.buffer[context.sourceName]) {
config.buffer[context.sourceName] = {
data: [],
context: context,
queries: []
}
for (var c in config.queries) {
var queryStr = config.queries[c]
try {
var query = alasql.compile(queryStr)
config.buffer[context.sourceName].queries.push(query)
} catch (err) {
eventEmitter.emit('error', new Error('Error in sql output filter: ' + err.message))
}
}
}
config.buffer[context.sourceName].data.push(data)
}