MSSQL Cross-database query problem (Mantis issue id 0000154)
Posted: 13.11.2014, 09:52
Hi.
Recently I've begun to port some old, but very large desktop application from Borland C++ Builder to Lazarus. I've found the Zeoslib only component library suitable for replacing proprietary SQLDirect. I've ported the code to Delphi (with fantastic Perl script), then made it work, then moved to Lazarus. Everything went ok until I stucked at cross-table query. Doesn't matter if it's using FreeTDS or MS SQL ntwdblib, the cross-table query simply does not work.
I needed this feature badly, so I've managed to fix the Zeos source code by changing the file "ZDbcDbLibMetadata.pas".
I've replaced this:
with this:
and this:
with this:
Sorry for posting this patch here, but I could not register into Mantis. I've tested this patch with and without cross-database queries and it works fine. I think that you should include my modification in upcoming releases, because I think it fixes a major issue.
I've tested the code od Server 2012 Express and all the following queries run fine:
Cheers!
Recently I've begun to port some old, but very large desktop application from Borland C++ Builder to Lazarus. I've found the Zeoslib only component library suitable for replacing proprietary SQLDirect. I've ported the code to Delphi (with fantastic Perl script), then made it work, then moved to Lazarus. Everything went ok until I stucked at cross-table query. Doesn't matter if it's using FreeTDS or MS SQL ntwdblib, the cross-table query simply does not work.
I needed this feature badly, so I've managed to fix the Zeos source code by changing the file "ZDbcDbLibMetadata.pas".
I've replaced this:
Code: Select all
with GetStatement.ExecuteQuery(
Format('exec sp_columns %s, %s, %s, %s',
[ComposeObjectString(TableNamePattern),
ComposeObjectString(SchemaPattern),
ComposeObjectString(Catalog),
ComposeObjectString(ColumnNamePattern)])) do
Code: Select all
with GetStatement.ExecuteQuery(
Format('exec %s.%s.sp_columns %s, %s, %s, %s',
[Catalog,
SchemaPattern,
ComposeObjectString(TableNamePattern),
ComposeObjectString(SchemaPattern),
ComposeObjectString(Catalog),
ComposeObjectString(ColumnNamePattern)])) do
Code: Select all
with GetStatement.ExecuteQuery(
Format('exec sp_column_privileges %s, %s, %s, %s',
[ComposeObjectString(Table),
ComposeObjectString(Schema),
ComposeObjectString(Catalog),
ComposeObjectString(ColumnNamePattern)])) do
Code: Select all
with GetStatement.ExecuteQuery(
Format('exec %s.%s.sp_column_privileges %s, %s, %s, %s',
[Catalog,
Schema,
ComposeObjectString(Table),
ComposeObjectString(Schema),
ComposeObjectString(Catalog),
ComposeObjectString(ColumnNamePattern)])) do
I've tested the code od Server 2012 Express and all the following queries run fine:
Code: Select all
exec ..sp_columns ...
exec .dbo.sp_columns ...
exec database.dbo.sp_columns ...