| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

01-28-11, 13:18
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 8
|
|
|
Db2Command with Compound SQL
|
|
I am trying to execute Db2Command where the command text contains 2 blocks of code wrapped with begin atomic example:
--#SET TERMINATOR /
begin atomic
insert into B1.TESTSEQUENCE (AppSequenceId
, AppLocalTime
, AppSynchTime
, Remarks
)
values (@AppSequenceId
, @AppLocalTime
, @AppSynchTime
, @Remarks
)
;
insert into B1.TESTSEQUENCE (AppSequenceId
, AppLocalTime
, AppSynchTime
, Remarks
)
values (@AppSequenceId_a8
, @AppLocalTime
, @AppSynchTime
, @Remarks_a9
)
;
end
/
The error I receive is:
ERROR [42601] [IBM][DB2/NT64] SQL0104N An unexpected token "end / begin " was found following " , ? , ? ) ; ". Expected tokens may include: "<space>". LINE NUMBER=32. SQLSTATE=42601
Can anyone provide insight into the correct syntax for this operation.
Using .Net Framework 4.0 IBM DB2/UDB 9.7.2.2
Thanks
|
|

01-28-11, 14:29
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
You'll need to tell whatever tool you are using that "/" is the statement delimiter. "--#SET TERMINATOR" is only valid for DB2 CLP.
|
|

01-28-11, 15:22
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 8
|
|
|
|
thank you very much. Would you know what the syntax for the Db2Command? Or is it a property of the command or connection?
thanks
|
|

01-28-11, 15:47
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
|
|

01-28-11, 17:22
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 8
|
|
A Db2Command is the object that is used when communicating via .Net (IBM DataProvider). I am working on a windows application that communicates to DB2 via IBM's DataProvider for .Net.
Db2Command is the class that contains the command to be executed.
|
|

01-29-11, 08:36
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
It expects a single statement. You cannot execute multiple statements at once. "begin atomic ... end" is a (compound) statement. "begin atomic ... end / begin" is not.
|
|

02-12-11, 17:46
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 8
|
|
|
solution
Wrap entire block in a BEGIN / END block:
No Terminator char definition needed.
No semicolon need at end of outer begin block, but they are needed
at the end of every begin atomic block.
BEGIN
begin atomic
insert into B1.TESTSEQUENCE (AppSequenceId
, AppLocalTime
, AppSynchTime
, Remarks
)
values (@AppSequenceId
, @AppLocalTime
, @AppSynchTime
, @Remarks
)
;
insert into B1.TESTSEQUENCE (AppSequenceId
, AppLocalTime
, AppSynchTime
, Remarks
)
values (@AppSequenceId_a8
, @AppLocalTime
, @AppSynchTime
, @Remarks_a9
)
;
end ;
END
|
|

02-12-11, 20:33
|
|
Registered User
|
|
Join Date: May 2009
Posts: 472
|
|
apboic, If you have DB2 LUW V9.7 you can Insert both rows with one statement:
Code:
INSERT INTO B1.TESTSEQUENCE
( AppSequenceId
, AppLocalTime
, AppSyncTime
, Remarks)
VALUES( @AppSequenceId
, @AppLocalTime
, @AppSynchTime
, @Remarks
)
,( @AppSequenceId_a8
, @AppLocalTime
, @AppSynchTime
, @Remarks_a9
)
I am not sure when this became available so it may be valid in V9.5 or earlier.
It is only one statement so it should be passed by you DB2Command. And either both rows will be inserted or they won't so it will be an Atomic transaction.
|
|

02-12-11, 21:56
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,195
|
|
I could see multiple rows VALUES clause on DB2 5.2 for UNIX and Windows.
IBM DB2 Universal Database SQL Reference Version 5.2
Quote:
values-clause
Derives a result table by specifying the actual values, using expressions, for each
column of a row in the result table. Multiple rows may be specified.
|
|
|

02-15-11, 15:08
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 8
|
|
Thanks for the help. My original example did not illustrate the complexity of what i was trying to do. I agree, the example could have been down without the begin atomic. However, if I wanted to send multiple transactions in a single Db2Command, then the syntax would be different: This is a working example: (There are 2 transx sent to the db in 1 call)
BEGIN
BEGIN ATOMIC
INSERT INTO B1.TESTSEQUENCE
( AppSequenceId
, AppLocalTime
, AppSyncTime
, Remarks)
VALUES( @AppSequenceId
, @AppLocalTime
, @AppSynchTime
, @Remarks
)
,( @AppSequenceId_a8
, @AppLocalTime
, @AppSynchTime
, @Remarks_a9
);
INSERT INTO B1.TESTSEQUENCE
( AppSequenceId
, AppLocalTime
, AppSyncTime
, Remarks)
VALUES( @AppSequenceId
, @AppLocalTime
, @AppSynchTime
, @Remarks
)
,( @AppSequenceId_a8
, @AppLocalTime
, @AppSynchTime
, @Remarks_a9
);
END ;
INSERT INTO B1.TESTSEQUENCE
( AppSequenceId
, AppLocalTime
, AppSyncTime
, Remarks)
VALUES( @AppSequenceId
, @AppLocalTime
, @AppSynchTime
, @Remarks
)
,( @AppSequenceId_a8
, @AppLocalTime
, @AppSynchTime
, @Remarks_a9
);
END ;
END
|
|

02-15-11, 16:30
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Quote:
Originally Posted by apboic
if I wanted to send multiple transactions in a single Db2Command,
|
This will still be a single transaction (or even a part of one transaction), not multiple transactions.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|