NetTalk Central

Author Topic: Blank records in database  (Read 4674 times)

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Blank records in database
« on: January 16, 2012, 06:48:12 AM »
If I have Prime auto inc even if not necessary checked on the Advanced tab of a form because I have a child browse on one of my tabs a record is created in the parent table. This is what I expect.
However, if the user then moves away from the form without saving a record the record with  the autoincremented field is left in the table.
How do you handle this issue?
1. Leave the record there
2. Write some code to remove the record and its ( possible children)
If so what code are you using and where?
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Blank records in database
« Reply #1 on: January 16, 2012, 03:52:15 PM »
If they move away without clicking cancel then I would think it is reasonable to leave it there. If they click cancel then I add some cleanup code to remove the records on an insert and revert the records back on a change.

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Blank records in database
« Reply #2 on: January 16, 2012, 09:51:07 PM »
Hi Kevin
Thanks for the comment.
The problem with that is the browse displays a whole lot of blank records, normally at the beginning of the table since there is no default sort value.
If they cancel I have no problem removing the (possibly) created child records if it is an insert, but if they move off to another menu choice which they are prone to do since they could do it in a Win32 app I am left with this blank record and possible children.
My query was where would you put the code to periodically clean up the parent and children records in the above situation.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Blank records in database
« Reply #3 on: January 16, 2012, 10:44:03 PM »
My query was where would you put the code to periodically clean up the parent and children records in the above situation.

>> You could add it to the parent browse. So as it loops to build the table delete any blank records. Of course this only deletes those as it tries to load them but at least they won't see them. The downside to deleting them is you may also delete a record that a user has just added but is still in the process of completing. Tricky one. Maybe just filter them out and run the delete code when you start the web server or add a button to the web server window which you can log in and push every so often to run your clean up code. Just some random ideas...

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Blank records in database
« Reply #4 on: January 16, 2012, 11:25:40 PM »
Here's my approach. It's overkill, so water down to suit your needs.

a) add a field to the table called "completed". Set this to 1 when the user clicks on 'Save'.
b) add two fields; DateCreated, TimeCreated to the record. Prime these when the record is made. (ie use the Priming tab).
c) create a procedure (normal clarion source) which runs through the table, deletes all "incomplete" records "older than x".

I start the procedure, (using START, so it's on a separate thread) from the WebServer. This could even be a separate exe really.
Using the Take Event method you can start it say once a day, or as often as you like.

cheers
Bruce

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Blank records in database
« Reply #5 on: January 17, 2012, 12:49:43 AM »
Thanks Bruce and Kevin
Thats what I'll do
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Blank records in database
« Reply #6 on: January 24, 2012, 12:02:03 AM »
Bruce
Topspeed tables
Because I have a child browse in the form I check Prime Auto Inc even if not necessary on the parent form. Is this correct, if not under what circumstances would I use this check field?
The creates a record with only the incremented parentID all other fields including the primed fields are blank in the table.
 This means that if the user chooses another menu choice or closes the browser all that is left is the record with the parentid, no primed field values.
So would the best way be for me to remove all records where completed = 0 since any record with completed = 1 has been saved?
The obvious problem with that is that I could be removing a record that in the process of being added but since my users are in normal office hours I can schedule this to run later in the evening.
How would you handle this problem is the users were worldwide?
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Blank records in database
« Reply #7 on: January 24, 2012, 12:50:04 AM »
>> Because I have a child browse in the form I check Prime Auto Inc even if not necessary on the parent form.   Is this correct

If there's a brows eon the form it falls into "necessary" so it should go this route without you checking that box.

>>, if not under what circumstances would I use this check field?

when you wanted the record to be created as the form is opened - usually because you want the record to be there for hand-code purposes.

>> The creates a record with only the incremented parentID all other fields including the primed fields are blank in the table.
 This means that if the user chooses another menu choice or closes the browser all that is left is the record with the parentid, no primed field values.

correct. (I think dictionary priming is applied - via the usual ABC triggers) - however I would have expected the priming to occur... that's something I might switch-around.

>> So would the best way be for me to remove all records where completed = 0 since any record with completed = 1 has been saved?

as mentioned elsewhere, I'd only set the "completed" value in the "ValidateRecord" embed. that's the safest long-term option, and doesn't rely on the fields _not_ being primed.

>> The obvious problem with that is that I could be removing a record that in the process of being added but since my users are in normal office hours I can schedule this to run later in the evening.
How would you handle this problem is the users were worldwide?

This is why in the earlier note I refereed to a "create date" and "create time".  you'd want the records to be of a certain age before deleting them. That said, if the "priming" occurred first then it makes it a lot easier to set the date & time.

Cheers
Bruce

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Blank records in database
« Reply #8 on: January 24, 2012, 01:00:36 AM »
>> however I would have expected the priming to occur... that's something I might switch-around.

done for 6.17
I'm guessing (hoping really) this won't affect anyone, but it makes more sense to be able to prime fields before the initial add. This is necessary, for instance, to handle the case where you have multiple unique keys on the record. (where the other keys do not have "exclude nulls" ticked.)

Bruce

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Blank records in database
« Reply #9 on: January 24, 2012, 01:02:22 AM »
Thanks
preempted my question
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186