Browse Source

fix: Fixed issue with sql query spliting in SqliteClient when there is ';' in the query itself

pull/6869/head
Muhammed Mustafa 1 year ago
parent
commit
520143819d
  1. 30
      packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts

30
packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts

@ -1630,8 +1630,36 @@ class SqliteClient extends KnexClient {
const trx = await this.sqlClient.transaction(); const trx = await this.sqlClient.transaction();
const splitQueries = (query) => {
const queries = [];
let quotationCount = 0;
let currentQuery = '';
for (let i = 0; i < query.length; i++) {
if (query[i] === '"' || query[i] === "'") {
// Ignore if quotation is escaped
if (i > 0 && query[i - 1] !== '\\') {
quotationCount++;
}
}
if (query[i] === ';' && quotationCount % 2 === 0) {
queries.push(currentQuery);
currentQuery = '';
} else {
currentQuery += query[i];
}
}
if (currentQuery.trim() !== '') {
queries.push(currentQuery);
}
return queries;
};
try { try {
const queries = upQuery.split(';'); const queries = splitQueries(upQuery);
for (let i = 0; i < queries.length; i++) { for (let i = 0; i < queries.length; i++) {
if (queries[i].trim() !== '') { if (queries[i].trim() !== '') {
await trx.raw(queries[i]); await trx.raw(queries[i]);

Loading…
Cancel
Save