You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Julian M. Savage" <js...@fisci.com> on 2000/11/01 03:53:15 UTC

Re: Ant sql task print

Johan,

I added the ability to do printing from this task, and it works fine for me,
using Sybase (I use it on a regular basis). I think that Stefan tested it
with FreeTDS, Interbase and DB2 before he cleaned it up and checked it in. I
don't know what to suggest, except I'm curious to know if this problem
occurs when you don't try to print the results.

As another point, I did notice when reviewing the code that this task
doesn't close the PrintStream if there is an IOException, which I understand
from traffic on the developers list might be a particular problem for
Windows users (and perhaps is bad form even under unix). Fixing this would
be a two line change I guess - just move the close of out from within the
finally clause to just after the while() loop, like this:
Index: SQLExec.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.j
ava,v
retrieving revision 1.9
diff -u -r1.9 SQLExec.java
--- SQLExec.java        2000/09/29 15:51:13     1.9
+++ SQLExec.java        2000/11/01 02:38:12
@@ -548,10 +548,8 @@
         catch (IOException ioe) {
             throw new BuildException("Error writing " +
output.getAbsolutePath(), ioe, location);
         }
-        finally {
-            if (out != null && out != System.out) {
-                out.close();
-            }
+        if (out != null && out != System.out) {
+            out.close();
         }
     }

Julian.

----- Original Message -----
From: "Johan Adelöw" <jo...@corustechnologies.com>
To: "ant user mailing list" <an...@jakarta.apache.org>
Sent: Tuesday, October 31, 2000 9:38 PM
Subject: Ant sql task print


> There must be som kind of bug in the printResults() method in the sql task
i
> ant.
>
> A simple sql statement that returns a table name and writes it to file
(like
> below)
>
> <sql driver="oracle.jdbc.driver.OracleDriver"
> url="jdbc:oracle:thin:@dogbert:1521:repbld" userid="rep" password="rep"
> showheaders="false" print="true"
>  output="print.txt">
> select table_name from user_tables where table_name
> like '%OGO_DATA%' ;
> </sql>
>
> Results in the following error:
>
>
> BUILD FAILED
>
> test.xml:11: java.sql.SQLException: ORA-01009: missing mandatory parameter
>
> java.sql.SQLException: ORA-01009: missing mandatory parameter
>
>         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java)
>         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java)
>         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java)
>         at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java)
>         at oracle.jdbc.driver.OracleResultSet.next(OracleResultSet.java)
>         at
> org.apache.tools.ant.taskdefs.SQLExec.printResults(SQLExec.java:539)
>         at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:496)
>         at
> org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:425)
>         at
>
org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.jav
> a:592)
>         at
>
org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$0(SQLExec.java:589)
>         at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:366)
>         at org.apache.tools.ant.Target.execute(Target.java:142)
>         at org.apache.tools.ant.Project.runTarget(Project.java:818)
>         at org.apache.tools.ant.Project.executeTarget(Project.java:532)
>         at org.apache.tools.ant.Project.executeTargets(Project.java:506)
>         at org.apache.tools.ant.Main.runBuild(Main.java:420)
>         at org.apache.tools.ant.Main.main(Main.java:149)
>
> It seems that when the writing to file is finished the statement
> "rs = statement.getResultSet()) != null" should be null but
> isn't (525) and when doing
> "rs.next()"     (539) the program fails.
>
> Does any body konw anything about this? Is the print function of the sql
> task tested by anyone?
>
>
>
> *************************************************
>
> ________________________________________________
>
> E-mail: johan.adelow@corustechnologies.com
> Direct: +46-8-678 80 60
> Mobile: +46-70-563 13 97
> Office: +46-8-4403860 (Always open)
> Home page: www.corustechnologies.com
> _________________________________________________
>
>
>


RE: Ant sql task print

Posted by Conor MacNeill <co...@ebinteractive.com.au>.
OK, I think I have fixed this. It now works under Oracle. Can someone check
it under the other databases. The main change is to take the result of
getMoreResults into account. Since this is returning false under Oracle,
presumably you shouldn't call getResultSet(), although as I read the javadoc
it should be OK.

I also noticed that if I had two statements in the SQL, only the last is
written to the file. I haven't fixed that yet.

I did fix the printing of NULL columns though.

Conor

