You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Pradeep.C" <pr...@yahoo.com> on 2009/04/09 13:36:27 UTC

Ant sql task fails while executing insert statement containg string description with "--"

Hi There,
I am trying to execute *.sql file containing insert statements using ant
<sql> task onto the DB2 database. The build is failing for me as one of the
insert statement in *.sql has a string description with "--" charters init.

My insert statement looks something like this:

INSERT INTO TableItem (TABLENAME, CODE, DESCRIPTION, ANNOTATION, ISENABLED,
SORTORDER, LOCALEIDENTIFIER, LASTWRITTEN, VERSIONNO) VALUES ('TestTable',
'TT1', 'Common -- Test', '', '1', 0, 'en', CURRENT TIMESTAMP, 1);

And the build error I get:

[sql] Failed to execute: INSERT INTO TableItem (TABLENAME, CODE,
DESCRIPTION, ANNOTATION, ISENABLED, SORTORDER, LOCALEIDENTIFIER,
LASTWRITTEN, VERSIONNO) VALUES ('TestTable', 'TT1000', 'Common -- Test', '',
'1', 0, 'en', CURRENT TIMESTAMP, 1);
[sql] INSERT INTO TableHeader (TableName, TimeEntered, DefaultCode,
LASTWRITTEN, VERSIONNO) VALUES ('TestTable', CURRENT TIMESTAMP, '', CURRENT
TIMESTAMP, 1)
Build Failed:
c:\project\development\EJBServer\bin\app_database.xml:232:
com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE:
42601, SQLERRMC: ('TestTable', 'TT1000', 'Common -- Te;N, VERSIONNO)
VALUES;<space>

But if I execute this insert statement from the DB2 command prompt, it is
getting executed successfully.

Can you please help me in finding the reason for this please?

Cheers,
Pradeep
-- 
View this message in context: http://www.nabble.com/Ant-sql-task-fails-while-executing-insert-statement-containg-string-description-with-%22--%22-tp22969153p22969153.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Ant sql task fails while executing insert statement containg string description with "--"

Posted by AcO6 <al...@de.pwc.com>.
Hi Pradeep,


Pradeep.C wrote:
> 
> Hi There,
> I am trying to execute *.sql file containing insert statements using ant
> <sql> task onto the DB2 database. The build is failing for me as one of
> the insert statement in *.sql has a string description with "--" charters
> init.
> 
> My insert statement looks something like this:
> 
> INSERT INTO TableItem (TABLENAME, CODE, DESCRIPTION, ANNOTATION,
> ISENABLED, SORTORDER, LOCALEIDENTIFIER, LASTWRITTEN, VERSIONNO) VALUES
> ('TestTable', 'TT1', 'Common -- Test', '', '1', 0, 'en', CURRENT
> TIMESTAMP, 1);
> 
> But if I execute this insert statement from the DB2 command prompt, it is
> getting executed successfully.
> 
> Can you please help me in finding the reason for this please?
> 
> Cheers,
> Pradeep
> 

I had the same problem:

INSERT INTO TBU (PERIODID,BUID,NAME,ARCHIVE) VALUES (0,'---','---',0);

failed, because of the "--" in the statement.

Looking at the target source:
org.apache.tools.ant.taskdefs.SQLExec.runStatements() - Line 527
the solution is quite simple:



> // SQL defines "--" as a comment to EOL
> // and in Oracle it may contain a hint
> // so we cannot just remove it, instead we must end it
> if (!keepformat && line.indexOf("--") >= 0) {
>     sql.append("\n");
> }
> 

I used keepformat="true" and removed all comments from the SQL-Script.
Work's fine :)

Regards,
AcO6
-- 
View this message in context: http://www.nabble.com/Ant-sql-task-fails-while-executing-insert-statement-containg-string-description-with-%22--%22-tp22969153p23423228.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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