@@ -71,7 +71,8 @@ import java.sql.*;
* Comments may be created with REM -- or //.
* Comments may be created with REM -- or //.
*
*
* @author <a href="mailto:jeff@custommonkey.org">Jeff Martin</a>
* @author <a href="mailto:jeff@custommonkey.org">Jeff Martin</a>
* @author <A href="gholam@xtra.co.nz">Michael McCallum</A>
* @author <A href="mailto:gholam@xtra.co.nz">Michael McCallum</A>
* @author <A href="mailto:tim.stephenson@sybase.com">Tim Stephenson</A>
*/
*/
public class SQLExec extends Task {
public class SQLExec extends Task {
@@ -90,6 +91,8 @@ public class SQLExec extends Task {
private AntClassLoader loader;
private AntClassLoader loader;
private Vector filesets = new Vector();
/**
/**
* Database connection
* Database connection
*/
*/
@@ -223,13 +226,21 @@ public class SQLExec extends Task {
this.sqlCommand += sql;
this.sqlCommand += sql;
}
}
/**
* Adds a set of files (nested fileset attribute).
*/
public void addFileset(FileSet set) {
filesets.addElement(set);
}
/**
/**
* Set the sql command to execute
* Set the sql command to execute
*/
*/
public Transaction createTransaction() {
public Transaction createTransaction() {
Transaction t = new Transaction();
transactions.addElement(t);
return t;
Transaction t = new Transaction();
transactions.addElement(t);
return t;
}
}
/**
/**
@@ -269,6 +280,9 @@ public class SQLExec extends Task {
/**
/**
* Set the statement delimiter.
* Set the statement delimiter.
*
* <p>For example, set this to "go" and delimitertype to "ROW" for
* Sybase ASE or MS SQL Server.</p>
*/
*/
public void setDelimiter(String delimiter) {
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
this.delimiter = delimiter;
@@ -332,11 +346,26 @@ public class SQLExec extends Task {
public void execute() throws BuildException {
public void execute() throws BuildException {
sqlCommand = sqlCommand.trim();
sqlCommand = sqlCommand.trim();
if (srcFile == null && sqlCommand.length() == 0 ) {
if (srcFile == null && sqlCommand.length()==0 && filesets.isEmpty() ) {
if (transactions.size() == 0) {
if (transactions.size() == 0) {
throw new BuildException("Source file, transactions or sql statement must be set!", location);
throw new BuildException("Source file or fileset , transactions or sql statement must be set!", location);
}
}
} else {
} else {
// deal with the filesets
for (int i=0; i<filesets.size(); i++) {
FileSet fs = (FileSet) filesets.elementAt(i);
DirectoryScanner ds = fs.getDirectoryScanner(project);
File srcDir = fs.getDir(project);
String[] srcFiles = ds.getIncludedFiles();
// Make a transaction for each file
for ( int j=0 ; j<srcFiles.length ; j++ ) {
Transaction t = createTransaction();
t.setSrc(new File(srcDir, srcFiles[j]));
}
}
// Make a transaction group for the outer command
// Make a transaction group for the outer command
Transaction t = createTransaction();
Transaction t = createTransaction();
t.setSrc(srcFile);
t.setSrc(srcFile);