Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: accessing current data from a database whilst already in a session


This question is answered.


Permlink Replies: 8 - Last Post: Oct 22, 2016 10:06 PM Last Post By: canice pierre
canice pierre

Posts: 48
Registered: 9/27/12
accessing current data from a database whilst already in a session  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2016 10:55 AM
I have an Intraweb application with 1 database component and 1 IBtransaction component in the Usersession unit.
There are 2 separate forms with tables pointing to the same database. There are data-aware components on both forms.

problem:

If a change is made in one of the forms and then a new session is opened, the change can be seen in the other form.
However if both sessions are already opened, a change to the data in one form does not update the field in the other.
Table refresh, open, close makes no difference.

I would like to issue commands to commit the IBtransaction but the syntax does not allow for eg. Form2.Ibtransaction1 if your are within Form1.
Emailx45 Yahoo

Posts: 37
Registered: 6/21/08
Re: accessing current data from a database whilst already in a session  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2016 1:24 PM   in response to: canice pierre in response to: canice pierre
canice pierre

Posts: 48
Registered: 9/27/12
Re: accessing current data from a database whilst already in a session  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2016 3:42 PM   in response to: Emailx45 Yahoo in response to: Emailx45 Yahoo
Thanks. What my problem is, is that data entered in the webform does not commit to the database until the server application is closed. Because of this any new updates are not picked up by a new session. This is what I want to fix.

Emailx Yahoo wrote:
try this explanation in Atozed

http://www.atozed.com/intraweb/docs/Develop/index.aspx

http://www.atozed.com/intraweb/docs/Develop/Sessions/HowSessionManagementWorks.aspx

Edited by: Emailx Yahoo on Oct 20, 2016 1:26 PM
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: accessing current data from a database whilst already in a session  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2016 4:23 PM   in response to: canice pierre in response to: canice pierre
That would not be because of IW. It has to be related to the actual database controls. IW does not change the way the data controls work. It's exactly the same as it would be in a VCL application.

You have to post some detail so we can see how the data is being handled. I rely on IW database functionality in multi-user environments. It works great.

If you are expecting the screen to automatically update to reflect changes made by other users, that is not going to happen. That is because of the way a web application and browsers function. Once the server has rendered a page and delivered it to the requesting client, it stops communicating until another request from the client is submitted due events on the page. You will need to refresh the page to show any changes made to the database. You could also use a timer with an asynchronous event to make it feel like real-time updates.

You can prove this by adding a button to each page. When the button is clicked you should call MyTable.Refresh or whatever you need to update the data. You should then be able to have user A make changes, and then have user B refresh to see those changes. Working in the browser will require some rethinking of your user interface.

Edited by: Daniel Fields on Oct 20, 2016 4:38 PM
canice pierre

Posts: 48
Registered: 9/27/12
Re: accessing current data from a database whilst already in a session  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2016 4:51 AM   in response to: Daniel Fields in response to: Daniel Fields
Thanks,

I actually do not rely on a page refresh. I actually do a locate on the record that User A changed but it is not reflected in B. I even resubmit a commit, and open command before doing this.

For example, I make a change to a record and commit the transaction. I then use the iBconsole to look at the data in the database itself and I do not see the update.
When I close the server application and re-open I then see the change in user B and also in the database itself using iBconsole.

My parameter on the Ibtransaction is also set to commit in design time. Do you know of any other settings that I can use to ensure that the actual database is updated instantly?

I have another question regarding my efficiency. I have the same components duplicated on two different forms/units. Database, Transaction and tables. They point to the same .IB file on my machine. The reason I did this is because even though I can have all these components for eg in one form and can make the data ready components connect to one set of components, when it comes to the code, I am unable to make one form use a component from another form like I can do in VCl.
Any advice on this one?

Daniel Fields wrote:
That would not be because of IW. It has to be related to the actual database controls. IW does not change the way the data controls work. It's exactly the same as it would be in a VCL application.

You have to post some detail so we can see how the data is being handled. I rely on IW database functionality in multi-user environments. It works great.

If you are expecting the screen to automatically update to reflect changes made by other users, that is not going to happen. That is because of the way a web application and browsers function. Once the server has rendered a page and delivered it to the requesting client, it stops communicating until another request from the client is submitted due events on the page. You will need to refresh the page to show any changes made to the database. You could also use a timer with an asynchronous event to make it feel like real-time updates.

You can prove this by adding a button to each page. When the button is clicked you should call MyTable.Refresh or whatever you need to update the data. You should then be able to have user A make changes, and then have user B refresh to see those changes. Working in the browser will require some rethinking of your user interface.

Edited by: Daniel Fields on Oct 20, 2016 4:38 PM
Eitan Arbel

Posts: 508
Registered: 2/24/13
Re: accessing current data from a database whilst already in a session
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2016 8:21 AM   in response to: canice pierre in response to: canice pierre
hi pierre

