diff --git a/src/routes/api/sql.js b/src/routes/api/sql.js index f37b6d310..9dec60aff 100644 --- a/src/routes/api/sql.js +++ b/src/routes/api/sql.js @@ -33,13 +33,14 @@ function execute(req) { for (let query of queries) { query = query.trim(); - if (!query) { - continue; - } - while (query.startsWith('-- ') { // Query starts with one or more SQL comments, discard these before we execute. - query = query.substr(query.indexOf('\n') + 1) + const pivot = query.indexOf('\n'); + query = pivot > 0 ? query.substr(pivot + 1).trim() : ""; + } + + if (!query) { + continue; } if (query.toLowerCase().startsWith('select') || query.toLowerCase().startsWith('with')) {