Page 1 of 1

Patch for ZDbcPostgreSqlUtils

Posted: 15.05.2009, 13:20
by Ostfriese
I've modified CheckPostgreSQLError a little bit to remove a compiler hint which was thrown.

Code: Select all

procedure CheckPostgreSQLError(Connection: IZConnection;
  PlainDriver: IZPostgreSQLPlainDriver;
  Handle: PZPostgreSQLConnect; LogCategory: TZLoggingCategory;
  LogMessage: string;
  ResultHandle: PZPostgreSQLResult);

var ErrorMessage: string;
//FirmOS
    StatusCode:String;
begin
  if Assigned(Handle) then
    ErrorMessage := Trim(StrPas(PlainDriver.GetErrorMessage(Handle)))
  else ErrorMessage := '';
  if ErrorMessage<>'' then begin
    if Assigned(ResultHandle) then begin
{     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_SEVERITY)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_MESSAGE_PRIMARY)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_MESSAGE_DETAIL)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_MESSAGE_HINT)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_STATEMENT_POSITION)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_INTERNAL_POSITION)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_INTERNAL_QUERY)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_CONTEXT)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_SOURCE_FILE)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_SOURCE_LINE)));
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_SOURCE_FUNCTION)));
}     
     StatusCode := Trim(StrPas(PlainDriver.GetResultErrorField(ResultHandle,PG_DIAG_SQLSTATE)));
    end else begin
     StatusCode:='';
    end;
  end;



  if ErrorMessage <> '' then
  begin
    if Assigned(Connection) and Connection.GetAutoCommit then
      Connection.Rollback;

    DriverManager.LogError(LogCategory, PlainDriver.GetProtocol, LogMessage,      0, ErrorMessage);
    if ResultHandle <> nil then PlainDriver.Clear(ResultHandle);
    if PlainDriver.GetStatus(Handle) = CONNECTION_BAD then
      begin
        PlainDriver.Finish(Handle);
        //HA 090515 removed because never used
        //Handle := nil;
      end;
    raise EZSQLException.CreateWithStatus(StatusCode,Format(SSQLError1, [ErrorMessage]));
  end;
end;

Posted: 20.05.2009, 21:59
by mdaems
Wait a second... is this safe? No way this should set the passed value from the calling procedure to nil?

Mark

Posted: 22.05.2009, 13:58
by trupka
I think that Handle var is used in plain postgres driver. It seems that, if we don't set it to nil, there is possibility to call some libpq functions with uninitialized pointer.
What will happen then? I'm not even brave enough to try it. So I cowardly vote for - not safe