This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 234246
Collapse All | Expand All

(-)a/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java (-1 / +46 lines)
Lines 264-269 Link Here
264
        private void parse() {
264
        private void parse() {
265
            checkDelimiterStatement();
265
            checkDelimiterStatement();
266
            int startQuote = -1;
266
            int startQuote = -1;
267
            int commentStart = 0;
267
            while (pos < sqlLength) {
268
            while (pos < sqlLength) {
268
                char ch = sql.charAt(pos);
269
                char ch = sql.charAt(pos);
269
                
270
                
Lines 303-308 Link Here
303
                        
304
                        
304
                    case STATE_MAYBE_LINE_COMMENT:
305
                    case STATE_MAYBE_LINE_COMMENT:
305
                        if (ch == '-') {
306
                        if (ch == '-') {
307
                            commentStart = pos + 1;
306
                            state = STATE_LINE_COMMENT;
308
                            state = STATE_LINE_COMMENT;
307
                        } else {
309
                        } else {
308
                            state = STATE_MEANINGFUL_TEXT;
310
                            state = STATE_MEANINGFUL_TEXT;
Lines 313-324 Link Here
313
                        
315
                        
314
                    case STATE_LINE_COMMENT:
316
                    case STATE_LINE_COMMENT:
315
                        if (ch == '\n') {
317
                        if (ch == '\n') {
318
                            checkForDelimiterStmt(commentStart, pos - 1);
316
                            state = STATE_MEANINGFUL_TEXT;
319
                            state = STATE_MEANINGFUL_TEXT;
317
                        } 
320
                        } 
318
                        break;
321
                        break;
319
                        
322
                        
320
                    case STATE_MAYBE_BLOCK_COMMENT:
323
                    case STATE_MAYBE_BLOCK_COMMENT:
321
                        if (ch == '*') {
324
                        if (ch == '*') {
325
                            commentStart = pos + 1;
322
                            state = STATE_BLOCK_COMMENT;
326
                            state = STATE_BLOCK_COMMENT;
323
                        } else {
327
                        } else {
324
                            statement.append('/'); // previous char
328
                            statement.append('/'); // previous char
Lines 337-342 Link Here
337
                        
341
                        
338
                    case STATE_MAYBE_END_BLOCK_COMMENT:
342
                    case STATE_MAYBE_END_BLOCK_COMMENT:
339
                        if (ch == '/') {
343
                        if (ch == '/') {
344
                            checkForDelimiterStmt(commentStart, pos - 2);
340
                            state = STATE_MEANINGFUL_TEXT;
345
                            state = STATE_MEANINGFUL_TEXT;
341
                            // avoid writing the final / to the result
346
                            // avoid writing the final / to the result
342
                            pos++;
347
                            pos++;
Lines 438-444 Link Here
438
        private static boolean isEndStringQuoteChar(int start, int end) {
443
        private static boolean isEndStringQuoteChar(int start, int end) {
439
            return isStartStringQuoteChar(start) && end == getMatchingQuote(start);
444
            return isStartStringQuoteChar(start) && end == getMatchingQuote(start);
440
        }
445
        }
441
446
        
442
        /**
447
        /**
443
         * See if the user wants to use a different delimiter for splitting
448
         * See if the user wants to use a different delimiter for splitting
444
         * up statements.  This is useful if, for example, their SQL contains
449
         * up statements.  This is useful if, for example, their SQL contains
Lines 486-491 Link Here
486
            return true;
491
            return true;
487
        }
492
        }
488
        
493
        
494
        /**
495
         * Check for Delimiter Statement in comment.
496
         * 
497
         * Simulates regular behaviour found in checkDelimiterStatement
498
         */
499
        private void checkForDelimiterStmt(int start, int end) {
500
            while(Character.isWhitespace(sql.charAt(start)) && start < end) {
501
                start++;
502
            }
503
            if(start >= end && (end - start + 1) <= DELIMITER_TOKEN.length()) {
504
                return;
505
            }
506
            boolean delimiterMatched = true;
507
            for(int i = 0; i < DELIMITER_TOKEN.length(); i++) {
508
                if(Character.toUpperCase(sql.charAt(start)) != 
509
                        Character.toUpperCase(DELIMITER_TOKEN.charAt(i))) {
510
                    delimiterMatched = false;
511
                    break;
512
                }
513
                start++;
514
            }
515
            if(! delimiterMatched) {
516
                return;
517
            }
518
            while (Character.isWhitespace(sql.charAt(start)) && start < end) {
519
                start++;
520
            }
521
            StringBuilder sb = new  StringBuilder();
522
            for(int i = start; i <= end; i++) {
523
                if(! Character.isWhitespace(sql.charAt(i))) {
524
                    sb.append(sql.charAt(i));
525
                } else {
526
                    break;
527
                }
528
            }
529
            if(sb.length() > 0) {
530
                delimiter = sb.toString();
531
            }
532
        }
533
        
489
        private void skipWhitespace() {
534
        private void skipWhitespace() {
490
            while ( pos < sqlLength && Character.isWhitespace(sql.charAt(pos)) ) {
535
            while ( pos < sqlLength && Character.isWhitespace(sql.charAt(pos)) ) {
491
                nextColumn();
536
                nextColumn();
(-)a/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java (+31 lines)
Lines 161-166 Link Here
161
        );
161
        );
162
    }
162
    }
163
    
163
    
164
    public void testDelimiterComment() {
165
        // See bug #234246)
166
        // Block comment
167
        assertSplit("SELECT * FROM a;SELECT * FROM b/*DELIMITER //*///"
168
                + "SELECT * FROM a//SELECT * FROM b"
169
                , "SELECT * FROM a"
170
                , "SELECT * FROM b"
171
                , "SELECT * FROM a"
172
                , "SELECT * FROM b");
173
        // Line comment
174
        assertSplit("SELECT * FROM a;\n"
175
                + "SELECT * FROM b\n"
176
                + "--   DELIMITER //\n"
177
                + "//"
178
                + "SELECT * FROM a//\n"
179
                + "SELECT * FROM b"
180
                , "SELECT * FROM a"
181
                , "SELECT * FROM b"
182
               , "SELECT * FROM a", "SELECT * FROM b");
183
        // Block comment
184
        assertSplit("/*DELIMITER --*--*/\n"
185
                + "SELECT * FROM a\n"
186
                + "--*--"
187
                + "SELECT * FROM b\n"
188
                , "SELECT * FROM a"
189
                , "SELECT * FROM b");
190
        // Guard against problems at line end
191
        assertSplit("SELECT * FROM b/*DELIMITER --*--*/", "SELECT * FROM b");
192
        assertSplit("SELECT * FROM b--DELIMITER --*--", "SELECT * FROM b");
193
    }
194
    
164
    private static void assertSplit(String script, String... expected) {
195
    private static void assertSplit(String script, String... expected) {
165
        assertSplit(script, true, expected);
196
        assertSplit(script, true, expected);
166
    }
197
    }

Return to bug 234246