2
votes

i need to check the sql server version every time my application installation begins through inno setup. but as sql creates the server version specific entry(like MySQL Server 5.1) as key in the registry, so i have to give the path like

HKLM\SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.1

while checking the version.
but when i install the sql server having version other than 5.1, it checks on the above path, it couldn't find. so again installation begins although it is already installed. so i want some generic path like

HKLM\SOFTWARE\Wow6432Node\MySQL AB\MySQL Server

which is not version specific. so that i can easily retreive the value from the MySQL key and check for it.My Code is

function fCheckMySQLInstall():boolean;
    var
  mysqlVersion : string;
begin
  bIsMyQLInstalled := False;
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.1', 'Version', mysqlVersion) = true then
    if CompareStr(mysqlVersion,'5.1') >= 0  then
      bIsMyQLInstalled := True;

  Result := bIsMyQLInstalled;
end;

as the path is /MySQL Server 5.1 which is not correct. should be generic for all version so that i can check for other version. Solutions are welcome.

2
m installing MySQL ServerRanjit Singh
Let me help you update your question. What's the most important here; your overall task is to find the (most recent) version number of the installed MySQL server. Is that correct ?TLama
thank you...yes. i want to check the most recent version installed in the system. dev.mysql.com/doc/mysql-windows-excerpt/5.1/en/… here is link which shows the entry is always version specific in the registryRanjit Singh
MySQL uses MSI installer for Windows (except that it can run with no installation, which you'd be having hard times to detect). Hence I think that instead of this registry ritual might be better to get the MSI product code and use the MSI API function to get the version. But take it as a hint, I have only bad experience with MySQL. Actually, I would pack the whole MySQL project into a box and shoot it into a deep space with the message how one should not develop and document DBMS.TLama
:) thank you for helping me.Ranjit Singh

2 Answers

1
votes

So basically you must enumerate the keys under 'SOFTWARE\Wow6432Node\MySQL AB\' using RegEnumKey(ex) and do the matching to "MySQL Server Vx.y" yourself, and determining highest version from that.

The Delphi/FreePascal registry unit provide functionality for enumerating keys that way, in Inno Setup you can use the RegGetSubkeyNames function for that.

0
votes

what i have done is. get all the versions of mySQL server from the registry(for how see the code below!). after extracting all the versions, compare the version of mysql to be installed to extracted version and decide whether to install or not. detailed explanantion is given in mycode.

if RegGetSubkeyNames(HKLM, URL, mysqlVersion) then
  begin
    counter := 0;
    specificVersion := '';
    for mysqlVersionIteration := 0 to GetArrayLength(mysqlVersion)-1 do begin
      specificVersion := mysqlVersion[mysqlVersionIteration];
     res := copy(specificVersion,1,12);
     if(res = 'MySQL Server')then
       if RegQueryStringValue(HKLM, URL+'\'+specificVersion, 'Version', Version) = true then
       begin
           SetArrayLength(extractedVersion, counter + 1);
           extractedVersion[counter] := Version;
           counter := counter + 1;
       end;    
    end;
    for CompareVersionCount:= 0 to GetArrayLength(extractedVersion) - 1 do begin 
        alreadyVersionExists:= copy(extractedVersion[CompareVersionCount],1,3);
        if CompareStr(alreadyVersionExists,'{#MySQLVersion}') >= 0  then
        bIsMyQLInstalled := True;
    end;
  end; 
  1. here URL is "SOFTWARE\Wow6432Node\MySQL AB" in case of win64 and 'SOFTWARE\MySQL AB' in case of win32
  2. iterate through all the subkeys.
  3. extract first 12 letters, because there might be other subkeys.
  4. if that extracted letter is MySQL then the key must have mySQL version.
  5. extract the version of that particular key.
  6. put all the version already present in the system in extractedVersion array.
  7. at last iterate through the extractedVersion array and compare it to version of mySQL to be installed and decide whether to install or not.

By this method my installer does what i supposed to do.