![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 5 of 5 total |
![]() |
Wed, Sep 16 2015 11:48 AM | Permanent Link |
kamran | Hi All
When I click on the SaveUserBtn ; I just cannot seem to save the data record to the dbisam data file. There is a "user" table on the form which connects ok. What am i doing wrong here ? Here is my code: ............................................................................... var SignUpPage: TSignUpPage; implementation uses Main; procedure TSignUpPage.AfterCommit(Sender: TObject); begin Database.AfterCommit := nil; Database.OnCommitError := nil; Database.LoadRows(user); end; procedure TSignUpPage.OnCommitError(Sender: TObject; const ErrorMsg : string); begin Database.AfterCommit := nil; Database.OnCommitError := nil; ShowMessage('Error: ' + ErrorMsg); end; procedure TSignUpPage.SaveUserBtnClick(Sender: TObject); begin SignUpPage.User.Update; SignUpPage.User.Columns['USER_CODE'].AsString:='testuser'; SignUpPage.User.Save; end; procedure TSignUpPage.CancelSignUpBtnClick(Sender: TObject); begin showmessage('User Registration - Cancelled'); SignUpPage.Close; MainPage.Show; end; procedure TSignUpPage.userAfterSave(Sender: TObject); begin if Database.InTransaction then try Database.AfterCommit := AfterCommit; Database.OnCommitError := OnCommitError; Database.Commit; showmessage('New User Saved Successfully'); SignUpPage.Close; except Database.Rollback; raise; end; end; procedure TSignUpPage.userAfterLoad(Sender: TObject); begin Database.StartTransaction; SignUpPage.User.insert(true); end; procedure TSignUpPage.SignUpPageShow(Sender: TObject); begin Database.LoadRows(user); SignUpPage.User.Open; end; ----------------------------------------------------------------------------------------- Am I missing something here ? Thanks Kamran |
Wed, Sep 16 2015 12:19 PM | Permanent Link |
Raul ![]() | On 9/16/2015 11:48 AM, kamran wrote:
> Hi All > > When I click on the SaveUserBtn ; > > Am I missing something here ? On a quick glance it looks OK to me - i would suggest to check that your userAfterSave actually gets called (log it for example) and also check that TransactionLevel is 1 or 0 (i can't see any reason for nested transaction to occur but just in case). The other thing to check is to use the actual browser debug tools and see if the commit results in the web request getting sent to server. Raul |
Wed, Sep 16 2015 12:24 PM | Permanent Link |
Walter Matte Tactical Business Corporation | kamran wrote:
A couple of things...... procedure TSignUpPage.SignUpPageShow(Sender: TObject); begin Database.LoadRows(user); //////// SignUpPage.User.Open; the dataset user will be opened automatically ////////when the data comes back from the server. end; procedure TSignUpPage.CancelSignUpBtnClick(Sender: TObject); begin showmessage('User Registration - Cancelled'); if Database.InTransaction then // <<<<<< Rollback what you started....... Database.Rollback; SignUpPage.Close; MainPage.Show; end; procedure TSignUpPage.userAfterSave(Sender: TObject); begin if Database.InTransaction then try Database.AfterCommit := AfterCommit; Database.OnCommitError := OnCommitError; Database.Commit; // showmessage('New User Saved Successfully'); - you will know this if AfterCommit Happens move it there // SignUpPage.Close; move to after commit except // Database.Rollback; put in OnCommit Error. // raise; end; end; Walter Hi All When I click on the SaveUserBtn ; I just cannot seem to save the data record to the dbisam data file. There is a "user" table on the form which connects ok. What am i doing wrong here ? Here is my code: ............................................................................... var SignUpPage: TSignUpPage; implementation uses Main; procedure TSignUpPage.AfterCommit(Sender: TObject); begin Database.AfterCommit := nil; Database.OnCommitError := nil; Database.LoadRows(user); end; procedure TSignUpPage.OnCommitError(Sender: TObject; const ErrorMsg : string); begin Database.AfterCommit := nil; Database.OnCommitError := nil; ShowMessage('Error: ' + ErrorMsg); end; procedure TSignUpPage.SaveUserBtnClick(Sender: TObject); begin SignUpPage.User.Update; SignUpPage.User.Columns['USER_CODE'].AsString:='testuser'; SignUpPage.User.Save; end; procedure TSignUpPage.CancelSignUpBtnClick(Sender: TObject); begin showmessage('User Registration - Cancelled'); SignUpPage.Close; MainPage.Show; end; procedure TSignUpPage.userAfterSave(Sender: TObject); begin if Database.InTransaction then try Database.AfterCommit := AfterCommit; Database.OnCommitError := OnCommitError; Database.Commit; showmessage('New User Saved Successfully'); SignUpPage.Close; except Database.Rollback; raise; end; end; procedure TSignUpPage.userAfterLoad(Sender: TObject); begin Database.StartTransaction; SignUpPage.User.insert(true); end; procedure TSignUpPage.SignUpPageShow(Sender: TObject); begin Database.LoadRows(user); SignUpPage.User.Open; end; ----------------------------------------------------------------------------------------- Am I missing something here ? Thanks Kamran |
Thu, Sep 17 2015 6:01 AM | Permanent Link |
kamran | Thanks Raul and Walter
After testing for transaction level it was not 0 it was 2 so that I assume that means that there was some commits pending ! But I used "DataBase.RetryPendingRequests" before doing the commit and this did not seem to work - I wonder why ? 1. Maybe there is an easy way to track the commits ? The only thing to make it work was to do a number of commits before the save. 2. Is there a way to reset all pending commits ? 3. Also why can't I set the value of DataBase.TransactionLevel to 0 ? I guess its protected for some good reason ! Thanks Kamran |
Thu, Sep 17 2015 8:26 AM | Permanent Link |
Raul ![]() | On 9/17/2015 6:01 AM, kamran wrote:
> After testing for transaction level it was not 0 it was 2 so that > I assume that means that there was some commits pending ! Yes but what it really means is that you had called StartTransaction twice - this is supported because nested transaction are valid and good feature to have. See Transaction section of manual - it describes various activities well : http://www.elevatesoft.com/manual?action=viewtopic&id=ewb2&topic=Transactions > But I used "DataBase.RetryPendingRequests" before doing the commit > and this did not seem to work - I wonder why ? This is not relevant in this case - RetryPendingRequests applies after post to the server is done and fails (meaning you already had a transaction level = 0). > The only thing to make it work was to do a number of commits > before the save. Yes - it's up to you to ensure you have matching number of StartTransaction and Commit calls. You can check transaction level and then call commit so that it's 0 - however this is brute force approach. Your app design should be such that every StartTransaction is matched by either Commit or Rollback and you would not have the problem. > 2. Is there a way to reset all pending commits ? For actual pending commits (meaning ones already commited and in POST queue to the web server) you can call CancelPendingRequests. > 3. Also why can't I set the value of DataBase.TransactionLevel to 0 ? > I guess its protected for some good reason ! Because it would mess everything up as there are other activities tied to changing this. You control it through StartTransaction and Commit coammands. See again manual section "Committing a Transaction" for detailed explanation on what happens and how transaction level is decreased when you call commit. Raul |
This web page was last updated on Friday, December 1, 2023 at 06:01 PM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |