diff --git a/patches/sql-query-identifier+2.1.0.patch b/patches/sql-query-identifier+2.1.0.patch new file mode 100644 index 000000000..ed4146b68 --- /dev/null +++ b/patches/sql-query-identifier+2.1.0.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/sql-query-identifier/lib/tokenizer.js b/node_modules/sql-query-identifier/lib/tokenizer.js +index f8980fe..bb03059 100644 +--- a/node_modules/sql-query-identifier/lib/tokenizer.js ++++ b/node_modules/sql-query-identifier/lib/tokenizer.js +@@ -249,7 +249,7 @@ function skipWord(state, value) { + }; + } + function isWhitespace(ch) { +- return ch === ' ' || ch === '\t' || ch === '\n'; ++ return ch === ' ' || ch === '\t' || ch === '\n' || ch == '\r'; + } + function isString(ch, dialect) { + const stringStart = dialect === 'mysql' ? ["'", '"'] : ["'"]; diff --git a/plugins/dbgate-plugin-postgres/src/backend/driver.js b/plugins/dbgate-plugin-postgres/src/backend/driver.js index 5caec35ac..fc6702c38 100644 --- a/plugins/dbgate-plugin-postgres/src/backend/driver.js +++ b/plugins/dbgate-plugin-postgres/src/backend/driver.js @@ -121,7 +121,7 @@ const driver = { return { rows: res.rows.map(row => zipDataRow(row, columns)), columns }; }, async stream(client, sql, options) { - const sqlSplitted = identify(sql, { dialect: 'psql' }); + const sqlSplitted = identify(sql, { dialect: 'psql', strict: false }); for (const sqlItem of sqlSplitted) { await runStreamItem(client, sqlItem.text, options); diff --git a/plugins/dbgate-plugin-sqlite/src/backend/driver.js b/plugins/dbgate-plugin-sqlite/src/backend/driver.js index 657e418ba..8339a0434 100644 --- a/plugins/dbgate-plugin-sqlite/src/backend/driver.js +++ b/plugins/dbgate-plugin-sqlite/src/backend/driver.js @@ -6,48 +6,43 @@ const { identify } = require('sql-query-identifier'); let Database; -async function runStreamItem(client, sql, options) { - return new Promise((resolve, reject) => { - try { - const stmt = client.prepare(sql); - if (stmt.reader) { - const columns = stmt.columns(); - // const rows = stmt.all(); +function runStreamItem(client, sql, options) { + try { + console.log('RUN SQL ITEM', sql); + const stmt = client.prepare(sql); + if (stmt.reader) { + const columns = stmt.columns(); + // const rows = stmt.all(); - options.recordset( - columns.map((col) => ({ - columnName: col.name, - dataType: col.type, - })) - ); + options.recordset( + columns.map((col) => ({ + columnName: col.name, + dataType: col.type, + })) + ); - for (const row of stmt.iterate()) { - options.row(row); - } - - resolve(); - } else { - const info = stmt.run(); - options.info({ - message: `${info.changes} rows affected`, - time: new Date(), - severity: 'info', - }); - resolve(); + for (const row of stmt.iterate()) { + options.row(row); } - } catch (error) { - console.log('ERROR', error); - const { message, lineNumber, procName } = error; + } else { + const info = stmt.run(); options.info({ - message, - line: lineNumber, - procedure: procName, + message: `${info.changes} rows affected`, time: new Date(), - severity: 'error', + severity: 'info', }); - resolve(); } - }); + } catch (error) { + console.log('ERROR', error); + const { message, lineNumber, procName } = error; + options.info({ + message, + line: lineNumber, + procedure: procName, + time: new Date(), + severity: 'error', + }); + } } /** @type {import('dbgate-types').EngineDriver} */ @@ -73,10 +68,12 @@ const driver = { }; }, async stream(client, sql, options) { - const sqlSplitted = identify(sql, { dialect: 'sqlite' }); + // console.log('CP1', sql); + const sqlSplitted = identify(sql, { dialect: 'sqlite', strict: false }); + // console.log('CP2', sqlSplitted); for (const sqlItem of sqlSplitted) { - await runStreamItem(client, sqlItem.text, options); + runStreamItem(client, sqlItem.text, options); } options.done();