Page 1 of 1

[bug_fixed] BUG in TZPostgreSQLConnection.Open;

Posted: 28.11.2008, 23:58
by mariuszekpl
Error in generate SQL for SET CLIENT_ENCODING TO

IS

Code: Select all

procedure TZPostgreSQLConnection.Open;
var
  LogMessage: string;
  QueryHandle: PZPostgreSQLResult;
  SQL: PAnsiChar;
begin
  if not Closed then
    Exit;

  LogMessage := Format('CONNECT TO "%s" AS USER "%s"', [Database, User]);

  { Connect to PostgreSQL database. }
  FHandle := FPlainDriver.ConnectDatabase(PAnsiChar(BuildConnectStr));
  if FPlainDriver.GetStatus(FHandle) = CONNECTION_BAD then
    CheckPostgreSQLError(nil, FPlainDriver, FHandle, lcConnect, LogMessage,nil)
  else
    DriverManager.LogMessage(lcConnect, FPlainDriver.GetProtocol, LogMessage);

  { Set the notice processor (default = nil)}

  FPlainDriver.SetNoticeProcessor(FHandle,FNoticeProcessor,nil);

  { Sets a client codepage. }
  if FClientCodePage <> '' then
  begin
    SQL := PAnsiChar(Format('SET CLIENT_ENCODING TO ''%s''', [FClientCodePage]));
    QueryHandle := FPlainDriver.ExecuteQuery(FHandle, SQL);
    CheckPostgreSQLError(nil, FPlainDriver, FHandle, lcExecute, SQL,QueryHandle);
    FPlainDriver.Clear(QueryHandle);
    DriverManager.LogMessage(lcExecute, FPlainDriver.GetProtocol, SQL);
  end;

  { Turn on transaction mode }
  StartTransactionSupport;
  { Setup notification mechanism }
//  PQsetNoticeProcessor(FHandle, NoticeProc, Self);

  inherited Open;
end;
SHOULD BE

Code: Select all

procedure TZPostgreSQLConnection.Open;
var
  LogMessage: string;
  QueryHandle: PZPostgreSQLResult;
  SQL: PAnsiChar;
begin
  if not Closed then
    Exit;

  LogMessage := Format('CONNECT TO "%s" AS USER "%s"', [Database, User]);

  { Connect to PostgreSQL database. }
  FHandle := FPlainDriver.ConnectDatabase(PAnsiChar(BuildConnectStr));
  if FPlainDriver.GetStatus(FHandle) = CONNECTION_BAD then
    CheckPostgreSQLError(nil, FPlainDriver, FHandle, lcConnect, LogMessage,nil)
  else
    DriverManager.LogMessage(lcConnect, FPlainDriver.GetProtocol, LogMessage);

  { Set the notice processor (default = nil)}

  FPlainDriver.SetNoticeProcessor(FHandle,FNoticeProcessor,nil);

  { Sets a client codepage. }
  if FClientCodePage <> '' then
  begin
  {$IFDEF ZEOS_FULL_UNICODE}
    SQL := PAnsiChar(utf8string(Format('SET CLIENT_ENCODING TO ''%s''', [FClientCodePage])));
  {$ELSE}
    SQL := PAnsiChar(Format('SET CLIENT_ENCODING TO ''%s''', [FClientCodePage]));
  {$ENDIF}
    QueryHandle := FPlainDriver.ExecuteQuery(FHandle, SQL);
    CheckPostgreSQLError(nil, FPlainDriver, FHandle, lcExecute, SQL,QueryHandle);
    FPlainDriver.Clear(QueryHandle);
    DriverManager.LogMessage(lcExecute, FPlainDriver.GetProtocol, SQL);
  end;

  { Turn on transaction mode }
  StartTransactionSupport;
  { Setup notification mechanism }
//  PQsetNoticeProcessor(FHandle, NoticeProc, Self);

  inherited Open;
end;

Posted: 03.12.2008, 11:49
by mdaems
SVN Rev. 533