This question is not specific to B4A but it is not suitable for Chit Chat!
Suppose we have a class that represents an entity (such as an inventory item).
The class contains a property for each field of a database table.
Suppose I want to update a field of a record by the primary key.
I can load the data in the class object via a method contained in the class:
(I would also have a suggestion for the name - "Fill" Or "Load"? / "For", "By" or other?)
Then I set a property to be updated:
At this point I could have a method:
which, internally, checks if there is already a record containing that PK; in this case the method performs an Update, otherwise it performs an Insert.
Or I could have two methods, Update and Insert.
What you recommended me to write in the class:
a) only the Save method (which decides whether to update or insert)
b) Insert and Update methods (in which case the developer will have to decide)
Thank you in advance for your answers.
Suppose we have a class that represents an entity (such as an inventory item).
The class contains a property for each field of a database table.
Suppose I want to update a field of a record by the primary key.
I can load the data in the class object via a method contained in the class:
B4X:
InvenItem.FillForPK (PK)
Then I set a property to be updated:
B4X:
InvenItem.Qty = NewQuantity
At this point I could have a method:
B4X:
InvenItem.Save
Or I could have two methods, Update and Insert.
What you recommended me to write in the class:
a) only the Save method (which decides whether to update or insert)
b) Insert and Update methods (in which case the developer will have to decide)
Thank you in advance for your answers.
Last edited: