ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » update(select into external variable)

Post new topic  Reply to topic Goto page 1, 2  Next
 update(select into external variable) « View previous topic :: View next topic » 
Author Message
mqlover
PostPosted: Sun Nov 08, 2015 9:46 pm    Post subject: update(select into external variable) Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

Hi,

I have a project requirement where in I have a function to update the DB and also select the udpated value.
I cannot perform
update Databse.tablename as T set dbvarname=select(dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>
set externalvar=select dbvarname from Database.Tablename AS T where <condition>

There were lot of concurency issues. To avoid that I thought that I will assign to the external variable within the select statement which is withing update.

So now it is
update Databse.tablename as T set dbvarname=select(externalvar=dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>

This woudl avoid concurrency as update creates lock
But when I tested I am get DB exception as after assignng to externalvar the dbvarname has no value. And my db table cannot take NULL.

I searched a lot but found nothign similar. I am working on this past few days but in vain.

Could anybody pls help. I am stuck here.

Thansk in advance
Back to top
View user's profile Send private message
maurito
PostPosted: Mon Nov 09, 2015 12:00 am    Post subject: Re: update(select into external variable) Reply with quote

Partisan

Joined: 17 Apr 2014
Posts: 358

mqlover wrote:
Hi,

I have a project requirement where in I have a function to update the DB and also select the udpated value.
I cannot perform
update Databse.tablename as T set dbvarname=select(dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>
set externalvar=select dbvarname from Database.Tablename AS T where <condition>

There were lot of concurency issues. To avoid that I thought that I will assign to the external variable within the select statement which is withing update.

So now it is
update Databse.tablename as T set dbvarname=select(externalvar=dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>

This woudl avoid concurrency as update creates lock
But when I tested I am get DB exception as after assignng to externalvar the dbvarname has no value. And my db table cannot take NULL.

I searched a lot but found nothign similar. I am working on this past few days but in vain.

Could anybody pls help. I am stuck here.

Thansk in advance

define a SEQUENCE object ( in db2, but if you are using other database, there are equivalents ), and let the database generate the value.

http://www.ibm.com/developerworks/data/library/techarticle/0302fielding/0302fielding.html
Back to top
View user's profile Send private message
smdavies99
PostPosted: Mon Nov 09, 2015 12:21 am    Post subject: Re: update(select into external variable) Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

maurito wrote:
mqlover wrote:
Hi,

I have a project requirement where in I have a function to update the DB and also select the udpated value.
I cannot perform
update Databse.tablename as T set dbvarname=select(dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>
set externalvar=select dbvarname from Database.Tablename AS T where <condition>

There were lot of concurency issues. To avoid that I thought that I will assign to the external variable within the select statement which is withing update.

So now it is
update Databse.tablename as T set dbvarname=select(externalvar=dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>

This woudl avoid concurrency as update creates lock
But when I tested I am get DB exception as after assignng to externalvar the dbvarname has no value. And my db table cannot take NULL.

I searched a lot but found nothign similar. I am working on this past few days but in vain.

Could anybody pls help. I am stuck here.

Thansk in advance

define a SEQUENCE object ( in db2, but if you are using other database, there are equivalents ), and let the database generate the value.

http://www.ibm.com/developerworks/data/library/techarticle/0302fielding/0302fielding.html


Oracle also uses a Squence whereas SQLServer uses IDENTITY.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
mqlover
PostPosted: Mon Nov 09, 2015 2:42 am    Post subject: Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

The db is owned by a different vendor who wouldn't make changes hence it has to be handled by wmb. So could you help me how to handle this through Esql.
Back to top
View user's profile Send private message
maurito
PostPosted: Mon Nov 09, 2015 5:55 am    Post subject: Reply with quote

Partisan

Joined: 17 Apr 2014
Posts: 358

mqlover wrote:
The db is owned by a different vendor who wouldn't make changes hence it has to be handled by wmb. So could you help me how to handle this through Esql.


In that case, start with the SELECT. you need it to return a scalar, not a variable if you are to input it into the UPDATE.
Back to top
View user's profile Send private message
mqlover
PostPosted: Tue Nov 10, 2015 2:21 am    Post subject: Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

Hi,

Yeah I did following
Set externalvar = select tablevar from table where conditions

Update

Still there is concurrency issue as two threads can do select same time and may select same value
Back to top
View user's profile Send private message
maurito
PostPosted: Tue Nov 10, 2015 5:00 am    Post subject: Reply with quote

Partisan

Joined: 17 Apr 2014
Posts: 358

mqlover wrote:
Hi,

Yeah I did following
Set externalvar = select tablevar from table where conditions

Update

Still there is concurrency issue as two threads can do select same time and may select same value

maybe use Passthru select for update ?... as I guess a stored procedure is out of the question.
Back to top
View user's profile Send private message
mqlover
PostPosted: Tue Nov 10, 2015 6:02 pm    Post subject: Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

Lemme try that. Tx. But I don't think db2 supports select for update
.
Back to top
View user's profile Send private message
mqlover
PostPosted: Wed Nov 11, 2015 5:44 pm    Post subject: Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

It seems not to be working. Is there any other way? Can anybody guide me?
Back to top
View user's profile Send private message
mqlover
PostPosted: Wed Nov 11, 2015 6:59 pm    Post subject: Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

I was trying to do the below now :

select columnname into external var from tablename where <conditions>

But this throws error in ESQL. But is there a way if I can wrap in a passthru statemnt? Actually not getting how to do, even few googled things not helping me out really.
Back to top
View user's profile Send private message
maurito
PostPosted: Thu Nov 12, 2015 12:05 am    Post subject: Reply with quote

Partisan

Joined: 17 Apr 2014
Posts: 358

mqlover wrote:
It seems not to be working. Is there any other way? Can anybody guide me?


what have you tried ?.
What errors you get ?
Back to top
View user's profile Send private message
smdavies99
PostPosted: Thu Nov 12, 2015 12:14 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

something like this possibly?

use PASSTHRU as a FUNCTION
Code:

declare cSQL CHAR 'select * from X where X.COL2 = 23;
set Envritonment.Data.XXX[] = Passthru(cSQL);

_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
mqlover
PostPosted: Thu Nov 12, 2015 1:49 am    Post subject: Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

I was trying to assign the select into a variable within update.
but in vain, it does not assign to the update.
Code:

update Databse.tablename as T set dbvarname=(select externalVar=dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>

But this assigns NULL to the set of the update command as it assigns to externalVar and becomes NULL.

Then I put the code in PASSTHRU function as below
Code:

PASSTHRU(update Database.tablename as T set dbvarname=(select dbvarname+1 INTO  externalVar from Database.Tablename AS T where <condition>) where <conditions>)


This failed with the DB exception.

Then I am just trying the same approach with changing syntax so as to make it work with esql.
Back to top
View user's profile Send private message
maurito
PostPosted: Thu Nov 12, 2015 2:08 am    Post subject: Reply with quote

Partisan

Joined: 17 Apr 2014
Posts: 358

mqlover wrote:
I was trying to assign the select into a variable within update.
but in vain, it does not assign to the update.
Code:

update Databse.tablename as T set dbvarname=(select externalVar=dbvarname+1 from Database.Tablename AS T where <condition>) where <conditions>

But this assigns NULL to the set of the update command as it assigns to externalVar and becomes NULL.

Then I put the code in PASSTHRU function as below
Code:

PASSTHRU(update Database.tablename as T set dbvarname=(select dbvarname+1 INTO  externalVar from Database.Tablename AS T where <condition>) where <conditions>)


This failed with the DB exception.

Then I am just trying the same approach with changing syntax so as to make it work with esql.

and what happened to the PASSTHRU ( SELECT FOR UPDATE ?!

Code:

Select-statement


Read syntax diagramSkip visual syntax diagram
>>-+-----------------------------------+--fullselect--●--------->
   |       .-,-----------------------. |                 
   |       V                         | |                 
   '-WITH----common-table-expression-+-'                 

>--+------------------+--●--+---------------------+--●---------->
   +-read-only-clause-+     '-optimize-for-clause-'     
   '-update-clause----'                                 

>--+------------------+----------------------------------------><
   '-isolation-clause-'   

it certainly has a for update clause.
Back to top
View user's profile Send private message
mqlover
PostPosted: Thu Nov 12, 2015 2:58 am    Post subject: Reply with quote

Disciple

Joined: 25 Jul 2010
Posts: 176

Sorry, have a question, does this select for update not allow other thread to select the same value from the table?
I meant will the other thread take same value after one thread read it? Or will there any be any locks?

How about using external lock?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » update(select into external variable)
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.