You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Kasatkin Konstantin <KV...@estylesoft.com> on 2006/10/10 09:11:08 UTC

Problem to get the final SQL query text from the DaoTemplate

Hello guys, 
I've been using iBatis about a year and had no problems till now. 
I have an following issue (I'll begin at the root problem): 

I use MySQL server as DB engine, it produces messages like "Duplicate entry 'SOME VALUE' for key 3" 
on unique constraints. The problem is, if I have, for instance, three unique indices in one table. 
I perform INSERT query that populates all the fields by record, then I catch exception and realise
there is no way to know, whick index has generated the message. I only see its number.

If I've had the possibility to get the text of the sql statement that has jast executed I could
extract Table Name from it, return key sequence for this table and find out the name of
correcponding index.

I've dug the whole source code and couldn't find a way to extract sql query text. 

Maybe there is some way to get the SQL query text from a DaoTemplate? 


Re: Problem to get the final SQL query text from the DaoTemplate

Posted by Jeff Butler <je...@gmail.com>.
There's no public API for retrieving the SQL text.  Part of the issue is
that the text can be variable because of iBATIS' dynamic SQL tags - so the
iBATIS engine potentially re-calculates the text for each query.

In your example - don't you know the table name anyway?  You coded the
statement, so you should know.

If you're trying to do something more general, like a general error handler,
then you could parse the XML file, then parse the SQL.

Jeff Butler
On 10/10/06, Kasatkin Konstantin <KV...@estylesoft.com> wrote:
>
>  Hello guys,
>
> I've been using iBatis about a year and had no problems till now.
> I have an following issue (I'll begin at the root problem):
>
> I use MySQL server as DB engine, it produces messages like "Duplicate
> entry 'SOME VALUE' for key 3"
>
> on unique constraints. The problem is, if I have, for instance, three
> unique indices in one table.
> I perform INSERT query that populates all the fields by record, then I
> catch exception and realise there is no way to know, whick index has
> generated the message. I only see its number.
>
> If I've had the possibility to get the text of the sql statement that has
> jast executed I could extract Table Name from it, return key sequence for
> this table and find out the name of correcponding index.
>
> I've dug the whole source code and couldn't find a way to extract sql
> query text.
>
> Maybe there is some way to get the SQL query text from a DaoTemplate?
>
>