--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: Julian M. Savage [mailto:jsavage@fisci.com]
> Sent: Wednesday, 1 November 2000 13:53
> To: ant-user@jakarta.apache.org; ant-dev@jakarta.apache.org
> Subject: Re: Ant sql task print
>
>
> Johan,
>
> I added the ability to do printing from this task, and it works
> fine for me,
> using Sybase (I use it on a regular basis). I think that Stefan tested it
> with FreeTDS, Interbase and DB2 before he cleaned it up and
> checked it in. I
> don't know what to suggest, except I'm curious to know if this problem
> occurs when you don't try to print the results.
>
> As another point, I did notice when reviewing the code that this task
> doesn't close the PrintStream if there is an IOException, which I
> understand
> from traffic on the developers list might be a particular problem for
> Windows users (and perhaps is bad form even under unix). Fixing this would
> be a two line change I guess - just move the close of out from within the
> finally clause to just after the while() loop, like this:
> Index: SQLExec.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs
> /SQLExec.j
> ava,v
> retrieving revision 1.9
> diff -u -r1.9 SQLExec.java
> --- SQLExec.java        2000/09/29 15:51:13     1.9
> +++ SQLExec.java        2000/11/01 02:38:12
> @@ -548,10 +548,8 @@
>          catch (IOException ioe) {
>              throw new BuildException("Error writing " +
> output.getAbsolutePath(), ioe, location);
>          }
> -        finally {
> -            if (out != null && out != System.out) {
> -                out.close();
> -            }
> +        if (out != null && out != System.out) {
> +            out.close();
>          }
>      }
>
> Julian.
>
> ----- Original Message -----
> From: "Johan Adelöw" <jo...@corustechnologies.com>
> To: "ant user mailing list" <an...@jakarta.apache.org>
> Sent: Tuesday, October 31, 2000 9:38 PM
> Subject: Ant sql task print
>
>
> > There must be som kind of bug in the printResults() method in
> the sql task
> i
> > ant.
> >
> > A simple sql statement that returns a table name and writes it to file
> (like
> > below)
> >
> > <sql driver="oracle.jdbc.driver.OracleDriver"
> > url="jdbc:oracle:thin:@dogbert:1521:repbld" userid="rep" password="rep"
> > showheaders="false" print="true"
> >  output="print.txt">
> > select table_name from user_tables where table_name
> > like '%OGO_DATA%' ;
> > </sql>
> >
> > Results in the following error:
> >
> >
> > BUILD FAILED
> >
> > test.xml:11: java.sql.SQLException: ORA-01009: missing
> mandatory parameter
> >
> > java.sql.SQLException: ORA-01009: missing mandatory parameter
> >
> >         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java)
> >         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java)
> >         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java)
> >         at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java)
> >         at oracle.jdbc.driver.OracleResultSet.next(OracleResultSet.java)
> >         at
> > org.apache.tools.ant.taskdefs.SQLExec.printResults(SQLExec.java:539)
> >         at
> org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:496)
> >         at
> > org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:425)
> >         at
> >
> org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(S
> QLExec.jav
> > a:592)
> >         at
> >
> org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$0(SQLExec
> .java:589)
> >         at
> org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:366)
> >         at org.apache.tools.ant.Target.execute(Target.java:142)
> >         at org.apache.tools.ant.Project.runTarget(Project.java:818)
> >         at org.apache.tools.ant.Project.executeTarget(Project.java:532)
> >         at org.apache.tools.ant.Project.executeTargets(Project.java:506)
> >         at org.apache.tools.ant.Main.runBuild(Main.java:420)
> >         at org.apache.tools.ant.Main.main(Main.java:149)
> >
> > It seems that when the writing to file is finished the statement
> > "rs = statement.getResultSet()) != null" should be null but
> > isn't (525) and when doing
> > "rs.next()"     (539) the program fails.
> >
> > Does any body konw anything about this? Is the print function of the sql
> > task tested by anyone?
> >
> >
> >
> > *************************************************
> >
> > ________________________________________________
> >
> > E-mail: johan.adelow@corustechnologies.com
> > Direct: +46-8-678 80 60
> > Mobile: +46-70-563 13 97
> > Office: +46-8-4403860 (Always open)
> > Home page: www.corustechnologies.com
> > _________________________________________________
> >
> >
> >
>
>


RE: Ant sql task print

Posted by Conor MacNeill <co...@ebinteractive.com.au>.
OK, I think I have fixed this. It now works under Oracle. Can someone check
it under the other databases. The main change is to take the result of
getMoreResults into account. Since this is returning false under Oracle,
presumably you shouldn't call getResultSet(), although as I read the javadoc
it should be OK.

