From 9de84f88c72bdead3bf9fbd09b581a11be839dd9 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sat, 7 Jul 2001 10:22:23 +0000 Subject: [PATCH] Add support for delimiter type. Base don the ideas contained in the bugzilla report suggested by johan.adelow@corustechnologies.com (Johan Adelow) PR: 273 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269283 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/SQLExec.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index 1636d7804..f1f872866 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -74,6 +74,15 @@ import java.sql.*; * @author Michael McCallum */ public class SQLExec extends Task { + + static public class DelimiterType extends EnumeratedAttribute { + static public final String NORMAL = "normal"; + static public final String ROW = "row"; + public String[] getValues() { + return new String[] {NORMAL, ROW}; + } + } + private int goodSql = 0, totalSql = 0; @@ -136,6 +145,12 @@ public class SQLExec extends Task { */ private String delimiter = ";"; + /** + * The delimiter type indicating whether the delimiter will + * only be recognized on a line by itself + */ + private String delimiterType = DelimiterType.NORMAL; + /** * Print SQL results. */ @@ -259,6 +274,16 @@ public class SQLExec extends Task { this.delimiter = delimiter; } + /** + * Set the Delimiter type for this sql task. The delimiter type takes + * two values - normal and row. Normal means that any occurence of the delimiter + * terminate the SQL command whereas with row, only a line containing just the + * delimiter is recognized as the end of the command. + */ + public void setDelimiterType(DelimiterType delimiterType) { + this.delimiterType = delimiterType.getValue(); + } + /** * Set the print flag. */ @@ -441,9 +466,8 @@ public class SQLExec extends Task { line = line.trim(); if (line.startsWith("//")) continue; if (line.startsWith("--")) continue; - if ( line.length() > 2 ) { - if (line.substring(0,3).equalsIgnoreCase("REM")) continue; - } + if (line.length() > 2 && + line.substring(0,3).equalsIgnoreCase("REM")) continue; sql += " " + line; sql = sql.trim(); @@ -453,9 +477,10 @@ public class SQLExec extends Task { // so we cannot just remove it, instead we must end it if (line.indexOf("--") >= 0) sql += "\n"; - if (sql.endsWith(delimiter)){ + if (delimiterType.equals(DelimiterType.NORMAL) && sql.endsWith(delimiter) || + delimiterType.equals(DelimiterType.ROW) && line.equals(delimiter)) { log("SQL: " + sql, Project.MSG_VERBOSE); - execSQL(sql.substring(0, sql.length()-1), out); + execSQL(sql.substring(0, sql.length() - delimiter.length()), out); sql = ""; } }