Page 1 of 1

[patch_done] PgSQL - Possible metadata mistaken information

Posted: 08.07.2009, 21:41
by shmarchiori
I'm using PostgreSQL 8.3 since this version has been released, always with Zeos Query, ROQuery etc.. But I'm new on ZMetadata component.
In past I get metadata from PostgreSQL using direct queries, which precess was not so easy to do. My reference was always this wiki http://pt.wikibooks.org/wiki/PostgreSQL ... /Metadados (don't know about english version).
However, inspecting metadata result, I've noticed missing and incorrect information about numeric type. Numeric type in Pg is defined by precision and scale ( see http://www.postgresql.org/docs/8.3/inte ... IC-DECIMAL).
Since data returning by metadata seems to be wrong, I turn back to those old SQL scripts and changed Zeos code a little, for testing, so:

unit ZDbcPostgreSqlMetadata.pas

else if (PgType = 'numeric') or (PgType = 'decimal') then
begin
{
//Old code here
AttTypMod := GetInt(8) - 4;
Result.UpdateInt(7, (AttTypMod shr 16) and $FFFF);
Result.UpdateInt(9, AttTypMod and $FFFF);
Result.UpdateInt(10, 10);
}
AttTypMod := GetIntByName('atttypmod') - 4;
Result.UpdateInt(7, (AttTypMod div 65536)); //precision
Result.UpdateInt(9, (AttTypMod mod 65536)); //scale
Result.UpdateInt(10, 10); //base?

Here's my point: those changes solved my problem, and inspecting the whole system, seems to work fine. But, are those changes accurate?

Posted: 08.07.2009, 23:20
by mdaems
Hi, I suppse you're more a postgres expert than I am. So I suppose your changes are accuate.

However, concerning performance I would like to see you using GetInt instead of GetIntByName. (ByName involves an extra array search). Can you cange yur patch and test it for your test case? Afterwards I'll feed the change to the test suite to see if that keeps running.

Mark

Posted: 09.07.2009, 13:34
by shmarchiori
Since there was many places in this procedure where Get<field>ByName was used, and SQL for 7.4 and above PostgreSQL versions return absolutelly the same columns, there were no excuses for using "ByName" statements. So I made a little more improvements on code, removing all "ByName"s.
It would be desirable to remove every "ByName" statement in this unit. Maybe I got time to do it next week :)

(Changes Attached)

Posted: 09.07.2009, 21:11
by mdaems
shmarchiori,

Thanks for the patch!

Do you care doing your changes against svn testing branch (or trunk or a snapshot)? Because I want to do patches as much as possible in testing branch and trunk first before backporting them to 6.6-patches. And the dbc metadata units have changed quite a lot between 6.6 and 7.x so it's difficult to compare changed 6.6 version to 7.x versions using winmerge.

SVN. Rev 673.

Mark

Posted: 09.07.2009, 21:51
by shmarchiori
I'm afraid I've never done this before. Would you have any link with instructions of how to do it?
It's always a pleaseure to help this community.

Posted: 09.07.2009, 23:05
by mdaems
shmarchiori,

You'll have to decide if you want to have a second, experimental version of zeoslib (7.X) hanging around on your computer. With the possible risk of using the wrong version for your real projects.

If no : Just do as you did today : change your 6.6 copy and send me the new version. I'll compare and dat the right changes in testing branch. This is more work for me. But reasonable for small patches.

If yes : download the most recent testing or trunk version from http://zeosdownloads.firmos.at/downloads/snapshots/ or use svn to checkout a working copy from the repository directly. See here for more information ("Downloading" paragraph). There's also a link to a very small manual about svn usage.
After downloading you can do the changes to the 7.x version, and test them. Then you can send me the changed file again that can easily merge, test and commit. Or when you're using svn, you can send an svn diff(patch) file. That's even easier.

Mark

Posted: 10.07.2009, 12:15
by shmarchiori
Mark, I really cannot do this right now. This little patch comes to solve a problem I'm having on a real project, that must be done within a couple weeks.
However, not right now, but soon, I'll contributing really more with Zeos.
For now, I'm sending changes to you.

Best regards, Sergio.