Problem with Updating SQL Database from DG
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Problem with Updating SQL Database from DG
Hello,
I have been creating an extensively customized Datagrid that interfaces with an SQL database. There are numerous user-editable fields in the rows of the DG, and I am implementing the EditFieldText pField, pIndex, pKey function from the Datagrid API to update the internal array automatically after the field is edited by the user.
The goal of this is to keep the internal array current, so the user may perform any action after making changes with full confidence that the changed information is saved.
I am trying to debug this, and am currently handling the CloseFieldEditor message in the card script to update the SQL database. Thus, whenever the focus leaves the field being edited, the internal array is grabbed and used to update the columns in the relevant table in the SQL db.
The Problem:
However, it is apparent that the CloseFieldEditor message is being handled before the internal array of the DG reflects the MOST RECENT CHANGE. So, when I retrieve the dgData, it is current EXCEPT FOR the last change made to any field in the datagrid.
It looks like a matter of timing between the automatic update of the internal array, and the time at which I can receive and handle the CloseFieldEditor message in the card script.
How can I overcome this, so that when the internal array is retrieved (preferably from the CloseFieldEditor handler), it is 100% current, rather than one change behind?
Hope that makes sense! I can include any scripts necessary, though I feel this hinges on my lack of understanding the order in which the engine processes different functions or commands.
Regards,
Phil E.
I have been creating an extensively customized Datagrid that interfaces with an SQL database. There are numerous user-editable fields in the rows of the DG, and I am implementing the EditFieldText pField, pIndex, pKey function from the Datagrid API to update the internal array automatically after the field is edited by the user.
The goal of this is to keep the internal array current, so the user may perform any action after making changes with full confidence that the changed information is saved.
I am trying to debug this, and am currently handling the CloseFieldEditor message in the card script to update the SQL database. Thus, whenever the focus leaves the field being edited, the internal array is grabbed and used to update the columns in the relevant table in the SQL db.
The Problem:
However, it is apparent that the CloseFieldEditor message is being handled before the internal array of the DG reflects the MOST RECENT CHANGE. So, when I retrieve the dgData, it is current EXCEPT FOR the last change made to any field in the datagrid.
It looks like a matter of timing between the automatic update of the internal array, and the time at which I can receive and handle the CloseFieldEditor message in the card script.
How can I overcome this, so that when the internal array is retrieved (preferably from the CloseFieldEditor handler), it is 100% current, rather than one change behind?
Hope that makes sense! I can include any scripts necessary, though I feel this hinges on my lack of understanding the order in which the engine processes different functions or commands.
Regards,
Phil E.
Re: Problem with Updating SQL Database from DG
Hi Phil,
you could:
1. ad a little delay in your CloseFieldEditor handler before getting the updated DGData:
on CloseFieldEditor
## ...
## ...
## let the EditorDo all what's neccessary and then:
send "update_all_the_stuff_from_DGData" to this cd in 100 millisecs
end CloseFieldEditor
THis way the datagrid has the time to update its internal stuff.
2. Use the data in the EditorField to update your DB directly in the CloseEditorField handler!
This is the way I do things over here.
Get the picture?
Best
Klaus
you could:
1. ad a little delay in your CloseFieldEditor handler before getting the updated DGData:
on CloseFieldEditor
## ...
## ...
## let the EditorDo all what's neccessary and then:
send "update_all_the_stuff_from_DGData" to this cd in 100 millisecs
end CloseFieldEditor
THis way the datagrid has the time to update its internal stuff.
2. Use the data in the EditorField to update your DB directly in the CloseEditorField handler!
This is the way I do things over here.
Get the picture?
Best
Klaus
Re: Problem with Updating SQL Database from DG
Hi, Klaus,
Yes, I think I get it.
So: call a handler on the card script after a delay that updates the database (from the CloseFieldEditor handler)
or
send the statement needed to update the DB directly from the CloseFieldEditor handler (which is what I am already doing)
Since I am already implementing the second suggestion, but am still having this problem, is there a possibility that I can just have the program wait to execute the SQL command creation and delivery from that handler?
Thanks,
Phil E.
Yes, I think I get it.
So: call a handler on the card script after a delay that updates the database (from the CloseFieldEditor handler)
or
send the statement needed to update the DB directly from the CloseFieldEditor handler (which is what I am already doing)
Since I am already implementing the second suggestion, but am still having this problem, is there a possibility that I can just have the program wait to execute the SQL command creation and delivery from that handler?
Thanks,
Phil E.
Re: Problem with Updating SQL Database from DG
Hi Phil,
Sorry, don't get it.
Best
Klaus
??? If you use "SEND XXX IN..." you already have the delay you need and you can even define the delay?Gage wrote:...send the statement needed to update the DB directly from the CloseFieldEditor handler (which is what I am already doing)
Since I am already implementing the second suggestion, but am still having this problem, is there a possibility that I can just have the program wait to execute the SQL command creation and delivery from that handler?
Sorry, don't get it.
Best
Klaus
Re: Problem with Updating SQL Database from DG
Hi, Klaus,
Ahh, I didn't mean "SEND"ing the statement. I meant that the CloseFieldEditor message is automatically sent by the engine, and I am handling that to update the database, but still having the problem.
To rephrase, I am not manually adding any "WAIT" commands of any sort anywhere. I thought your #2 suggestion was to use the CloseFieldEditor handler to create the statement to update the database to reflect the current data. I am doing that, and am experiencing the issue where the internal data has not been updated BEFORE the CloseFieldEditor handler executes, leaving my most recent change unreflected when I go to update the database in CloseFieldEditor.
So, my current method:
1. click on a field in the DG to edit its contents
2. EditFieldText with pField, pIndex, pKey parameters passed
3. edit the field as desired
4. move focus off field being edited
5. CloseFieldEditor is sent by engine and handled in DG group script
6. CFE handler in DG group script responsible for building statement to update the data using the dgData
The problem happens around number 5 and 6. Because I pass all three parameters with EditFieldText, the dgData should automatically update on CloseFieldEditor. However, I go to handle this message in order to update the database, but it appears that the dgData does not yet reflect the MOST RECENT CHANGE only (all previous changes are reflected, though). Since the dgData is not current, my update also does not reflect the most recent edit to a field in the data grid.
I hope that is more clear. Sorry about the ambiguity.
Thanks!
Phil E.
Ahh, I didn't mean "SEND"ing the statement. I meant that the CloseFieldEditor message is automatically sent by the engine, and I am handling that to update the database, but still having the problem.
To rephrase, I am not manually adding any "WAIT" commands of any sort anywhere. I thought your #2 suggestion was to use the CloseFieldEditor handler to create the statement to update the database to reflect the current data. I am doing that, and am experiencing the issue where the internal data has not been updated BEFORE the CloseFieldEditor handler executes, leaving my most recent change unreflected when I go to update the database in CloseFieldEditor.
So, my current method:
1. click on a field in the DG to edit its contents
2. EditFieldText with pField, pIndex, pKey parameters passed
3. edit the field as desired
4. move focus off field being edited
5. CloseFieldEditor is sent by engine and handled in DG group script
6. CFE handler in DG group script responsible for building statement to update the data using the dgData
The problem happens around number 5 and 6. Because I pass all three parameters with EditFieldText, the dgData should automatically update on CloseFieldEditor. However, I go to handle this message in order to update the database, but it appears that the dgData does not yet reflect the MOST RECENT CHANGE only (all previous changes are reflected, though). Since the dgData is not current, my update also does not reflect the most recent edit to a field in the data grid.
I hope that is more clear. Sorry about the ambiguity.
Thanks!
Phil E.
Re: Problem with Updating SQL Database from DG
Hi Phil,
I thought of scripting the "CloseEditorField" handler by yourself and use the
data that the user had entered to update the db BEFORE this is written back into
the datagrid and it gets updated!
Know what I mean?
Best
Klaus
I thought of scripting the "CloseEditorField" handler by yourself and use the
data that the user had entered to update the db BEFORE this is written back into
the datagrid and it gets updated!
Know what I mean?
Best
Klaus
Re: Problem with Updating SQL Database from DG
Klaus,
OK, yes!
Kind of like reinventing the wheel, but just because the built-in Field Editor functionality is a little flawed for how I am using it.
How can the Field Editor be accessed? I know CloseFieldEditor is sent with the parameter pFieldEditor, which I imagine contains the long ID of the Field Editor. So would I use script like this:
on CloseFieldEditor pFieldEditor
put the text of fld pFieldEditor into tText
--update DB using tText
end CloseFieldEditor
Let me know if that is about right.
Thanks for your help!
Phil E.
OK, yes!
Kind of like reinventing the wheel, but just because the built-in Field Editor functionality is a little flawed for how I am using it.
How can the Field Editor be accessed? I know CloseFieldEditor is sent with the parameter pFieldEditor, which I imagine contains the long ID of the Field Editor. So would I use script like this:
on CloseFieldEditor pFieldEditor
put the text of fld pFieldEditor into tText
--update DB using tText
end CloseFieldEditor
Let me know if that is about right.
Thanks for your help!
Phil E.
Re: Problem with Updating SQL Database from DG
Hi Phil,
yes, something like this.
I added this script to the datagrid GROUP directly (not the behavior) to update my DB
independently from the datagrid:
Best
Klaus
yes, something like this.
I added this script to the datagrid GROUP directly (not the behavior) to update my DB
independently from the datagrid:
Code: Select all
on CloseFieldEditor pFieldEditor
## tCurrentIndex is a local variable that I set "on selectionChanged pHilitedIndex, pPrevHilitedIndex" in the same script!
put pHilitedIndex into tCurrentIndex
## Get complete data of currently selected ROW
put the dgDataOfIndex[tCurrentIndex] of me into tData
## Get the text/value, that the user entered
put the text of pFieldEditor into tValue
## I "call" my db update routine with a little delay:
send "db_update XXX,YYY,tValue,1234" to me in 10
## MOST IMPORTANT:
## PASS CloseFieldEditor to let the dg behavior do its work :-)
pass CloseFieldEditor
end CloseFieldEditor
Klaus
Re: Problem with Updating SQL Database from DG
Klaus,
You help solve so many of my problems. I am sincerely grateful!
Have an excellent day!
Phil E.
You help solve so many of my problems. I am sincerely grateful!
Have an excellent day!
Phil E.