Thursday, November 20, 2014

Check PostgreSQL version on the machine

Hi All,
Please use the reference from the below custom action I have created for checking the PostgreSQL version on your machine.

function CheckPostgresSQLVersion(hMSI)
STRING ProcessName, szLine, Text,svReturnLine;
NUMBER nvFileHandle, ExitCode,nvResult,nvLineNumber,nLoc;
begin
ProcessName = "CheckPostgresSQLVersion";
OpenFileMode (FILE_MODE_APPEND);
if (CreateFile (nvFileHandle, SUPPORTDIR, "PostgresSQLVersion.bat") = 0) then
szLine = "psql --version";
WriteLine(nvFileHandle, szLine);
endif;

// Close the file.
CloseFile (nvFileHandle);

ExitCode = RunApplication(hMSI, SUPPORTDIR^"PostgresSQLVersion.bat", " >PostgresSQLVersion.txt", "");
if (ExitCode = 0) then
GetFullErrorText(hMSI, 60, SUPPORTDIR, "PostgresSQLVersion.txt", Text);
nvResult = FileGrep (SUPPORTDIR ^ "PostgresSQLVersion.txt", "psql (PostgreSQL)", svReturnLine,nvLineNumber, RESTART);
if(nvResult = 0) then
nLoc = StrFind(svReturnLine,"9.1");

if(nLoc<0 p="" then=""> MsiSetProperty(hMSI, "INVALID_POSTGRESQL_VERSION", "1");
MessageBox("Invalid version of PostgreSQL",SEVERE);
else
MsiSetProperty(hMSI, "INVALID_POSTGRESQL_VERSION", "0");
endif;
endif;
endif;
DeleteFile(SUPPORTDIR^"PostgresSQLVersion.bat");
end;