MCPcopy Index your code
hub / github.com/sequelize/sequelize / filterSQLError

Method filterSQLError

src/dialects/db2/query.js:197–241  ·  view source on GitHub ↗
(err, sql, connection)

Source from the content-addressed store, hash-verified

195 }
196
197 filterSQLError(err, sql, connection) {
198 if (err.message.search('SQL0204N') != -1 && _.startsWith(sql, 'DROP ')) {
199 err = null; // Ignore table not found error for drop table.
200 } else if (err.message.search('SQL0443N') != -1) {
201 if (this.isDropSchemaQuery()) {
202 // Delete ERRORSCHEMA.ERRORTABLE if it exist.
203 connection.querySync('DROP TABLE ERRORSCHEMA.ERRORTABLE;');
204 // Retry deleting the schema
205 connection.querySync(this.sql);
206 }
207 err = null; // Ignore drop schema error.
208 } else if (err.message.search('SQL0601N') != -1) {
209 const match = err.message.match(/SQL0601N {2}The name of the object to be created is identical to the existing name "(.*)" of type "(.*)"./);
210 if (match && match.length > 1 && match[2] === 'TABLE') {
211 let table;
212 const mtarray = match[1].split('.');
213 if (mtarray[1]) {
214 table = `"${mtarray[0]}"."${mtarray[1]}"`;
215 } else {
216 table = `"${mtarray[0]}"`;
217 }
218 if (connection.dropTable !== false) {
219 connection.querySync(`DROP TABLE ${table}`);
220 err = connection.querySync(sql);
221 }
222 else {
223 err = null;
224 }
225 } else {
226 err = null; // Ignore create schema error.
227 }
228 } else if (err.message.search('SQL0911N') != -1) {
229 if (err.message.search('Reason code "2"') != -1) {
230 err = null; // Ignore deadlock error due to program logic.
231 }
232 } else if (err.message.search('SQL0605W') != -1) {
233 err = null; // Ignore warning.
234 } else if (err.message.search('SQL0668N') != -1 &&
235 _.startsWith(sql, 'ALTER TABLE ')) {
236 connection.querySync(`CALL SYSPROC.ADMIN_CMD('REORG TABLE ${sql.substring(12).split(' ')[0]}')`);
237 err = connection.querySync(sql);
238 }
239 if (err && err.length === 0) { err = null; }
240 return err;
241 }
242
243 /**
244 * High level function that handles the results of a query execution.

Callers 1

_runMethod · 0.95

Calls 1

isDropSchemaQueryMethod · 0.95

Tested by

no test coverage detected