You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2007/03/14 00:16:55 UTC

DO NOT REPLY [Bug 41836] New: - No warning from SQL task, but jdbc gets SQL State: 23000

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=41836>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=41836

           Summary: No warning from SQL task, but jdbc gets SQL State: 23000
           Product: Ant
           Version: 1.6.5
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
        AssignedTo: dev@ant.apache.org
        ReportedBy: apache@digicoast.com
                CC: apache@digicoast.com


There is a specific warning that I was expecting after a flawed SQL statement 
was executed but Ant executes the statement and reports "1 of 1 SQL statements 
executed successfully".   

A java stub that tests the same query gets:
SQL Warning:
Column 'col1' in group statement is ambiguous
ANSI-92 SQL State: 23000
Vendor Error Code: 1052

This is with MySQL Server 5.0.22, with MySQL Connector/J v5.0.5.

$ msyql -uroot -p

mysql> create schema test;
mysql> create table test.x (id int);
mysql> create table test.y (id int, col1 varchar(10));
mysql> quit;

# Do not forget to set classpath to include mysql-connector jar 
# 

$ javac JDBCTestErr1052.java
$ java JDBCTestErr1052

query:select 'test' as col1 from test.x inner join test.y on (y.id = 1) group 
by col1

SQL Warning:
Column 'col1' in group statement is ambiguous
ANSI-92 SQL State: 23000
Vendor Error Code: 1052

$ cat JDBCTestErr1052.java
import java.sql.*;

public class JDBCTestErr1052 {
    private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    private static final String JDBC_URL    = "jdbc:mysql://localhost/";
    private static final String JDBC_USER   = "root";
    private static final String JDBC_PASS   = "blah";

    private static final String query =
     "select 'test' as col1 from test.x inner join test.y on (y.id = 1) group 
by col1";

    public static void printWarnings(SQLWarning warn) {
      while (warn != null) {
        System.out.println("\nSQL Warning:");
        System.out.println(warn.getMessage(  ));
        System.out.println("ANSI-92 SQL State: " + warn.getSQLState(  ));
        System.out.println("Vendor Error Code: " + warn.getErrorCode(  ));
        warn = warn.getNextWarning(  );
      }
    }

    public static void main(String[] args) throws Throwable {
        System.out.println("query:"+query);

        Class.forName(JDBC_DRIVER).newInstance();
        Connection conn = 
DriverManager.getConnection(JDBC_URL,JDBC_USER,JDBC_PASS);

        try {
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(query);

            printWarnings(st.getWarnings());
            printWarnings(rs.getWarnings());

            rs.close();
            st.close();
        }
        catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


DO NOT REPLY [Bug 41836] - No warning from SQL task, but jdbc gets SQL State: 23000

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=41836>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=41836





------- Additional Comments From stevel@apache.org  2007-03-14 04:16 -------
I think the problem here is that <sql> on cares about errors; it doesnt look for
and print warnings. We could correct this in two ways

1. log the warnings at INFO or WARN
2. add a failOnWarning attribute to trigger behaviour on warnings

Would this work?

As an aside, we have zero unit tests against mysql, but as I've been automating
deployment of mysql at work, I may know how we could do this, though the test
setup would be tricky indeed. We'd need JMX, the (GPL) Mysql JMX connector, and
SmartFrog, plus the configuration info for the target test system(s), and we'd
need to get smartfrog to run an antunit build file. Much, much easier to test
against HSQLDB instead.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


DO NOT REPLY [Bug 41836] - No warning from SQL task, but jdbc gets SQL State: 23000

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=41836>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=41836





------- Additional Comments From apache@digicoast.com  2007-03-14 15:22 -------
> it doesnt look for and print warnings.

I see.   Since Ant was displaying data truncate warnings as errors I was 
assuming it was already behaving as if there was a "failOnWarning".  But what 
appears to actually be happening is that MySQL jdbc Connector/J already 
escalates these types of MySQL warnings into JDBC errors.

When I add jdbcCompliantTruncation=false to the jdbc connection string (e.g., 
"jdbc:mysql://localhost/?jdbcCompliantTruncation=false)" and issue a statement 
that causes a MySQL Warning, I now get a warning in Java (versus an exception 
when jdbcCompliantTruncation=true), but Ant does not show the warning at all -- 
which is the behavior you described.

> 1. log the warnings at INFO or WARN
> 2. add a failOnWarning attribute to trigger behaviour on warnings
> Would this work?

Yes, those would solve the problem for me.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org