[patch_done] PostgreSQL + C++Builder 2010 Assigning Port

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

markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

[patch_done] PostgreSQL + C++Builder 2010 Assigning Port

Post by markus »

Hi,

I've finally decided to switch to testing-egonhugeist branch.
When i'm trying to assign Port of ZConnection in code:
ZConnection1->Port = 5432;
i get message
[ILINK32 Error] Error: Unresolved external '__fastcall Zabstractconnection::TZAbstractConnection::SetPortW(const const int)'
i thought it might have something to do with my app being run on wchar_t mapping, but when i switched to char mapping i got:
[ILINK32 Error] Error: Unresolved external '__fastcall Zabstractconnection::TZAbstractConnection::SetPortA(const const int)'

Weird thing is that when i assign proper port on design time in Object Inspector - it works fine.
I can change other connection params (Host,Database etc.) in my code without any problems.

did something changed in connection parameters?

Best regards,
Marek
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Hmm, tried to follow you.
But everything is fine.

Are you up to date? Latest revision.
What exactly you are doing?

Michael

Btw. Yes we changed a lot concerning the connection parameters. But mostly on dbc-layer and minior on the component-layer.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post by markus »

Yes i used latest svn revision (1143)
I did these steps:
1. create Empty VCL project
2. Plate TZConnection component
3. in form constructor type: ZConnection->Port = 5432;
it fails to do linking with errors from my previous post.
When you set port in Object Inspector - everything is ok.

Btw:
i downloaded build 1144 today, and got messages:
[BCC32 Error] Zplainoracle9i.hpp(256): E2015 Ambiguity between 'BOOL' and 'Zplaindblibdriver::BOOL'

i've noticed that BOOL type was added in Zplaindblibdriver in this revision. Should i change something in my packages creation?
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Hmm,

the BOOL issue is solved Rev. 1146.

The connection assignments making me curious:

constructor TZAbstractConnection.Create(AOwner: TComponent);
begin
FURL := TZURL.Create;

inherited Create(AOwner);

MDeams and me removed the Port, Database, etc. Fields from the TZAbstactConnection. We exchanged this with the TZURL-class because we've detected a never reported leak in our Sources for direct Dbc users.

If you've access problems then this coul'd only have one reason: The TZURL-class isn't assigned when you call ZConnection.Port := 1234; inside the TForm.constructor, right?

I tested it with FPC/Delphi7/2007/XE Compiler and can't find out what's going wrong.

I'll write the project manager concerning this bug. A workaroud: Assign this Values in OnShow or OnPaint.

Can you debug the lines exactly? Is it possible that the ZURL isn't assigned in the ZConnection in the OnCreate-Event?

best regards
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post by markus »

TForm constructor is just example of this issue.
I'm using DataModule in my application, but problem is the same.

I cannot pinpoint exact line of code that causes error, because it's linker error.
When i compile Delphi packages to c+ builder *.hpp files are created automatically. But what is strange: SetPortW and SetPortA are functions that are ment for WideString and AnsiString.

I've also got problems with UTF8 encoding with new revisions - but i'm trying to prepare case study, and this might take some time.
Generally my app needs to run in UTF8, because i'm having both polish chars and thai chars at the same time in DB.
my PostgreSQL 9.0 DB is running in UTF8.
I've tried experimenting with new options: TZConnection.PreprepareSQL or CodePage, but in result i got chinese chars in my app...
in rev.903 everything was flawless for me - insert/update of db fields. even filtering witch thai chars.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Wide/Ansi functions i use a lot. But they are actually not in use. Look at ZCompatibility.pas there you'll find a lot of Character-functions but actually they are defined out {$IFDEF WITH_CHARCONTROL} Now i can't say if this behavior is result of using these functions in the Sources -> no C-Builder expieriences or from somewhere else.

Strange for me is your PG9 behavior. Question: did you use a older version before? They are playing with "StandartConformingStrings=True". From 8(False) to 9(true again). And i know Zeos has some own PostgreSQL String-Encodings in the Sources, which "normaly" have no Unicode effect. Look at ZDbcPostgreUtils.Pas function EncodeString.

Hmm my ClientCodePage is the connection CharacterSet, an indicator for the Wide down/up behavior between the component-layer and the dbc-layer (function ZAnsiString/ZString), and the choosen FieldTypes (TString/WideString-Fields). Do you use a unicode one? This is simple i think.

Concerning that Unicode PG9 behavior: What happens exactly? Insert/Edit of some Components? What are you doing? Do you've predefined Fields from type ftString?

And concering the Henk ZxxPlainxx.pas thread. Can you attach a patch?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post by markus »

I used psql 8.4 and later moved to 9.0 - both accessed with Zeos 7, but older revisions (903 is my latest). Everything worked ok.

