Skip to content

Build your personal knowledge base with Trilium Notes

Fix SQL comment handling

mechanarchy1fc23c948ee5
diff --git a/src/routes/api/sql.js b/src/routes/api/sql.js
index f37b6d310a..9dec60aff0 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')) {