I also noticed that if I had two statements in the SQL, only the last is
written to the file. I haven't fixed that yet.

I did fix the printing of NULL columns though.

Conor

--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: Julian M. Savage [mailto:jsavage@fisci.com]
> Sent: Wednesday, 1 November 2000 13:53
> To: ant-user@jakarta.apache.org; ant-dev@jakarta.apache.org
> Subject: Re: Ant sql task print
>
>
> Johan,
>
> I added the ability to do printing from this task, and it works
> fine for me,
> using Sybase (I use it on a regular basis). I think that Stefan tested it
> with FreeTDS, Interbase and DB2 before he cleaned it up and
> checked it in. I
> don't know what to suggest, except I'm curious to know if this problem
> occurs when you don't try to print the results.
>
> As another point, I did notice when reviewing the code that this task
> doesn't close the PrintStream if there is an IOException, which I
> understand
> from traffic on the developers list might be a particular problem for
> Windows users (and perhaps is bad form even under unix). Fixing this would
> be a two line change I guess - just move the close of out from within the
> finally clause to just after the while() loop, like this:
> Index: SQLExec.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs
> /SQLExec.j
> ava,v
> retrieving revision 1.9
> diff -u -r1.9 SQLExec.java
> --- SQLExec.java        2000/09/29 15:51:13     1.9
> +++ SQLExec.java        2000/11/01 02:38:12
> @@ -548,10 +548,8 @@
>          catch (IOException ioe) {
>              throw new BuildException("Error writing " +
> output.getAbsolutePath(), ioe, location);
>          }
> -        finally {
> -            if (out != null && out != System.out) {
> -                out.close();
> -            }
> +        if (out != null && out != System.out) {
> +            out.close();
>          }
>      }
>
> Julian.
>
> ----- Original Message -----
> From: "Johan Adelöw" <jo...@corustechnologies.com>
> To: "ant user mailing list" <an...@jakarta.apache.org>
> Sent: Tuesday, October 31, 2000 9:38 PM
> Subject: Ant sql task print
>
>
> > There must be som kind of bug in the printResults() method in
> the sql task
> i
> > ant.
> >
> > A simple sql statement that returns a table name and writes it to file
> (like
> > below)
> >
> > <sql driver="oracle.jdbc.driver.OracleDriver"
> > url="jdbc:oracle:thin:@dogbert:1521:repbld" userid="rep" password="rep"
> > showheaders="false" print="true"
> >  output="print.txt">
> > select table_name from user_tables where table_name
> > like '%OGO_DATA%' ;
> > </sql>
> >
> > Results in the following error:
> >
> >
> > BUILD FAILED
> >
> > test.xml:11: java.sql.SQLException: ORA-01009: missing
> mandatory parameter
> >
> > java.sql.SQLException: ORA-01009: missing mandatory parameter
> >
> >         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java)
> >         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java)
> >         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java)
> >         at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java)
> >         at oracle.jdbc.driver.OracleResultSet.next(OracleResultSet.java)
> >         at
> > org.apache.tools.ant.taskdefs.SQLExec.printResults(SQLExec.java:539)
> >         at
> org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:496)
> >         at
> > org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:425)
> >         at
> >
> org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(S
> QLExec.jav
> > a:592)
> >         at
> >
> org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$0(SQLExec
> .java:589)
> >         at
> org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:366)
> >         at org.apache.tools.ant.Target.execute(Target.java:142)
> >         at org.apache.tools.ant.Project.runTarget(Project.java:818)
> >         at org.apache.tools.ant.Project.executeTarget(Project.java:532)
> >         at org.apache.tools.ant.Project.executeTargets(Project.java:506)
> >         at org.apache.tools.ant.Main.runBuild(Main.java:420)
> >         at org.apache.tools.ant.Main.main(Main.java:149)
> >
> > It seems that when the writing to file is finished the statement
> > "rs = statement.getResultSet()) != null" should be null but
> > isn't (525) and when doing
> > "rs.next()"     (539) the program fails.
> >
> > Does any body konw anything about this? Is the print function of the sql
> > task tested by anyone?
> >
> >
> >
> > *************************************************
> >
> > ________________________________________________
> >
> > E-mail: johan.adelow@corustechnologies.com
> > Direct: +46-8-678 80 60
> > Mobile: +46-70-563 13 97
> > Office: +46-8-4403860 (Always open)
> > Home page: www.corustechnologies.com
> > _________________________________________________
> >
> >
> >
>
>