MCPcopy
hub / github.com/sequelize/sequelize / filterSQLError

Method filterSQLError

lib/dialects/db2/query.js:185–229  ·  view source on GitHub ↗
(err, sql, connection)

Source from the content-addressed store, hash-verified

183 }
184
185 filterSQLError(err, sql, connection) {
186 if (err.message.search('SQL0204N') != -1 && _.startsWith(sql, 'DROP ')) {
187 err = null; // Ignore table not found error for drop table.
188 } else if (err.message.search('SQL0443N') != -1) {
189 if (this.isDropSchemaQuery()) {
190 // Delete ERRORSCHEMA.ERRORTABLE if it exist.
191 connection.querySync('DROP TABLE ERRORSCHEMA.ERRORTABLE;');
192 // Retry deleting the schema
193 connection.querySync(this.sql);
194 }
195 err = null; // Ignore drop schema error.
196 } else if (err.message.search('SQL0601N') != -1) {
197 const match = err.message.match(/SQL0601N {2}The name of the object to be created is identical to the existing name "(.*)" of type "(.*)"./);
198 if (match && match.length > 1 && match[2] === 'TABLE') {
199 let table;
200 const mtarray = match[1].split('.');
201 if (mtarray[1]) {
202 table = `"${mtarray[0]}"."${mtarray[1]}"`;
203 } else {
204 table = `"${mtarray[0]}"`;
205 }
206 if (connection.dropTable !== false) {
207 connection.querySync(`DROP TABLE ${table}`);
208 err = connection.querySync(sql);
209 }
210 else {
211 err = null;
212 }
213 } else {
214 err = null; // Ignore create schema error.
215 }
216 } else if (err.message.search('SQL0911N') != -1) {
217 if (err.message.search('Reason code "2"') != -1) {
218 err = null; // Ignore deadlock error due to program logic.
219 }
220 } else if (err.message.search('SQL0605W') != -1) {
221 err = null; // Ignore warning.
222 } else if (err.message.search('SQL0668N') != -1 &&
223 _.startsWith(sql, 'ALTER TABLE ')) {
224 connection.querySync(`CALL SYSPROC.ADMIN_CMD('REORG TABLE ${sql.substring(12).split(' ')[0]}')`);
225 err = connection.querySync(sql);
226 }
227 if (err && err.length === 0) { err = null; }
228 return err;
229 }
230
231 /**
232 * 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