ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John H. Lee" <j...@c.kiracom.com>
Subject [PATCH] SQLExec NullPointerException plus Filtering
Date Wed, 26 Jul 2000 01:16:54 GMT

Fixes bugs listed in previous [PATCH] message and allows filtering of
<sql> input file.  Project.replace() made public...problems with this?

-John



Index: SQLExec.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v

retrieving revision 1.3
diff -u -r1.3 SQLExec.java
--- SQLExec.java        2000/07/25 13:55:07     1.3
+++ SQLExec.java        2000/07/26 01:12:22
@@ -116,7 +116,19 @@
      * SQL input command
      */
     private String sqlCommand = "";
-
+
+    /**
+     * SQL input file property filtering
+     */
+    private boolean filtering = false;
+
+    /**
+     * Turn filtering on/off
+     */
+    public void setFiltering(String filter) {
+        filtering = Project.toBoolean(filter);
+    }
+
     /**
      * Set the name of the sql file to be run.
      */
@@ -170,7 +182,6 @@
      * Load the sql file and then execute it
      */
     public void execute() throws BuildException {
-        Connection conn = null;

         sqlCommand = sqlCommand.trim();

@@ -200,10 +211,11 @@
         }

         try{
-            conn.setAutoCommit(autocommit);
-
             log("connecting to " + url, Project.MSG_VERBOSE );
             conn = DriverManager.getConnection(url, userId, password);
+
+            conn.setAutoCommit(autocommit);
+
             statement = conn.createStatement();

             if (sqlCommand.length() != 0) {
@@ -258,7 +270,11 @@
             while ((line=in.readLine()) != null){
                 if (line.trim().startsWith("//")) continue;
                 if (line.trim().startsWith("--")) continue;
-
+
+                if (filtering) {
+                    line = project.replace(line, project.getFilters());

+                }
+
                 sql += " " + line;
                 if (sql.trim().endsWith(";")){
                     log("SQL: " + sql, Project.MSG_VERBOSE);





Index: Project.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v

retrieving revision 1.32
diff -u -r1.32 Project.java
--- Project.java        2000/07/21 14:24:35     1.32
+++ Project.java        2000/07/26 01:16:32
@@ -661,7 +661,7 @@
      *
      * @returns the string with the token replaced.
      */
-    private String replace(String s, Hashtable tokens) {
+    public String replace(String s, Hashtable tokens) {
         int index = s.indexOf(TOKEN_START);

         if (index > -1) {


Mime
View raw message