Finding the latest version number
Posted by smithce (smithce), 3 June 2005Hi
I am need of some inpiration/guidance.
I have the results of a query (of objects from our code control database) and need to identify the latest version of an object.
The problem is that the object version could be an integer, or (if the object has been 'branched') of the format n.n.n.n.
Here are some examples below:
I am stuck on how to compare the version numbers and therefore return the latest and greatest.
Any ideas/suggestions would be very welcome !
Posted by admin (Graham Ellis), 3 June 2005Hiya ... it's Friday afternoon, so please excuse a "Bull at a gate" approach. Test code:
Looks OK - but TEST IT FURTHER - your data didn't contain too many test cases our of order there may still be some bugs in my code.
Method - sort all the incoming records, then set up a has for each named object so that the later ones override the earlier ones. Once the hash is fully set up, it includes only the latest version numbers.
The sort algorithm splits out product name and release numbers and compares product name first. Where the product name is the same it loops through each dot separated parts of the version number and returns either +1 or -1 when it finds a difference. If it runs out of parts from $a first, it returns -1 and if it runs out of parts from $b first it returns +1. If both run out at the same time, it returns 0.
Posted by admin (Graham Ellis), 3 June 2005P.S. I moved some of your data lines around to test the sorting a little more thoroughly ....
Posted by smithce (smithce), 6 June 2005
Well...what can I say.
I need to do some further testing but that is amazing ...does exactly what is required.
Thanks you very much. I saw this Saturday morning but could not test it until today and it has certainly cheered up my dreary Monday !!!
This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho