Page 1 of 1

SQLConnection.GetColumnNames doesn't consider selected schema

Posted: 30.01.2023, 14:10
by aehimself
Hello,

I realized that by simply calling SQLConnection.GetColumnNames('MYTABLE', 'MYCOLUMN', sl) returns multiple results from different schemas. If I use the other overload and specify SQLConnection.Catalog as the first parameter (schema pattern) only one row is returned as expected, as I have a schema set on the connection.

The reason is, the first variant simply calls the other overload without a schema name. Therefore, ZDbcOracleMetadata : 1916 (TZOracleDatabaseMetadata.UncachedGetColumns) returns an empty string for OwnerCondition and therefore no filtering will be done.

There was a similar fix of mine a while ago (Merged revision(s) 7301 from trunk: By AEHimself: ZStoredProc "Cannot retrieve resultset" with multiple schemas / catalogs fix), so my question is, is this intentional, or metadata should consider the schema set on it's connection?
If it should, should I correct it on the level of TZAbstractConnection, or in TZOracleDatabaseMetadata (as there is a huge chaos in usage of terms "catalog" and "schema" across different RDBMS systems).

Re: SQLConnection.GetColumnNames doesn't consider selected schema

Posted: 30.01.2023, 20:24
by marsupilami
*Sigh* - I dislike the way, Zeos mixes the usage of Catalog, Schema and Database. Zeos doesn't use these terms consistently.

From my POV the DBC layer does it more or less right. An Example from PostgreSQL:
* Catalog = Database
* Schema = Schema in the database - public for example, or dbo on Microsoft SQL Server

In TZConnection we do it wrong There we do:
* Database = Catalog on the DBC layer
* Catalog = Schema on the DBC layer.

I think we should change that in an upcoming version of Zeos...

Anyway - TZAbstractConnection.GetColumnNames(const TablePattern, ColumnPattern: string; List: TStrings) should use the Catalog setting from the TZConnection object. I don't know why it was introduced with spaces at all.

Opinions?

Re: SQLConnection.GetColumnNames doesn't consider selected schema

Posted: 30.01.2023, 20:58
by aehimself
As for the terminology and it's modification in an upcoming release - no idea.

As for the fixing, I support it. Just say the magic word and a pull request will be on it's way.

Re: SQLConnection.GetColumnNames doesn't consider selected schema

Posted: 31.01.2023, 08:49
by marsupilami
Any pull request will be greatly apreciated :)

Re: SQLConnection.GetColumnNames doesn't consider selected schema

Posted: 31.01.2023, 09:10
by aehimself
#75 fresh and ripe, ready for merging :)

Re: SQLConnection.GetColumnNames doesn't consider selected schema

Posted: 01.02.2023, 10:35
by marsupilami
I applied the patch and synced it to Github. Thank you :)