Jump to content
Sign in to follow this  
DarrenWhite99

Comparing complex version numbers for Files, Applications, etc.

Recommended Posts

Automate installations provide a number of custom MySQL functions. These helped fill particular needs within the program, but they can help you too!.

Suppose you have two version numbers, like VER1=10.3 and VER2=10.2. Trying to compare them directly is a StringComparison and returns only 1 or 0 (True or False). A proper version comparison will tell you if VER1 is LESS than, EQUAL to, or GREATER than VER2.

The custom function LT_CompareVersions('VER1','VER2') will do just this.

Here is how the function works in practice. If VER1 is greater, the result should be "1", if it is less it should be "-1", and "0" if equal.  

            Evaluating,  StringCompare,  VersionCompare,  ShouldBe
            '11.34>11',            '1',             '1',       '1'
          '11.34>11.4',            '0',             '1',       '1'
       '1.10.0>11.0.0',            '0',            '-1',      '-1'
       '2.10.0>11.0.0',            '1',            '-1',      '-1'
'11.34.0.0>11.4.99.99',            '0',             '1',       '1'

You can see that a simple version compare will work with VER1>VER2, but when they get more complex you would get the wrong result each time.

Here is an example using the "IF SQL Check" script function. In my test, I want to know if the DiscoveredVersion is greater than my TargetVersion:

IF [SQL SELECT (LT_CompareVersions('@DiscoveredVersion@','@TargetVersion@') > 0) AS VerResult]  =  1  THEN  Jump to :NoUpgradeNeeded


 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...