SQLiteDatabase and UPDATE

Existential question:

How do you deal with an UPDATE statement ?

Do you SET all Fields or only those that were modified (and if the later, how ?)

Yes, probably a dumb question. We can’t always be at 100%. :frowning:

UPDATE mytable SET myfield=newvalue or 'newvalue'

This isnt a question about how to do an update.
If it was , the answer is ‘only those that were modified’

The actual question is about your screen full of data, and which fields have changed, isnt it?

Create a class that matches the record format.
Read a record into an instance of the class.
Update the window from the same data.

When any field is amended, record that ‘somethinghaschanged’
Enable the ‘Save’ button

When you save, it is easiest to update all fields, but of you want to update only the changed fields, compare the controls to the object that knows what the original data looked like and generate SQL from that.

You can update all the fields or only those that have changed. Doing the latter is less work for the database engine, less traffic on a network and preferred by the administrators of the database, network, servers, etc.

This answer my question: Save only the modified fields using a custom class, etc. as Jeff explain above.

Thanks Jeff

PS: my natural penchant for doing is to save all (seems less work / thinking for me). I will try Jeff advice (of course he wrote it for that).

I update all fields and only when the user clicks the Update button. This allows them to make a mistake then cancel out and not have the database touched.
It is less traffic and complexity in the long run, since I use a Prepared Statements to perform my updates — I would hate to have to do this on every field.

I get an eye on TextEdit / TextArea / TextField: there aretwo Changed Events, but no “RowTag” equivalent where I could store a DirtyTag (and then later - at UPDATE time - save fields based on that Boolean), but beside HelpTag, nothing is available.

Adding a Boolean property for each changeable Control on the WIndow is less work that Jeff solution (probably), but still time consuming.

I have to take time to add this feature or… ask myself - and get an answer to that question - how many time an hour - for example - my user(s) modify the Data Base (traffic) ?

make a subclass of each control you use : textfield, textarea, checkbox, etc to myTextField, etc…
and use them everywhere in your app. (change the superclass for any control you need to personalize)
then if you need a property, simply add it to the myControl and it is available to all your app.
if you make them external classes, then they are available to all your apps each time you open them.

Yes ! Thanks Jean-Yves.

Bad to be an oldster :frowning: