Assume we have a code snippet such as what follows:
SomeTable.SETRANGE(field1,<somevalue>);
IF SomeTable.FIND('-') THEN
REPEAT
<do some processing>
UNTIL SomeTable.NEXT = 0;
What happens if during the <do some processing> portion it changes the field1 value of the current record. I can't remember, and I was hoping someone might help me out without having to run some tests.
Will 'NEXT' still proceed to the next record correctly or will some records get skipped? Oh and to complicate things more, what happens if you have 2 or more processes all running this same logic. What happens when one of the other processes updates the value of field1 in a record that the current process hasn't reached yet? Will it get filtered out? Will the Next loop work correctly? (I should clarify that when I say "hasn't reached yet", I mean the current process has already begun looping through the records before the other process updated the specified record)
Thanks in advance everyone.
Thad Ryker
I traded my sanity for a railgun

Comments
If another process is doing the same, on Navision it will be blocked by current session because of tablelocks.
On SQL, a session can get blocked until the first is freed or the second has waited too long (see "Timeout Duraction" in tab advanced when creating a new DB or altering the DB). It is also possible one of both has a deadlock, EVEN IF THE RECORDS THEY CHANGE ARE COMPLETELY DIFFERENT! This last because in 1 page are records of both sets and SQL can also lock pages in stead of records.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
How would this particular operation deadlock? Since they are locking the same table it shouldn't be a possibility should it (or do you mean if each process is also using another table in common)?
Oh and thanks:)
I traded my sanity for a railgun
Regarding locking, the COMMIT function alone does not lock the table. The function LOCKTABLE locks the table. If you modified a record during a process while another person is on the same record, if they try to modify something they'll get a "Another User has modified...." message.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
I traded my sanity for a railgun
If you do place a commit within the loop, then you must also be able to recover from a partially completed loop.
I traded my sanity for a railgun
You talked multiple NAS for loadbalancing. Loadbalancing what? The performance of the DB? This will not be resolved by multiple NAS's. In this case better 1 NAS... and this risolves also the locking problems between NAS's.
Important to note here is that the table is not locked after the LOCKTABLE statement! :shock: This because Navision buffers the write commands on the client and ONLY when the buffer is full or an immediate action is expected from the DB (like a FIND or GET) the LOCKTABLE is send to the DB.
If on the other hand you use the debugger, Navision does NOT buffer the write commands!
Conclusion: if you REALLY want to lock the table at the moment of the LOCKTABLE-command, put a FIND or a GET behind it (even if you know the record you FIND or GET does not exist).
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Incidentally an issue that could impact this, is another thread I posted about SQL NAS and multithreading. Someone told me that SQL NAS is multithreaded, which if this is true I wouldn't have to use multiple NAS's to balance requests for response times. However, at this point I've been unable to substantiate this claim.
I should also note another thing about that code sample: When I used FIND('-'), I would of course be using FINDFIRST in SQL. I do appreciate everyone's feedback, I'm hoping to avoid problems others have already discovered:) Why re-invent the wheel and all that ...
I traded my sanity for a railgun
By the way, to answer your question...
Don't ever modify any fields that are used for filtering in the rec variable that you are looping in. Instead, use a second variable for the modifying part: If you do MODIFY on MyFirstRec, Navision will lose its place in the set of records, because it will retrieve a new set, and it will not include the modified record. If yuo use MySecondRec, it will write the new value to the database, but will leave MyFirstRec undisturbed in memory and it will move to the next one without a problem.
RIS Plus, LLC
Thanks for that breakdown Denster, I always wondered about the specifics behind how the Navision find worked, and what happened when you did 'Rec1 := Rec2', but I never found any clear docs that explained it. Knowing these things can only make me a better programmer:) (as long as I apply the knowledge correctly
Anyone know by chance whether that Nas SQL multithreaded thing is true or false?
I traded my sanity for a railgun
FIND('-') was meant as 'get the set of records and point to the first one', and was also used for various other purposes. On SQL Server there's not enough information to know what you are going to do with it. Are you going to loop? do you just want the first record? Do you want to know if records exist?
FINDFIRST/FINDLAST basically means 'get the first/last record, but only the one record. You intend to only use that first/last record, and you do not intend to loop through any set of records. You would for instance typically use FINDLAST to determine the last used Line number in a journal table.
If you only want to know if records exist, you should use ISEMPTY. FINDFIRST and FINDLAST return a whole record, ISEMPTY returns only a bit (yes/no) and is therefore quicker.
Now if you want to get a set of records, with the intent of looping through, you use FINDSET, and you can read online help to find out what the parameters are (there are two of them).
So:
- if you want to know if records exist: ISEMPTY
- if you want one record: FINDFIRST/FINDLAST
- if you want to loop: FINDSET(boolean,boolean)
RIS Plus, LLC
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
So better use an extra record-variable.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
The second variable is the best solution...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.