Page 1 of 1

Postgres pg_CS

Posted: 16.04.2008, 10:12
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

Posted: 16.04.2008, 14:06
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

Posted: 16.04.2008, 23:47
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

Posted: 17.04.2008, 10:21
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

Posted: 17.04.2008, 10:38
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

Posted: 17.04.2008, 11:22
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

Posted: 18.04.2008, 09:27
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

Posted: 24.04.2008, 20:41
by mdaems
Please add it to the IZDatabaseMetadata interface. I know a least mysql and firebird could also implement it.

Mark

Posted: 24.04.2008, 22:28
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

Posted: 24.04.2008, 23:44
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

Posted: 24.04.2008, 23:53
by sandeep_c24
I will use following definition then

Code: Select all

function GetSupportedCharactersets : IZResultSet;
Sandeep