Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -532,16 +532,26 @@
}

dataverseSelected() {
if (this.selected == undefined) {
this.queryString = 'None';
} else if (this.selected === 'None' || this.selected === 'Default') {
this.queryString = '';
if (this.selected == undefined) return;

const useStmt = 'USE ' + this.selected + ';\n';
let qs = this.queryString || '';
const leadingUseRegex = /^\s*USE\s+[^;]+;\s*/i;

if (this.selected === 'None' || this.selected === 'Default') {
qs = qs.replace(leadingUseRegex, '');
this.selected = 'Default';
} else {
this.queryString = 'USE ' + this.selected + '; \n' + this.queryString;
if (leadingUseRegex.test(qs)) {
qs = qs.replace(leadingUseRegex, useStmt);
} else {
qs = useStmt + qs;
}
Comment on lines +537 to +549
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leadingUseRegex only matches a USE ...; that appears at the very start of the query (ignoring whitespace). If the user has a leading SQL++ comment/header (e.g., -- ... or /* ... */) before the USE statement, the regex won’t match and switching dataverses will prepend a new USE while leaving the old one in place, potentially resulting in the query still running under the old dataverse (since the later USE can override). Consider expanding the match to allow leading comments before the first USE, or stripping/replacing the first USE statement that occurs before any non-comment tokens.

Copilot uses AI. Check for mistakes.
}

this.queryString = qs;
this.editor.getDoc().setValue(this.queryString);
this.editor.execCommand('goDocEnd')
this.editor.execCommand('goDocEnd');
this.editor.focus();
}

Expand Down
Loading