Hi Diego,
I agree (it was my first assumption, server doesn't send warning if an error 
occurred in a stored procedure).
It’s not only with SIGNAL statement.

Try something like this :
stmt.execute("drop table IF EXISTS t;");
     stmt.execute("create table t (c int);");
     stmt.execute("create or replace procedure pwarning() as\n" +
                  "begin\n" +
                  "  CREATE TABLE `test`.`t` (`c` INT) engine=X ;\n" +
                  "end");
     stmt.execute("call pwarning()");

Show warnings returns:

+---------+------+-------------------------------------------+
| Level   | Code | Message                                   |
+---------+------+-------------------------------------------+
| Warning | 1286 | Unknown storage engine 'X'                |
| Warning | 1266 | Using storage engine InnoDB for table 't' |
| Error   | 1050 | Table 't' already exists                  |
+---------+------+-------------------------------------------+

but JDBC is not aware of the warnings.

Regards,
Jérôme.

De : Diego Dupin [mailto:[email protected]]
Envoyé : mercredi 5 avril 2017 13:08
À : jerome brauge
Cc : Daniel Black; [email protected]
Objet : Re: [Maria-developers] JDBC getWarnings and stored procedure

Hi,

It must be more related to using SIGNAL inside a stored procedure, server 
doesn't send warning to driver in this case.

Warning does inside java connector when server send warning information.
Example :

        try (Statement stmt = sharedConnection.createStatement()) {
            stmt.execute("create or replace procedure pwarning()\n" +
                    "begin\n" +
                    "  DROP TABLE IF EXISTS test.no_such_table;\n" +
                    "end");
            stmt.execute("call pwarning()");
            SQLWarning sqlWarning = stmt.getWarnings();
            Assert.assertNotNull(sqlWarning);
            Assert.assertTrue(sqlWarning.getMessage().contains("Unknown table 
'test.no_such_table'"));
        }

regards,
Diego.

On Wed, Apr 5, 2017 at 8:24 AM, jerome brauge 
<[email protected]<mailto:[email protected]>> wrote:
Hello Daniel,
In fact, getWarnings works fine when there is no error.
The following procedure issues one warning and one error, and in this case 
getWarnings() (called inside SQLException catch) returns null even with 
reenableWarnings().

create or replace procedure pwarning1()
begin
  SIGNAL SQLSTATE '01000';
  RESIGNAL SET MESSAGE_TEXT = 'error message';
end
/

Regards,
Jérôme.



> -----Message d'origine-----
> De : Maria-developers [mailto:maria-developers-<mailto:maria-developers->
> [email protected]<mailto:[email protected]>]
>  De la part de Daniel
> Black
> Envoyé : mercredi 5 avril 2017 03:09
> À : 
> [email protected]<mailto:[email protected]>;
>  Diego Dupin
> Objet : Re: [Maria-developers] JDBC getWarnings and stored procedure
>
>
>
> On 03/04/17 20:21, jerome brauge wrote:
> > Hello,
> >
> > When we call a stored procedure in JDBC which emit warnings,
> > getWarnings() always returns null.
> >
> > I don't really think that the problem is in MariaDB Connector J
> > because warning flag in the EOF packet is not set to true.
> >
>
> hasWarnings is set:
>
> https://github.com/MariaDB/mariadb-connector-
> j/blob/master/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractC
> onnectProtocol.java#L745
>
>
> Its used here:
>
> https://github.com/MariaDB/mariadb-connector-
> j/blob/master/src/main/java/org/mariadb/jdbc/MariaDbConnection.java#L8
> 27
>
> I suspect the bug is warningsCleared has a implicit default of false in the
> above class.
>
> As a workaround check, call reenableWarnings() before getWarnings().
>
> > Mysql client behaves in the same way, by default it shows warnings
> > count issued by DML command but not for stored procedure.
> >
> >
> >
> > Is it a normal behavior ?
> >
> >
> >
> > Best regards,
> >
> > Jérôme.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~maria-developers
> > Post to     : 
> > [email protected]<mailto:[email protected]>
> > Unsubscribe : https://launchpad.net/~maria-developers
> > More help   : https://help.launchpad.net/ListHelp
> >
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~maria-developers
> Post to     : 
> [email protected]<mailto:[email protected]>
> Unsubscribe : https://launchpad.net/~maria-developers
> More help   : https://help.launchpad.net/ListHelp

_______________________________________________
Mailing list: https://launchpad.net/~maria-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to