Function functionality ?

Hello, 
I have a Function : 

create Function F1 ........ 
as 

update T1 set col1=col1+1; 
commit; 

return col1; 
end; 

Lets say col1 value before the func. is called is 100. Now, if user1 
executes this function and user2 also executes the same function, at the 
same time. 

1) What value is returned for user1 and user2. Would that update stt. locks 
the table, and allows only 1 user to access it? 

2) My requiemnent is that the 2 users should get different values from the 
function. 


thanks for your help 
-Sravan

0
Sravan
10/2/2001 12:55:23 AM
sybase.ase.administration 7058 articles. 2 followers. Follow

5 Replies
1696 Views

Similar Articles

[PageSpeed] 16
Get it on Google Play
Get it on Apple App Store

Sravan wrote...
> Hello, 
> I have a Function : 
> 
> create Function F1 ........ 
> as 
> 
> update T1 set col1=col1+1; 
> commit; 
> 
> return col1; 
> end; 
> 
> Lets say col1 value before the func. is called is 100. Now, if user1 
> executes this function and user2 also executes the same function, at the 
> same time. 
> 
> 1) What value is returned for user1 and user2. Would that update stt. locks 
> the table, and allows only 1 user to access it? 
> 
> 2) My requiemnent is that the 2 users should get different values from the 
> function. 
> 
> 
> thanks for your help 
> -Sravan
> 
> 

The CREATE FUNCTION is not an ASE statement.  Are you using ASA or SQL Anywhere?
-- 
Jim Egan [TeamSybase]
Senior Consultant
Sybase Professional Services
0
Jim
10/2/2001 2:46:56 AM
Hello, 
please accept my apologies for my ignorance in sybase syntax, as am a 
newbie. Let me rephrase my question :

I have a procedure, which returns a value : 
(please ignore my syntax)
create procedure p1 ........ 
as 

update T1 set col1=col1+1
commit

return col1 
end

Lets say col1 value before the proc. is called is 100. Now, if user1 
executes this procedure and user2 also executes the same procedure, at the 
same time. 

1) What value is returned for user1 and user2. Would that update stt. locks 
the table, and allows only 1 user to access it? 

2) My requiemnent is that the 2 users should get different values from the 
procedure. 


thanks for your help 
-Sravan
0
sravan
10/2/2001 6:51:44 PM
sravan wrote...
> Hello, 
> please accept my apologies for my ignorance in sybase syntax, as am a 
> newbie. Let me rephrase my question :
> 
> I have a procedure, which returns a value : 
> (please ignore my syntax)
> create procedure p1 ........ 
> as 
> 
> update T1 set col1=col1+1
> commit
> 
> return col1 
> end
> 
> Lets say col1 value before the proc. is called is 100. Now, if user1 
> executes this procedure and user2 also executes the same procedure, at the 
> same time. 
> 
> 1) What value is returned for user1 and user2. Would that update stt. locks 
> the table, and allows only 1 user to access it? 
> 
> 2) My requiemnent is that the 2 users should get different values from the 
> procedure. 

There could be a few different outcomes.  The most obvious one would be that the second 
user to run the procedure would get a value one higher than the first user.

The second user to run the procedure would most likely get blocked until the execution 
started by the first user finished.  Alternatively, it is possible that a deadlock could 
occur.  In this case one user would finish and the other would have their transaction 
rolled back.

Are you trying to write a procedure that gets a next key value?  If so I'll provide one way 
to do it.
-- 
Jim Egan [TeamSybase]
Senior Consultant
Sybase Professional Services
0
Jim
10/2/2001 7:27:37 PM
Jim, thanks for the response.
Yes. Am trying to get the next number. We discussed using "identity", for 
the purpose. But decided against, cos of some spf. business rules.

I would be interested in your alternate implmentation solution.

thanks
-sravan
0
sravan
10/3/2001 12:34:36 AM
sravan wrote...
> Jim, thanks for the response.
> Yes. Am trying to get the next number. We discussed using "identity", for 
> the purpose. But decided against, cos of some spf. business rules.
> 
> I would be interested in your alternate implmentation solution.

Assuming you have a table of keys as such:
CREATE TABLE TableKeys
(tablename VARCHAR(30) NOT NULL PRIMARY KEY,
 keyvalue  INTEGER NOT NULL)

CREATE PROCEDURE spgetnextkey 
@tablename VARCHAR(30)
AS
BEGIN
DECLARE @nextkey INTEGER

-- This updates the next key value and gets it at the same time.
UPDATE TableKeys
SET keyvalue = keyvalue + 1,
    @nextkey = keyvalue + 1
WHERE tablename = @tablename

IF @nextkey IS NULL
   RAISERROR ....
ELSE
   SELECT @nextkey

END

