Schultz’s PowerBuilder Notes

Guaranteeing a Singleton

Because the datetime on the client machine may not be accurate, I wanted to write a function to get the current date and time from the server.  

For Sybase DBMS, this is simply achieved with the GetDate() function.  The problem is developing the SQL to return exactly one row everytime the function is called.  (It will still work if the SQL returns multiple rows, but you will have a lot of unecessary database traffic.)

Since the application is using PFC security, I came up with the following function for the gnv_app of the ps0001 application:

// Function: of_GetDateTime
// Access: Public 
// Description: Gets the current datetime from the database server
// Arguments: none
// Returns:   datetime
Datetime ldtm_today

SELECT GetDate()
  INTO :ldtm_today
  FROM QUAD0054..security_apps
 WHERE application = "ps0001"
 USING itr_primary;

RETURN  ldtm_today

Oracle DBMS has DUAL to guarantee a singleton.


September 19, 2008 - Posted by | Database, Powerscript | , , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: