You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 lines
27 KiB

{
"version": 3,
"sources": ["../../../src/dialects/db2/query.js"],
"sourcesContent": ["'use strict';\n\nconst AbstractQuery = require('../abstract/query');\nconst sequelizeErrors = require('../../errors');\nconst parserStore = require('../parserStore')('db2');\nconst _ = require('lodash');\nconst { logger } = require('../../utils/logger');\nconst moment = require('moment');\nconst debug = logger.debugContext('sql:db2');\n\nclass Query extends AbstractQuery {\n getInsertIdField() {\n return 'id';\n }\n\n getSQLTypeFromJsType(value) {\n const param = { ParamType: 'INPUT', Data: value };\n if (Buffer.isBuffer(value)) {\n param.DataType = 'BLOB';\n return param;\n }\n return value;\n }\n\n async _run(connection, sql, parameters) {\t\n this.sql = sql;\n const benchmark = this.sequelize.options.benchmark || this.options.benchmark;\n let queryBegin;\n if (benchmark) {\n queryBegin = Date.now();\n } else {\n this.sequelize.log(`Executing (${ this.connection.uuid || 'default' }): ${ this.sql}`, this.options);\n }\n\n const errStack = new Error().stack;\n\n return new Promise((resolve, reject) => {\n // TRANSACTION SUPPORT\n if (_.startsWith(this.sql, 'BEGIN TRANSACTION')) {\n connection.beginTransaction(err => {\n if (err) {\n reject(this.formatError(err, errStack));\n } else {\n resolve(this.formatResults());\n }\n });\n } else if (_.startsWith(this.sql, 'COMMIT TRANSACTION')) {\n connection.commitTransaction(err => {\n if (err) {\n reject(this.formatError(err, errStack));\n } else {\n resolve(this.formatResults());\n }\n });\n } else if (_.startsWith(this.sql, 'ROLLBACK TRANSACTION')) {\n connection.rollbackTransaction(err => {\n if (err) {\n reject(this.formatError(err, errStack));\n } else {\n resolve(this.formatResults());\n }\n });\n } else if (_.startsWith(this.sql, 'SAVE TRANSACTION')) {\n connection.commitTransaction(err => {\n if (err) {\n reject(this.formatError(err, errStack));\n } else {\n connection.beginTransaction(err => {\n if (err) {\n reject(this.formatError(err, errStack));\n } else {\n resolve(this.formatResults());\n }\n });\n }\n }, this.options.transaction.name);\n } else {\n const params = [];\n if (parameters) {\n _.forOwn(parameters, (value, key) => {\n const param = this.getSQLTypeFromJsType(value, key);\n params.push(param);\n });\n }\n const SQL = this.sql.toUpperCase();\n let newSql = this.sql;\n if ((this.isSelectQuery() || _.startsWith(SQL, 'SELECT ')) &&\n SQL.indexOf(' FROM ', 8) === -1 ) {\n if (this.sql.charAt(this.sql.length - 1) === ';') {\n newSql = this.sql.slice(0, this.sql.length - 1);\n }\n newSql += ' FROM SYSIBM.SYSDUMMY1;';\n }\n\n connection.prepare(newSql, (err, stmt) => {\n if (err) {\n reject(this.formatError(err, errStack));\n }\n\n stmt.execute(params, (err, result, outparams) => {\n debug(`executed(${this.connection.uuid || 'default'}):${newSql} ${parameters ? JSON.stringify(parameters) : ''}`);\n\n if (benchmark) {\n this.sequelize.log(`Executed (${ this.connection.uuid || 'default' }): ${ newSql} ${parameters ? JSON.stringify(parameters) : ''}`, Date.now() - queryBegin, this.options);\n }\n\n if (err && err.message) {\n err = this.filterSQLError(err, this.sql, connection);\n if (err === null) {\n stmt.closeSync();\n resolve(this.formatResults([], 0));\n }\n }\n if (err) {\n err.sql = sql;\n stmt.closeSync();\n reject(this.formatError(err, errStack, connecti
"mappings": ";AAEA,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,kBAAkB,QAAQ;AAChC,MAAM,cAAc,QAAQ,kBAAkB;AAC9C,MAAM,IAAI,QAAQ;AAClB,MAAM,EAAE,WAAW,QAAQ;AAC3B,MAAM,SAAS,QAAQ;AACvB,MAAM,QAAQ,OAAO,aAAa;AAElC,oBAAoB,cAAc;AAAA,EAChC,mBAAmB;AACjB,WAAO;AAAA;AAAA,EAGT,qBAAqB,OAAO;AAC1B,UAAM,QAAQ,EAAE,WAAW,SAAS,MAAM;AAC1C,QAAI,OAAO,SAAS,QAAQ;AAC1B,YAAM,WAAW;AACjB,aAAO;AAAA;AAET,WAAO;AAAA;AAAA,QAGH,KAAK,YAAY,KAAK,YAAY;AACtC,SAAK,MAAM;AACX,UAAM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