Change Schema in ZConnection with PostgreSQL
Change Schema in ZConnection with PostgreSQL
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
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
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Re: Change Schema in ZConnection with PostgreSQL
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
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
Re: Change Schema in ZConnection with PostgreSQL
Good Morning
I did a test putting a ZConnection and coded the properties as the code:
It only connects to the public schema.
I am sending the example in the attachment.
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;
I am sending the example in the attachment.
You do not have the required permissions to view the files attached to this post.
Re: Change Schema in ZConnection with PostgreSQL
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
set search_path = MySchema
after login.
-Mark
Re: Change Schema in ZConnection with PostgreSQL
Could you give an example in which property I put "set search_path = MySchema"
Re: Change Schema in ZConnection with PostgreSQL
I have 0 experience with PG; however, the above statement looks like an SQL command.
Did you try
?
Did you try
Code: Select all
ZConnection1.ExecuteDirect('set search_path = MySchema');
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Re: Change Schema in ZConnection with PostgreSQL
that's right...thank you
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Re: Change Schema in ZConnection with PostgreSQL
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>"
Re: Change Schema in ZConnection with PostgreSQL
I support the second option, especially since MSSQL does this the same way (sending the USE command after login).
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47