about question 1 :
when i moved from Paradox to Interbase (and now i'm with FireBird), i had exactly the same problems.
i didn't know i need to use the Transaction...

so here is how i use it since i figure it out (the procedure is located in the UserSessionUnit) :
Procedure TIWUserSession.SomeSQLProc;
Begin
  With ibQuery1 Do Begin
    If Active Then Close;
    If NOT Transaction.Active Then Transaction.StartTransaction;  //   <<<--- Critical 1
    SQL.Text:='INSERT ...';
 
//    ParamByName if needed
 
//    ExecSQL or Open  --  if the INSERT is with or without RETURNING
 
    Transaction.Commit;  //   <<<--- Critical 2
    Close;
  End;
End;

the Transaction.StartTransaction and Transaction.Commit parts are the two things that makes other people see the updated data.
(i moved to FireBird after i saw that interbase didn't recognize the RETURNING command...)

{------------------------------------------------}

about question 2 :

first thing i would really recommend is to put your ibTable, ibQuery and all the database components in the UserSessionUnit (it is a DataModule after all).
it will be much easier to maintain the code and debug that way

then, in the form, add this :
uses UserSessionUnit;

in the form's code, you can use ibQuery1 that is located in the UserSessionUnit like that :

Procedure TfrmForm1.MyProcedure;
Begin
  With UserSession.ibQuery1 Do Begin  //  <<<--- see the UserSession.
    If Active Then Close;
 
    SQL.Text:='SELECT ....';
 
//    ParamByName if needed
 
    Open;
  End;
End;

or with the example above(question\answer 1), you can call the procedure that is located in the UserSessionUnit like that :

uses UserSessionUnit;
 
Procedure TfrmForm1.MyProcedure;
Begin
  UserSession.SomeSQLProc;
End;


i jumped from Delphi 6\Paradox, to Delphi XE2\Interbase, so i remember how "painful" the change was...
canice pierre

Posts: 48
Registered: 9/27/12
Re: accessing current data from a database whilst already in a session  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2016 10:06 PM   in response to: Eitan Arbel in response to: Eitan Arbel
Thank you.
It is now working.

Eitan Arbel wrote:
hi pierre

about question 1 :
when i moved from Paradox to Interbase (and now i'm with FireBird), i had exactly the same problems.
i didn't know i need to use the Transaction...

so here is how i use it since i figure it out (the procedure is located in the UserSessionUnit) :
Procedure TIWUserSession.SomeSQLProc;
Begin
  With ibQuery1 Do Begin
    If Active Then Close;
    If NOT Transaction.Active Then Transaction.StartTransaction;  //   <<<--- Critical 1
    SQL.Text:='INSERT ...';
 
//    ParamByName if needed
 
//    ExecSQL or Open  --  if the INSERT is with or without RETURNING
 
    Transaction.Commit;  //   <<<--- Critical 2
    Close;
  End;
End;

the Transaction.StartTransaction and Transaction.Commit parts are the two things that makes other people see the updated data.
(i moved to FireBird after i saw that interbase didn't recognize the RETURNING command...)

{------------------------------------------------}

about question 2 :

first thing i would really recommend is to put your ibTable, ibQuery and all the database components in the UserSessionUnit (it is a DataModule after all).
it will be much easier to maintain the code and debug that way

then, in the form, add this :
uses UserSessionUnit;

in the form's code, you can use ibQuery1 that is located in the UserSessionUnit like that :

Procedure TfrmForm1.MyProcedure;
Begin
  With UserSession.ibQuery1 Do Begin  //  <<<--- see the UserSession.
    If Active Then Close;
 
    SQL.Text:='SELECT ....';
 
//    ParamByName if needed
 
    Open;
  End;
End;

or with the example above(question\answer 1), you can call the procedure that is located in the UserSessionUnit like that :

uses UserSessionUnit;
 
Procedure TfrmForm1.MyProcedure;
Begin
  UserSession.SomeSQLProc;
End;


i jumped from Delphi 6\Paradox, to Delphi XE2\Interbase, so i remember how "painful" the change was...
Lou Feliz

Posts: 114
Registered: 7/16/97
Re: accessing current data from a database whilst already in a session
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2016 12:42 PM   in response to: canice pierre in response to: canice pierre
Hello,

In cases such as this, I use the UserSession data module and have the dataset/query share transaction component. I also usually issue commit retaining in after post event. You should not have to wait for app to close for updates to be visible.

canice pierre wrote:
Thanks. What my problem is, is that data entered in the webform does not commit to the database until the server application is closed. Because of this any new updates are not picked up by a new session. This is what I want to fix.

Emailx Yahoo wrote:
try this explanation in Atozed

http://www.atozed.com/intraweb/docs/Develop/index.aspx

http://www.atozed.com/intraweb/docs/Develop/Sessions/HowSessionManagementWorks.aspx

Edited by: Emailx Yahoo on Oct 20, 2016 1:26 PM
Emailx45 Yahoo

Posts: 37
Registered: 6/21/08
Re: accessing current data from a database whilst already in a session
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2016 1:33 PM   in response to: canice pierre in response to: canice pierre
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02