| |||||||||||
| |||||||||||
Finding the latest version number Posted by smithce (smithce), 3 June 2005 HiI 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: ACT_VAL_MOVEMENTS_SUMMARY.prc-3:sql:1 BOB_BENEFIT_COMPONENT.vw-16:ascii:2 BOB_ESCALATION_BASE.vw-10:ascii:2 BOB_ESCALATION_BASE.vw-11:ascii:2 BOB_GMP_COMPONENT.vw-17:ascii:2 BOB_PR_COMPONENT.vw-12:ascii:2 BasePkgs.sql-4.1.6:sql:2 BasePkgs.sql-4.1.7:sql:2 BasePkgs.sql-4.1.8:sql:2 F_GET_ANNUAL_AMT_PENCE.fnc-3:sql:1 LifeJoin.sql-4:sql:5 LifeJoin.sql-5:sql:5 PLA_error_summary.sh-8:shsrc:1 UAPS.pkg-3.1.27:ascii:1 UAPS_BENEFITCOMPONENT.pkg-10.1.11:ascii:1 UAPS_BENEFITCOMPONENT.pkg-11:ascii:1 UAPS_BENEFITCOMPONENT.pkg-12:ascii:1 UAPS_CONTRACTEDBENEFIT.pkg-13.1.14:ascii:1 UAPS_CONTRACTEDBENEFIT.pkg-13.1.15:ascii:1 UAPS_ESCALATIONBASE.pkg-10:ascii:1 UAPS_ESCALATIONBASE.pkg-11:ascii:1 UAPS_ESCALATIONBASE.pkg-12:ascii:1 UAPS_GMPCOMPONENT.pkg-13:ascii:1 VAL_EXTRACT.prc-43:sql:2 VAL_EXTRACT.prc-44:sql:2 VAL_EXTRACT.prc-45:sql:2 VAL_EXTRACT.prc-46:sql:2 VAL_EXTRACT.prc-47:sql:2 VAL_EXTRACT.prc-48.1.1:sql:2 VAL_EXTRACT.prc-48:sql:2 VAL_EXTRACT.prc-49:sql:2 VAL_EXTRACT.prc-50:sql:2 VAL_EXTRACT.prc-51.1.1:sql:2 VAL_EXTRACT.prc-51:sql:2 VAL_EXTRACT.prc-52:sql:2 VAL_EXTRACT.prc-53:sql:2 VAL_EXTRACT.prc-54:sql:2 VAL_EXTRACT.prc-55:sql:2 VAL_EXT_ANNUITY.sql-3.1.1:sql:1 VAL_EXT_ANNUITY.sql-7:sql:1 VAL_EXT_ANNUITY.sql-8:sql:1 VAL_EXT_AQUA_BULK_PREM.sql-4:sql:1 VAL_EXT_BNFT_COMP.sql-6:sql:1 VAL_EXT_BNFT_COMP.sql-7:sql:1 VAL_EXT_BNFT_COMP_CHG.sql-4:sql:1 VAL_EXT_CHILD_BNFT.sql-4:sql:1 VAL_EXT_CHILD_BNFT.sql-5:sql:1 VAL_EXT_CTRD_BNFT.sql-5.1.1:sql:1 VAL_EXT_CTRD_BNFT.sql-7:sql:1 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 2005 Hiya ... it's Friday afternoon, so please excuse a "Bull at a gate" approach. Test code:Code:
Results: 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 2005 P.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 !!! Many thanks Clive ![]() 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: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |