Forums
Hi Guys,
Does anyone know of a way to determine if an Icebreak session variable exists or has been created.
If one uses GetSesVar(..) or GetSesVarNum(..) a value of *BLANKS or Zero is returned if the session variable has not been created.
This does not tell us whether the session variable exists. Is there are function that can return True/False if the session varaible exists.
Thanks in advance
Syd
Re: Session variables existence
Hi Syd,
We cannot tell the difference between an “empty” and a none-existing session variable. The reason for this is that we are not storing empty session variables at all.
I’m also wondering why this is importing, can you tell me more about your problem?
Regards,
Bent
PS: I’ll be in Berlin for the next 5 days, but I hope that I will be able to answer your questions.
Re: Session variables existence
Thanks Bent,
It is about DB update.
In the simple world we do an update by:
1. Get data from server and displaying in browser
2. User changes data and clicks appropriate button
3. Data goes to server and DB is updated.
BUT -- in a multiuser system, the data in DB may change between #1 and #3 above. It could be updated by another user or process.
Using record or object locks in a browser environment is not wise, so, we need to know if the data has changed and react accordingly.
I use the following technique:
1. Get data DB into externally described data structure and store in session variable.
2. Display data on form in browser
3. user changes data and clicks appropriate button
4. Changed data sent to server
5. Server program gets record from session into data structure, and also gets record from DB into another data structure.
6. Comparing the two data structures - we know if record has changed.
7. If record has changed return message to browser -- else -- update record.
A problem can arise if the session variable has not been initialised and it contains numeric fields -- decimal data error.
I have a work arround to ensure this error does not occur, but, it would have been nice if it was possible to determine if the session variable had already been defined.
A further complication arises because similar transactions cannot use the same session variable. Consequently, each transaction uses a session variable name built from a random number. Each individual transaction uses a unique session variable.
In this way - we can cope with multi-user transactions on a busy system.
Regards
Syd
Re: Session variables existence
Hi Syd,
I'm not sure exactly what you are trying to do and how you have implemented it already?!
My guess is that it is an internal application, right?
You could probably set another session variable to something like true or false specifying wether or not the session variable you are trying to read is set or not.
I understand your concerns regarding two (or more) users updating the same record.
However, what about the simple scenario where one single user opens a record for editing, then presses Ctrl-N (to open up another browser window). This will open up another similar window in IE(*) with the same page, same session ID and same browser-history (but without reloading from the server). This second window could be told to go back in history and into another record which would update your session variable on the server. Then if the user switches back to the initial window and submit changes to the first record it would be compared to the other record just loaded into memory in the other window, right?
I would probably try to implement this scenario in another way:
When a record is loaded for editing, include a hidden field in the form with an MD5 checksum of the data of the entire record and a unique id of the record (token or whatever). When saving the data back to the server, the server should (using commit control of course) read the stored record, generate an MD5 checksum of the data and compare to the submitted hidden field of the MD5 checksom earlier. If they are equal then update and commit the changes.
(*) I'm NOT a fan of IE, but some users uses it so it should be taken into consideration while doing any browser application ;-)
Did the above make any sence?
Re: Session variables existence
Thanks John,
Yes - an internal application for a client of mine.
Yes - I already use the "second" True/False session variable approach to determine if the data has been loaded. I thought there might be a better way as this doubles the number of session variables that need to be handled.
The transaction is Ajax using Extjs forms. I use an object oriented approach. for example, customer maintenance is an JavaScript object that "exports" the "EditCust" procedure. Even in the same session the two "copies" of EditCust are different.
To ensure the server is also aware the transactions are different I use a JavaScript generated random number (created when the EditCust transaction starts) that is sent with every subsequent interaction with the the server for this transaction.
The session variable has this number appended to its name using %CHAR(..) to ensure that each transaction has a different variable.
This technique avoids the problem you mentioned and the user can update two different customers simultaneously in the same session.
When the transaction has been completed the session variable is removed using SesClrVar(...). This variable removal also takes place even if the Form window is closed by the user without any update taking place.
The second True/False session variable must also be handled in the same way, which prompted my question. There would be less session variables to handle.
Regards
Syd
Re: Session variables existence
Hi Syd;
from build 258 there might be a better solution for your challenge:
Both sesGetVar and sesGetvarNum now supports default values if the session variables do not exists.
In that way you can test if a session variable actually is created:
// test defaults - string s = sesGetVar('s' : 'abc'); // Default to abc if it does not exists %><br>s:<% = s %><% sesSetVar('s' : s + '.');// test defaults - numeric i = sesGetVarNum('i' : 123); // Default to 123 if it does not exists %><br>i:<% = %char(i) %><% sesSetVarNum('i' : i + 1); %>Re: Session variables existence
Thanks Niels,
I shall look out for this change next time I update the server software.
Regards
Syd