Lines 74-79
Link Here
|
74 |
*/ |
74 |
*/ |
75 |
public class SQLExec extends JDBCTask { |
75 |
public class SQLExec extends JDBCTask { |
76 |
|
76 |
|
|
|
77 |
private static final char QUOTE = '\''; |
78 |
|
77 |
/** |
79 |
/** |
78 |
* delimiters we support, "normal" and "row" |
80 |
* delimiters we support, "normal" and "row" |
79 |
*/ |
81 |
*/ |
Lines 428-450
Link Here
|
428 |
|
430 |
|
429 |
BufferedReader in = new BufferedReader(reader); |
431 |
BufferedReader in = new BufferedReader(reader); |
430 |
|
432 |
|
|
|
433 |
// used to determine if the current line |
434 |
// is in a quoted expression. If so then |
435 |
// the delimeter is considered part of the |
436 |
// expression and not the end of the statement. |
437 |
boolean inExpression = false; |
438 |
|
431 |
while ((line = in.readLine()) != null) { |
439 |
while ((line = in.readLine()) != null) { |
|
|
440 |
// flag whether the current line is a comment |
441 |
// or not. |
442 |
boolean isComment = false; |
443 |
|
432 |
if (!keepformat) { |
444 |
if (!keepformat) { |
433 |
line = line.trim(); |
445 |
line = line.trim(); |
434 |
} |
446 |
} |
435 |
line = getProject().replaceProperties(line); |
447 |
line = getProject().replaceProperties(line); |
436 |
if (!keepformat) { |
|
|
437 |
if (line.startsWith("//")) { |
448 |
if (line.startsWith("//")) { |
|
|
449 |
if (!keepformat) { |
438 |
continue; |
450 |
continue; |
|
|
451 |
}else{ |
452 |
isComment = true; |
453 |
} |
439 |
} |
454 |
} |
440 |
if (line.startsWith("--")) { |
455 |
if (line.startsWith("--")) { |
|
|
456 |
if (!keepformat) { |
441 |
continue; |
457 |
continue; |
|
|
458 |
}else{ |
459 |
isComment = true; |
460 |
} |
442 |
} |
461 |
} |
443 |
StringTokenizer st = new StringTokenizer(line); |
462 |
StringTokenizer st = new StringTokenizer(line); |
444 |
if (st.hasMoreTokens()) { |
463 |
if (st.hasMoreTokens()) { |
445 |
String token = st.nextToken(); |
464 |
String token = st.nextToken(); |
446 |
if ("REM".equalsIgnoreCase(token)) { |
465 |
if ("REM".equalsIgnoreCase(token)) { |
|
|
466 |
if (!keepformat) { |
447 |
continue; |
467 |
continue; |
|
|
468 |
}else{ |
469 |
isComment = true; |
470 |
} |
448 |
} |
471 |
} |
449 |
} |
472 |
} |
450 |
} |
473 |
} |
Lines 463-470
Link Here
|
463 |
sql.append("\n"); |
485 |
sql.append("\n"); |
464 |
} |
486 |
} |
465 |
} |
487 |
} |
|
|
488 |
|
489 |
// determine if a quoted expression has started or ended. |
490 |
if(!isComment && containsExpression(line)){ |
491 |
inExpression = !inExpression; |
492 |
} |
493 |
|
466 |
if ((delimiterType.equals(DelimiterType.NORMAL) |
494 |
if ((delimiterType.equals(DelimiterType.NORMAL) |
467 |
&& sql.toString().endsWith(delimiter)) |
495 |
&& sql.toString().endsWith(delimiter) |
|
|
496 |
&& !inExpression) |
468 |
|| |
497 |
|| |
469 |
(delimiterType.equals(DelimiterType.ROW) |
498 |
(delimiterType.equals(DelimiterType.ROW) |
470 |
&& line.equals(delimiter))) { |
499 |
&& line.equals(delimiter))) { |
Lines 479-484
Link Here
|
479 |
} |
508 |
} |
480 |
} |
509 |
} |
481 |
|
510 |
|
|
|
511 |
/** |
512 |
* Determines if the supplied line starts or ends |
513 |
* a quoted expression. |
514 |
* <p/> |
515 |
* To determine if an expression is started or ended |
516 |
* we simply check if an odd number of quotes |
517 |
* exists. (escaped quotes come in pairs, so that |
518 |
* shouldn't be a problem). |
519 |
* |
520 |
* @param line The line to test. |
521 |
* @return true if an expression has begun or ended, false otherwise. |
522 |
*/ |
523 |
protected boolean containsExpression (String line) |
524 |
{ |
525 |
if(line != null && line.trim().length() > 0){ |
526 |
int quoteCount = 0; |
527 |
char[] chars = line.toCharArray(); |
528 |
for(int ii = 0; ii < chars.length; ii++){ |
529 |
if(chars[ii] == QUOTE){ |
530 |
quoteCount++; |
531 |
} |
532 |
} |
533 |
|
534 |
if(quoteCount % 2 == 1){ |
535 |
return true; |
536 |
} |
537 |
} |
538 |
|
539 |
return false; |
540 |
} |
541 |
|
482 |
|
542 |
|
483 |
/** |
543 |
/** |
484 |
* Exec the sql statement. |
544 |
* Exec the sql statement. |