Postgres pg_CS

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Postgres pg_CS

Post by sandeep_c24 »

Hi

I need to use CS_Table array in ZDbcPostgreSqlUtils. It is not exposed would it be alright if I put it before Implementation?

Regards

Sandeep
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Can you explain why you need it directly? It looks as if you better us pg_CS_code or write the inverse pg_CS_code function, unless you need to loop the list, of course.

Mark
Image
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

I need to show those options in a combobox. I have a app where the user can select the Encoding for a database.

Sandeep
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

So you actually need a new Metadata function... GetSupportedCharactersets (or something like that).
I don't know for PG, but for mysql this is a server dependent list...
Ideally you would add this metadata function, returning a TStringlist like GetTables. Default = empty list. Then depending on the server you could add code to fill the list. If the list is fixed for all PG versions/servers you could add a function to ZDbcPostgreSqlUtils.pas to read the array. Otherwise the list should be filled by the server (query?) or at least version dependent in ZDbcPostgreSqlMetadata.pas

Is this feaseable? In case you can do it, this patch can be added to SVN as it's all new and independent from all other code. (Which is different from your other changes that aren't merged yet)

Mark
Image
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

Ok I'll have a look at and see if there is something in database that I can use to get Encoding. If there is something I'll add a function, as you suggested to metadata units.

Sandeep
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

I had a quick look on the web and I can't seem to find a way to get the encodings supported by Postgres.

Does anyone know how to get this?

Sandeep
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

I had a look at the pgAdmin source code and this is what they do

Code: Select all

        long encNo=0;
        wxString encStr;
        do
        {
            encStr=connection->ExecuteScalar(
                wxT("SELECT pg_encoding_to_char(") + NumToStr(encNo) + wxT(")"));
            if (!encStr.IsEmpty())
                cbEncoding->Append(encStr);

            encNo++;
        }
        while (!encStr.IsEmpty());
Should I add something similar to Postgres Metadata unit? If yes, should I add this method just for Postgres or to TZAbstractDatabaseMetadata class?

Sandeep
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Please add it to the IZDatabaseMetadata interface. I know a least mysql and firebird could also implement it.

Mark
Image
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

Is it ok to add a function like this

Code: Select all

    function GetSupportedCharactersets : TStringDynArray;
I don't want to return TStringList as the list will be created in this function and the user could forget to free it or if they use this function with try..finally and someone later changes something in the function which raises an exception before TStringList is created an exception will be raised when try..finally free executes.

Sandeep
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Actually, similar functions return a IZResultSet at dbc level. At component level this is converted into a TStringList. I would follow this logic whenever possible...

Concerning the case when a user forgets to Free -> that's up to the user and the existing methods (like GetTableNames) already work the same way.

Mark
Image
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

I will use following definition then

Code: Select all

function GetSupportedCharactersets : IZResultSet;
Sandeep
Post Reply