@@ -30,8 +30,6 @@ export class CodeEditorComponent implements OnInit {
3030 @Output ( ) execute = new EventEmitter < string > ( ) ;
3131 @Output ( ) clearData = new EventEmitter < void > ( ) ;
3232 @Input ( ) queryError : string | null = null ;
33-
34- isExecuting = false ;
3533 sqlQuery = '' ;
3634 errorMessage = '' ;
3735 successMessage = '' ;
@@ -61,7 +59,6 @@ export class CodeEditorComponent implements OnInit {
6159
6260 executeQuery ( ) : void {
6361 this . resetMessages ( ) ;
64-
6562 const query = this . sqlQuery ? this . sqlQuery . trim ( ) : '' ;
6663 if ( ! query ) {
6764 this . errorMessage = 'The query cannot be empty.' ;
@@ -150,6 +147,14 @@ export class CodeEditorComponent implements OnInit {
150147 return 'Parentheses are not balanced.' ;
151148 }
152149
150+ if ( this . hasMisplacedCommas ( trimmed ) ) {
151+ return 'Query contains misplaced commas.' ;
152+ }
153+
154+ if ( this . hasSubqueryWithoutAlias ( trimmed ) ) {
155+ return 'Subquery in FROM must have an alias.' ;
156+ }
157+
153158 const functions = this . extractFunctions ( upper ) ;
154159 for ( const func of functions ) {
155160 if ( ! allowedFunctions . has ( func ) ) {
@@ -202,4 +207,44 @@ export class CodeEditorComponent implements OnInit {
202207
203208 return funcs ;
204209 }
210+
211+ private hasMisplacedCommas ( query : string ) : boolean {
212+ const upperQuery = query . toUpperCase ( ) ;
213+
214+ if ( upperQuery . startsWith ( 'SELECT ,' ) || upperQuery . includes ( ',,' ) ) {
215+ return true ;
216+ }
217+
218+ if ( / , \s * F R O M / i. test ( upperQuery ) ) {
219+ return true ;
220+ }
221+
222+ const selectPart = query
223+ . replace ( / ^ S E L E C T \s + / i, '' )
224+ . replace ( / \s + F R O M .* $ / i, '' )
225+ . trim ( ) ;
226+
227+ if ( selectPart . startsWith ( ',' ) || selectPart . endsWith ( ',' ) ) {
228+ return true ;
229+ }
230+
231+ const fields = selectPart . split ( ',' ) ;
232+ for ( const f of fields ) {
233+ if ( f . trim ( ) === '' ) {
234+ return true ;
235+ }
236+ }
237+
238+ return false ;
239+ }
240+
241+ private hasSubqueryWithoutAlias ( query : string ) : boolean {
242+ const subqueryRegex = / F R O M \s * \( [ ^ ) ] * \) / i;
243+ if ( ! subqueryRegex . test ( query ) ) {
244+ return false ;
245+ }
246+ const aliasRegex = / F R O M \s * \( [ ^ ) ] * \) \s + ( A S \s + \w + | \w + ) / i;
247+ return ! aliasRegex . test ( query ) ;
248+ }
249+
205250}
0 commit comments