[bug_fixed] BUG in TZPostgreSQLConnection.Open;

The alpha/beta tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.

This is a forum that will be removed once the 7.X version goes into stable!!

Moderators: gto, EgonHugeist, olehs

Locked
mariuszekpl
Senior Boarder
Senior Boarder
Posts: 54
Joined: 30.09.2008, 10:59

[bug_fixed] BUG in TZPostgreSQLConnection.Open;

Post 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;
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

SVN Rev. 533
Image
Locked