SELECTLATESTVERSION

Steve_ContrisSteve_Contris Member Posts: 114
I am curious about the SELECTLATESTVERSION function. The help says that this function "forces the latest version of the database to be used". How would it be possible to NOT be using the latest version of the database? I understand that in some cases I need to do appropriate locking to guarantee the latest version of a particular record, but what is the "latest version of the database" that this function seems to be referring to?
What would Elvis do?

Comments

  • garakgarak Member Posts: 3,263
    This function is to get the latest version of the data in the tables. It means, that you cache will be cleared and the client loads the data new.
    For example you have a batch where you load the item Table into and make there some changes. Now, after changeing you want to do a another modify on the recordvariable instance. To get now the latest "version" (and not the datas that you have in xour cache on recordVariable) u can call SelectLatesVersion.

    Hope understandable.

    Regards
    Do you make it right, it works too!
  • Steve_ContrisSteve_Contris Member Posts: 114
    Thanks for the reply but that does not really get to the details of my question.
    My understanding is that Navision native database uses an historical versioning scheme to accomplish what is done with transaction logging and rollbacks in other databases - sql for instance. I assume that once a record has been changed and becomes commited to the latest historical version in the database any subsequent reads by any users will retrieve the latest version of that record. I don't have to do anything special programming-wise to be sure that the data I read reflects any changes that have been made by other users before my read. If that was not true, Navision would just not work in a multi-user environment.
    So I will re-phrase my question a bit: When would it be necessary to use this function instead of just re-reading the record or records that I am interested in? In what kind of situation would I be reading a record from a version in the database that is not the latest?
    What would Elvis do?
  • DenSterDenSter Member Posts: 8,307
    It is a function meant to work mostly on native, where it would only check the timestamp. If it's still the same between the record in the database and the one in memory all is well, and if it is different it gets the record again.

    You would typically use it when a record is retrieved from a 'hot' table (a table with many updates to records), and where there's a lot of checking going on before updating the record, when there is 'a lot of time' between getting the record and actually modifying it, when there might be a chance that someone else modified the record that you retrieved between the time that you retrieved it and the time that you need to update it. Other examples are NAS instances that run for long periods of time, and you'd use it to refresh setup records.

    Personally I've always used new GET statement, I always like to be explicit in my code and I think I had an issue with it early on in my career. I don't think there's a lot of use for it on SQL Server, doing a new GET essentially does the same thing.
  • Steve_ContrisSteve_Contris Member Posts: 114
    Thanks for the explanation. I only recently came across the use of this function in someone else's code and was kind of puzzled by it. It was being invoked at the end of a function that did some updating to a 'hot' table. But, given your explanation, why they would invoke it as the last line of the function still puzzles me.
    Also, if I was concerned about having the latest version of a record before using or modifying data from said record, I would use locking. Otherwise, in a multi-user environment there would never be any guarantee that what you have is the latest data - even using this function.
    What would Elvis do?
  • dougshepard3dougshepard3 Member Posts: 8
    I use SELECTLATESTVERSION when I know data in the table may have been recently updated outside of NAV - so the cache may be outdated because it's not aware of those changes.
  • Remco_ReinkingRemco_Reinking Member Posts: 74
    Or you use it when there are multiple servicetiers running. eg one to handle webservice calls and another that is running scheduled tasks. To be sure you have the latest version of a record, one that might have been changed on the other servicetier, you only get it using selectlatestversion and then do the record.GET
Sign In or Register to comment.