Today i looked more closely - only fields that cause trouble are text fields which are in fact blobs. Fields defined in db as varchar are displayed OK. Sorry for not describing this properly in first place.
This one is wit rev 903, client_encoding=UTF8, charset=UTF8
Image

This one rev latest, client_encoding=UTF8, charset=UTF8, prepareSQL=true
Image

Both screen shots are from the same application, the same database. Only difference is Zeos version.

I'm basically using ZQuery everywheree in my app with almost all default options. SQL is inserted in my code like: Query1->SQL->Text = "select ...". I do not use fields defined in design time - i always rely on type returned by query. I also don't use data aware components (except DBGrid of course;) ). I always get vaules maually in Query.AfterScroll event: ie. for memo field i do:

Code: Select all

mOpis->Lines->Text = DataSet->FieldByName("opis")->Text;
For all Memo and WideMemo fields i also use OnGetText event:

Code: Select all

void __fastcall TGridFrame::getText(TField *Sender, UnicodeString &Text, bool DisplayText)
{
	String tmp = Sender->AsString;
	if ( tmp != "")
		Text = tmp;
}
If You need any additional information, more of my code od DB dump - i'll be happy to provide You more info
I'm attaching few files:
fixed cbuilder ZPlain project
i also ran into problems wit types declared ZPlainDbLibDriver.pas - INT and SHORT - my compiler detected ambiguity between this file and winsock2.h
You do not have the required permissions to view the files attached to this post.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Ok Markus,

patch accepted and commited Rev.1147 (/testing-egonhugeist)

Concerning the Text-Blob behavior:

I know about that bug(???). And i know that the Trunk and the normal testing-branch don't have this behavior. This is a part, i actually havn't completed.
The reason why you see now such cryptical stupid letters:
On asking the Dataset for ->Text or ->String you'll get a 1byte AnsiChar sequence (UTF8) but a full unicode ide expects 2Byte WideChars in this case. So what happen's if you use Dataset->FieldbyName('opis').AsWideString?

So that's my fault. I patched this because of the testsuites which expected always the same sice of the stream between the component-layer and the dbc-layer. Which seems impossible with the unicode ide's... btw. it was only in the Postgre units done.

Let me see if i can improve something directly on the AbstractRODataset which is the interface between Zeos and the DB classes in this case..

If you find a lolution quickly, don't hesitate and attach a patch...

Thank you.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post by markus »

EgonHugeist wrote: So what happen's if you use Dataset->FieldbyName('opis').AsWideString?
It's the same.
CBuilder maps AsString and AsWideString both to UnicodeString type result.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

I know whats going wrong now...

I'm able to display everything right, like my attached pic shows you. But the written data in the Text-field is Byte encoded+escaped. When you're trying to read the Textfield i decode the Data (hmpf that beahvior is clearly wrong.)

Give me the Friday too, ok? Or i'll post if the bug is gone.

Best regards
You do not have the required permissions to view the files attached to this post.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post by markus »

No rush:)
Take your time and rest some time too...

We all owe You big THANKS for fighting with unicode in Zeos.

I'll do my best to help where i can too.

Best regards,
Marek
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Proposal:

Open ZDbcPostgreSqlResultSet.pas. Goto:

function TZPostgreSQLResultSet.GetString(ColumnIndex: Integer; const CharEncoding: TZCharEncoding = {$IFDEF FPC}ceUTF8{$ELSE}ceAnsi{$ENDIF}): Ansistring;

and comment this lines out:
//if not ( GetMetaData.GetColumnType(ColumnIndex +1) = stBinaryStream ) then
//Result := DecodeString(Result);

What happens?

Btw. if you open the PGAdmin and check the text-blob-field do the values look like:
"\344\000\374\000\344\000\374\000\344\000\374\000\344\000\374\000\344\000\015\000\012\000" (escaped from Zeos)
or are they clear readable?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post by markus »

My old values are clearly readable in pgadmin

When i applied Your patch - it didn't changed anything. Text fields are still wrong.
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post by markus »

i've found what caused problem with assigning port.
It seems that SetPortA and SetPortW are definded in files included by vcl itself.
So when i tired to use Zabstractdataset::SetPort indirectly - it was ambiguity.
http://edn.embarcadero.com/article/20125

When i changed SetPort and GetPort to SetConnPort and GetConnPort in ZAbstractConnection and ZConnection
code like this:

Code: Select all

ZConnection1->Port = 5432;
Worked like a charm:)
You do not have the required permissions to view the files attached to this post.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

That's great! Thanks, patch will be commited tonight.

Actually i'm working on changind the UnicodeStream behavior. I have a solution but not compiler neutral. So it could take a while...Hmpf.
If it's ready i'll inform you here..
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Locked