M.Folte
Posts: 3
Joined: Sun Nov 27, 2022 10:04 am

Best practice: Execute SQL scripts based on version

Sun Nov 27, 2022 10:16 am

Hello,

im currently evaluating AI and am making good progress so far.

However one feature we need for our installer/upgrader to execute SQL scripts based on the already installed version.
1.png
1.png (2.97KiB)Viewed 17708 times
We have one init script which is only to be executed for a new installation. That was easy enough to accomplish with the condition

Code: Select all

NOT OLDPRODUCTS
. However now we have a list of multiple update scripts which are only to be executed if the installed version is smaller than the version of the script.

The first solution that came to mind is to setup a search that reads the current installed version from the registry. I set up my upgrades so the old version is only uninstalled after the installation of the new version. And in theory it works perfectly well with a condition like

Code: Select all

INSTALLED_VERSION < "2.4.4"
.

However we get problems when we go past single digits versions. This systems breaks once we reach version 2.4.10. The condition

Code: Select all

INSTALLED_VERSION < "2.4.10"
won't work because 2.4.10 is actually smaller than 2.4.4 if we compare them as strings.

Is there a way to compare strings as version numbers in the conditioning?

If not I already came up with a workaround. However this workaround would require me to add a new search property for every version like so:
2.png
2.png (14.16KiB)Viewed 17708 times
And then use a condition like

Code: Select all

VERSION_2.4.2_INSTALLED = ""
. But I feel like I'm missing something and there is a better way to do this.

Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Best practice: Execute SQL scripts based on version

Tue Nov 29, 2022 12:05 pm

Hello and welcome to our forums.

Indeed, the properties are compared as strings and they cannot be compared as versions, unfortunately. In this case, the workaround you found, which requires a new search for each script, is the best option.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

M.Folte
Posts: 3
Joined: Sun Nov 27, 2022 10:04 am

Re: Best practice: Execute SQL scripts based on version

Fri Dec 02, 2022 1:44 pm

Hello and thanks for the welcome.

Okay, not a problem at all. The workaround works and will do the trick for us. Was just wondering if there was a better way.

Best regards,
Matthias

Liviu
Posts: 1035
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Best practice: Execute SQL scripts based on version

Fri Dec 02, 2022 3:44 pm

Hello Matthias,

Thank you for your follow-up.

Please let us know if you have any other questions.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”