In this example, 203 is the correct integer and I'm running this getNextId query before the actual Insert query, when the button in form is pressed. Below is the statement using the nextAvailableId variable:
I use AUTO_INCREMENT for all my Primary keys, so I never have to generate the Id values.
But here are just a couple of thoughts...
What is the time different between those two actions in your log. Is getNextId run a good time before the SQL query, or at the last moment before the SQL? Is there any risk that the operations overlap?
Where is that variable nextAvailableId located in the App. I've had some problems where the debug/help that pops up when I hover over a value makes it look like all is fine, but at runtime it turns out that the variable is not in scope of that particular piece of code.
Thanks for your reply. I tried not to add "id" in the query, since I was expecting it to auto increase, but that caused another error which I don't remember at the moment, that's the reason I decided to do it manually:
nextAvailableId is triggered when the form submit button is clicked. Then form2SubmitHandler immediately. Could that "immediate" run a problem, maybe the second query runs before the firs one complete and passing the value to the second one?
I'm no expert on this, but I found that adding await before the first function call can help to make the processing wait until the function has completed before starting the next one.
Instead of using two event handlers for submit button (which runs parallel) I now run only getNextId and run form2SubmitHandler as a Success handler. That way getNextId finished the work, adds value to nextAvailableId variable and then runs the insert query.
Thanks for sharing an update, @MuzafferB! Glad to hear you figured this out. Sometimes it can be very helpful to force certain queries to run in sequence instead of in parallel.