Change Schema in ZConnection with PostgreSQL

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
huelbert
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 28.07.2022, 02:17

Change Schema in ZConnection with PostgreSQL

Post by huelbert »

Goodnight

I'm starting a project with Zeos version 8.0.0-beta + PostgreSQL, the intention is to create several Schemas in a single database, one for each client.
In ZConnection I am not able to set the Schema.

Can you help me
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Change Schema in ZConnection with PostgreSQL

Post by marsupilami »

Hello huelbert,

usually this should work if you specify the schema in the Catalog property of TZConnection. If this doesn't work, please let me know.

Best regards,

Jan
huelbert
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 28.07.2022, 02:17

Re: Change Schema in ZConnection with PostgreSQL

Post by huelbert »

Good Morning

I did a test putting a ZConnection and coded the properties as the code:

Code: Select all

  
  ZConnection1.Disconnect;
  ZConnection1.Protocol := 'postgresql';
  ZConnection1.ClientCodepage := 'UTF8';
  ZConnection1.HostName := 'localhost';
  ZConnection1.Port := 5432;
  ZConnection1.Catalog := edSchema.Text;
  ZConnection1.User := 'postgres';
  ZConnection1.Password := 'masterkey';
  ZConnection1.Database := 'delphi-factoring';
  ZConnection1.Connected := True;
 
It only connects to the public schema.
I am sending the example in the attachment.
You do not have the required permissions to view the files attached to this post.
MJFShark
Expert Boarder
Expert Boarder
Posts: 211
Joined: 04.06.2020, 13:59

Re: Change Schema in ZConnection with PostgreSQL

Post by MJFShark »

I'm not sure setting catalog works for Pg. Pg's "current schema" handling is a bit different than other databases. I just run

set search_path = MySchema

after login.

-Mark
huelbert
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 28.07.2022, 02:17

Re: Change Schema in ZConnection with PostgreSQL

Post by huelbert »

Could you give an example in which property I put "set search_path = MySchema"
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 765
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Change Schema in ZConnection with PostgreSQL

Post by aehimself »

I have 0 experience with PG; however, the above statement looks like an SQL command.

Did you try

Code: Select all

ZConnection1.ExecuteDirect('set search_path = MySchema');
?
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
huelbert
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 28.07.2022, 02:17

Re: Change Schema in ZConnection with PostgreSQL

Post by huelbert »

that's right...thank you
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Change Schema in ZConnection with PostgreSQL

Post by marsupilami »

The schema search path is what kept me from implementing anything because I was not sure how to handle things correctly. Anyway - currently I see two ways to improve the situation:
  • We just overwrite the schema using something like "SET search_path TO <catalogname as specified in TZConnection>". This way we would effectivly disable the public schema and the users schema, if it exists.
  • We do a "show search_path" and the execute something like "SET search_path T0 <catalogname as specified in TZConnection>,<original search_path>"
Opinions?
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 765
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Change Schema in ZConnection with PostgreSQL

Post by aehimself »

I support the second option, especially since MSSQL does this the same way (sending the USE command after login).
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
Post Reply