[Gambas-user] Use of db.Begin, db.Commit and db.Rollback with a datasource and datacontrols
Hello, I have a form containing a datasource linked to a MySQL database table. The datasource contains datacontrols to display the data from the underlying table. There are buttons for add, edit, save, delete and cancel. The add button creates a new record. The save button saves the record. The Edit button allows change to the record. The cancel button cancels the changes. The delete button deletes the entire record. I would like the cancel button to cancel the add and all edits and repopulate the form with the original data from the datasource table. If the user hits the cancel button no change should be made to the table. The delete button asks for confirmation before deleting the record. I'm not so much looking for code so much but for advice on the proper sequence of bd.begin etc. Should add and edit begin a transaction and save commit the transaction? Should cancel rollback the transaction? The syntax is $Con.Begin, $Con.Commit and $Con.Rollback. Is that correct? If my thought is correct how do I get the form to display the original data? Thanks -- New Year. New Location. New Benefits. New Data Center in Ashburn, VA. GigeNET is offering a free month of service with a new server in Ashburn. Choose from 2 high performing configs, both with 100TB of bandwidth. Higher redundancy.Lower latency.Increased capacity.Completely compliant. http://p.sf.net/sfu/gigenet ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Use of db.Begin, db.Commit and db.Rollback with a datasource and datacontrols
Hello Martin, If you are working with only one record at a time, you don't need to use transactions. Transactions are used when multiple records need to be modified in an all-or-none scenario, such as when a record, that is the "one" in a one-to-many relationship, needs to be deleted. In such a case, you would start a transaction with .Begin, delete the dependent records followed by the one record. Then, if all modifications are successful, you would .Commit. If there is a failure at any time during the transaction, you would .Rollback. To get the datacontrol to display the original data after a canceled edit, use the .Refresh method. Lee __ "Artificial Intelligence is no match for natural stupidity." On 01/19/2015 07:11 PM, Martin McGlensey wrote: > Hello, > > > > I have a form containing a datasource linked to a MySQL database table. The > datasource contains datacontrols to display the data from the underlying > table. There are buttons for add, edit, save, delete and cancel. The add > button creates a new record. The save button saves the record. The Edit > button allows change to the record. The cancel button cancels the changes. > The delete button deletes the entire record. > > > > I would like the cancel button to cancel the add and all edits and > repopulate the form with the original data from the datasource table. If the > user hits the cancel button no change should be made to the table. The > delete button asks for confirmation before deleting the record. > > > > I'm not so much looking for code so much but for advice on the proper > sequence of bd.begin etc. Should add and edit begin a transaction and save > commit the transaction? Should cancel rollback the transaction? The syntax > is $Con.Begin, $Con.Commit and $Con.Rollback. Is that correct? If my thought > is correct how do I get the form to display the original data? > > > > Thanks > > -- > New Year. New Location. New Benefits. New Data Center in Ashburn, VA. > GigeNET is offering a free month of service with a new server in Ashburn. > Choose from 2 high performing configs, both with 100TB of bandwidth. > Higher redundancy.Lower latency.Increased capacity.Completely compliant. > http://p.sf.net/sfu/gigenet > ___ > Gambas-user mailing list > Gambas-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gambas-user > -- New Year. New Location. New Benefits. New Data Center in Ashburn, VA. GigeNET is offering a free month of service with a new server in Ashburn. Choose from 2 high performing configs, both with 100TB of bandwidth. Higher redundancy.Lower latency.Increased capacity.Completely compliant. http://p.sf.net/sfu/gigenet ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Use of db.Begin, db.Commit and db.Rollback with a datasource and datacontrols
>> use the .Refresh method << That assumes that one is using data linked controls. That is not always the case: examples: a date record is displayed/edited as two separate text boxes (i.e. date and time) a person's name is stored in the fields: given_name, initial, family_name the person's name is displayed/edited in a single text box I have in the past (with VB6) used the control.tag property to hold the original unedited text for the control. I have also been known to use that information to verify another user had not changed the original record prior to processing the update. On 01/19/2015 07:42 PM, T Lee Davidson wrote: > Hello Martin, > > ... > To get the datacontrol to display the original data after a canceled edit, > use the .Refresh method. > > -- New Year. New Location. New Benefits. New Data Center in Ashburn, VA. GigeNET is offering a free month of service with a new server in Ashburn. Choose from 2 high performing configs, both with 100TB of bandwidth. Higher redundancy.Lower latency.Increased capacity.Completely compliant. http://p.sf.net/sfu/gigenet ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user