A variation on this is to have @nextkey as the second parameter.  This provides to 
benefits.  First you can return the next key value as a parameter and won't have to worry 
about a result set.  Second, you can pass in a value for @nextkey and use it to increment 
the keyvalue column.  This allows you to request a range of values instead of just one.

I try to avoid calling this procedure within a transaction.  Doing so would hold up the 
generation of keys for other connections.  To minimize this make sure you use row locking 
on the table.
-- 
Jim Egan [TeamSybase]
Senior Consultant
Sybase Professional Services
0
Jim
10/3/2001 2:57:15 AM
Reply:

Similar Artilces:

Function call in other function
void (con){string baglanti = ConfigurationManager.ConnectionStrings["Musa"].ConnectionString; OleDbConnection con = new OleDbConnection(baglanti); }  void OkunmaSayisiniArttir() {con();       // error  OleDbCommand komut = new OleDbCommand("UPDATE makaleler SET mak_hit=mak_hit+1 where kimlik=@kimlik ", con); komut.Parameters.Add("@kimlik", Request.QueryString["kimlik"]); con.Open(); komut.ExecuteReader(); con.Close(); komut.Connection.Close(); } __________________________ This code blog does...

FUNCTION INSIDE FUNCTION
 ok suppose i have two asp buttons....each button has its own code which executes after that button is clicked.....can i call  button1 function inside button2 function.....ie whenever button2 is clicked button1 should execute too......can i call a function inside another function ? Put the code of your button click event in a function and call that function in button2 click event after the button2 cllick event code. Or if you just want to execute the same code in both the buttons then just call the same event in both the button click event.Apurva Kaushal  thank u ....sorry...

function name with in function?
Hi In ASP.NET (VB.NET) code-behind, While executing a function, how can I find programmatically which function I am in at that point of time? Function foo() as string ‘ Hey ! I am in function foo() End Function Please let me know. Thanks Pankaj How do you call the function?This posting is provided "AS IS" with no warranties, and confers no rights. Function call be called by any other function or sub. I think caller is irrelevant here. If you call that function by its name, just pass the name to the function to be called so you know where you are. Like this: ...

How to check if a native function is an internal function or an external function
Hello,all, In the JS interpreter, I found that some of internal object functions are also implemented as native functions. For example, js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n), which is used to create a new String object. It should be an internal functions but is implemented as a native function. In the function js_Invoke(JSContext *cx, uintN argc, jsval *vp, uintN flags) of jsinterp.cpp, Is there any method for me to check whether a native function is an internal function or an external function? Here, external functions mean those that do not belong to Javasc...

Print function not functional
Name: J. Michael Caruthers Email: mcaruthataoldotcom Product: Firefox Summary: Print function not functional Comments: With this current version of Firefox (3.6.10) I can no longer print from any site that I log-on to in the browser. For example, if I go to the AOL. site, I can't print a message either through AOL. itself or using the Firefox File/Print... tab. I can print normally in Windows IE or if I copy the message to MS Word (and print from there). I did not have this problem with earlier versions of Firefox. Browser Details: Mozilla/5.0 (Windows; U; Windows N...

differentiating between a function and a call to function
Hi, when I scan through scripts in my files , I come access a function definition and call to that function. e.g function init() { var f = doc.getField("lsBox3"); f.insertItemAt("Arizona", "AZ", 0); f.insertItemAt("California", "CA", 1); f.insertItemAt("Oregon", "OR", 2); f.insertItemAt("Ohio", "OH", 3); f.multipleSelection = true; } init(); So, when I get this entire string and pass it to evaluateReader() I get the items inserted in the listbox twice. How d...

how to call another function in a function?
what's the syntax should be? A function call can be made from another function/method (different ppl giving it different terms) by placing the name you've given the function in your function definition.   For example in C#: public int CalculateAdd(int x, int y){ return x+y;}public void CallAboveFunction(){ int result = CalculateAdd(2, 3);}   Example in VB.NET Function CalculateAdd(ByVal x As Integer, ByVal y As Integer) As Integer CalculateAdd = x + yEnd FunctionSub CallAboveFunction() Dim result as Integer result = CalculateAdd(2, 3)End S...

Administrator functions
Name: Ernst Noordhuis Email: ernstdotnoordhuisathome.nl Product: Firefox Summary: Administrator functions Comments: In Firefox I feel the need for soem administrator functions. As a system administrator on a primary school we are using firefox in stead of internet explorer. But I want to block the option settings by the students. Is such possible? Regards, Ernst Noordhuis Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 ...

function as input of another function
Hi Guys, I have a rather complicated problem. Every vehicle gets the following information (displayed as tooltip) from the loop below:CARRIER    - an IDVEHICLEIDTIME OF RECORDSHIPMENTTYPECONTAINERTYPEVEHICLENUMBER + DESTINATION Where DESTINATIOn is retrieved form a different function, based on a different query BUT with theCARRIER (id) from the main loop as the necessary input. Hence, to get DESTINATION for every VEHICLE I have to dive into the GetJobInfo Functionwith the previously retrieved CARRIER (as paramter) to get the DESTINATION.Something like this I imagined: + v...

How to javascript function from C# function ?
i have a popup function in the javascript. when ever i call it from HTML controls's onClick event it is working well. but when ever i writeResponse.Write("<script>"); Response.Write("PopupPicker(215,200);"); Response.Write("</script>"); in c# method it doesn't work any thing.my javascript function is as follow:<script language="javascript"> function PopupPicker(w,h) { var PopupWindow=null,settings; settings='width='+ w + ',height='+ h + ',location=no,directories=no,men...

Calling a function with a function argument...
Hi! Have a problem. I am creating a webapplication in ASP.NET and I display some data in a datagrid. In the datagrid I display some data as an HTML link and this data I get from the VB function GetCustomerName. When I click on the link an alert is generated via Javascript that displays the information kundnr and referens. <%# GetCustomerName(Container.DataItem("kundnr")) %> That works just fine, but now to my problem. I want to call a Javascript function with another argument that I want to send in as a VB function (check) like this. That function returns a string va...

&function() or function()? and etiquette...
This question is more for the gurus. It's about etiquette and style. I realize now the benefits of following coding standards and etiquette, and of course use warnings and use strict. My question lies in the & when calling a subroutine. Should those who are starting out use &function(); or function(); ?? I am also seeing the benefits of using prototypes when declaring my functions. No more worries of having to put the \ on the correct arguments when calling my wacky functions that take 2 refs and 3 scalars. Are prototypes recommended for easy maintenance? Or do they jus...

Function
Can a UDF return  a table query as result? Please kindly provide sample T-SQL. Thanks.Please mark the post(s) that have helped you as "Answer" Yes. Check out books on line under UDF.***********************Dinakar NethiLife is short. Enjoy it.*********************** In Northwind database I try to create and test the sample UDF shown in BOL as below:CREATE FUNCTION LargeOrderShippers ( @FreightParm money )RETURNS @OrderShipperTab TABLE   (    ShipperID     int,    ShipperName   nvarchar(80), &nbs...

function
I am a new programmer,using PowerBuilder6.5. I am fixing an exsisting app. that I did not create.How would I create a function that will make any window in an application ReadOnly when flagged.Please supply example code with your answer. On Thu, 6 Apr 2000 13:33:09 -0300, in powersoft.public.powerbuilder.general Karen Alexander <kalexander@deltaware.com> wrote: >I am a new programmer,using PowerBuilder6.5. I am fixing an exsisting app. >that I did not create.How would I create a function that will make any >window in an application ReadOnly when flagged.Please ...

Web resources about - Function functionality ? - sybase.ase.administration

PlayStation 2 online functionality - Wikipedia, the free encyclopedia
Selected games on Sony 's PlayStation 2 video game console offer online gaming or other online capabilities. Games that enable the feature provide ...

ThroughGlass Brings More Facebook Functionality To Google Glass
Google Glass is not even available to the public yet, and there are already two Facebook applications for the head-mounted device, with photo-sharing ...

ShareThis brings social reader functionality to new sharing widget for publishers
... option to automatically share their reading activity back to Facebook. This could lead more blogs and media sites to add social reader functionality ...

Reverting the changes to block functionality
Earlier today, we made a change to the way the “block” function of Twitter works. We have decided to revert the change after receiving feedback ...

Users want functionality without complexity with BYOD: Cortado
Mobile workers want to have access to their files while the move without the complexity, according to Cortado APAC sales manager, Brendan Samuels. ...

Apple takes password reset functionality offline after news of serious vulnerability
Earlier Friday, The Verge reported on a significant security exploit with Apple's "reset password" functionality for Apple IDs. Armed with only ...

Updated: Get Kinect-style functionality on your Mac with this free app
Flutter is a free app that brings gesture controls to your Mac via its built-in web cam. Get the download here.

Twitter bolsters search functionality - social media, social networking, Internet-based applications ...
Twitter will bolster search functionality to automatically complete users' queries and suggest related search terms, among other improvements ...

Google announces enhanced snooze functionality for Inbox by Gmail
Google today announced a useful new feature that is now available in its Inbox email app. Starting today, when users "snooze" an email that has ...

‘Ping’ brings iMessage-like functionality to email
... Check out 9to5Mac for more breaking coverage of Apple , iPhone , and Apps . What do you think? Discuss "‘Ping’ brings iMessage-like functionality ...

Resources last updated: 12/23/2015 8:15:04 PM