[bug_fixed] Bug in ZDbcPostgreSqlMetadata.pas(6.6 beta)

In this forum all bug reports concerning the 6.x branch will be gahtered. You have the possibility to track the bug fix process.

Moderators: EgonHugeist, mdaems

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

[bug_fixed] Bug in ZDbcPostgreSqlMetadata.pas(6.6 beta)

Post by sandeep_c24 »

Hi

TZSQLMetadata is not returning the list of tables for PostgreSQL. The problem is in the following method. Here is my fix for this. I have tested it and it is working ok for me.

[syntax="delphi"]function TZPostgreSQLDatabaseMetadata.GetTables(const Catalog: string;
const SchemaPattern: string; const TableNamePattern: string;
const Types: TStringDynArray): IZResultSet;
var
I: Integer;
Key: string;
TableType, OrderBy, SQL: string;
UseSchemas: Boolean;
LTypes: TStringDynArray;
begin
Key := GetTablesMetaDataCacheKey(Catalog,SchemaPattern,TableNamePattern,Types);
Result := GetResultSetFromCache(Key);
if Result = nil then
begin
UseSchemas := True;

if HaveMinimumServerVersion(7, 3) then
begin
SQL := ' SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM,'
+ ' c.relname AS TABLE_NAME, '
+ ' CASE (n.nspname LIKE ''pg\\_%'')'
+ ' OR (n.nspname=''information_schema'')'
+ ' WHEN true THEN CASE n.nspname '
+ ' WHEN ''pg_catalog'' THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''SYSTEM TABLE'''
+ ' WHEN ''v'' THEN ''SYSTEM VIEW'' '
+ ' WHEN ''i'' THEN ''SYSTEM INDEX'' '
+ ' ELSE NULL '
+ ' END '
+ ' WHEN ''information_schema'' THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''SYSTEM TABLE'''
+ ' WHEN ''v'' THEN ''SYSTEM VIEW'' '
+ ' WHEN ''i'' THEN ''SYSTEM INDEX'' '
+ ' ELSE NULL '
+ ' END '
+ ' WHEN ''pg_toast'' THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''SYSTEM TOAST TABLE'' '
+ ' WHEN ''i'' THEN ''SYSTEM TOAST INDEX'' '
+ ' ELSE NULL '
+ ' END '
+ ' ELSE CASE c.relkind '
+ ' WHEN ''r'' THEN ''TEMPORARY TABLE'' '
+ ' WHEN ''i'' THEN ''TEMPORARY INDEX'' '
+ ' ELSE NULL '
+ ' END '
+ ' END '
+ ' WHEN false THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''TABLE'' '
+ ' WHEN ''i'' THEN ''INDEX'' '
+ ' WHEN ''S'' THEN ''SEQUENCE'' '
+ ' WHEN ''v'' THEN ''VIEW'' '
+ ' ELSE NULL '
+ ' END '
+ ' ELSE NULL '
+ ' END '
+ ' AS TABLE_TYPE, d.description AS REMARKS '
+ ' FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c '
+ ' LEFT JOIN pg_catalog.pg_description d'
+ ' ON (c.oid = d.objoid AND d.objsubid = 0) '
+ ' LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid'
+ ' AND dc.relname=''pg_class'') LEFT JOIN pg_catalog.pg_namespace dn'
+ ' ON (dn.oid=dc.relnamespace AND dn.nspname=''pg_catalog'') '
+ ' WHERE c.relnamespace = n.oid ';
if SchemaPattern <> '' then // cannot happen due to SchemaPattern := '%'
begin
SQL := SQL + ' AND n.nspname LIKE '''
+ EscapeQuotes(ToLikeString(SchemaPattern)) + ''' ';
end;
OrderBy := ' ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME ';
end
else
begin
UseSchemas := False;
TableType := ' CASE c.relname LIKE ''pg\\_%'' '
+ 'WHEN true THEN CASE c.relname LIKE ''pg\\_toast\\_%'' '
+ 'WHEN true THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''SYSTEM TOAST TABLE'' '
+ ' WHEN ''i'' THEN ''SYSTEM TOAST INDEX'' '
+ ' ELSE NULL '
+ 'END '
+ 'WHEN false THEN CASE c.relname LIKE ''pg\\_temp\\_%'' '
+ ' WHEN true THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''TEMPORARY TABLE'' '
+ ' WHEN ''i'' THEN ''TEMPORARY INDEX'' '
+ ' ELSE NULL '
+ ' END '
+ ' WHEN false THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''SYSTEM TABLE'' '
+ ' WHEN ''v'' THEN ''SYSTEM VIEW'' '
+ ' WHEN ''i'' THEN ''SYSTEM INDEX'' '
+ ' ELSE NULL '
+ ' END '
+ ' ELSE NULL '
+ 'END '
+ 'ELSE NULL '
+ 'END '
+ 'WHEN false THEN CASE c.relkind '
+ ' WHEN ''r'' THEN ''TABLE'' '
+ ' WHEN ''i'' THEN ''INDEX'' '
+ ' WHEN ''S'' THEN ''SEQUENCE'' '
+ ' WHEN ''v'' THEN ''VIEW'' '
+ ' ELSE NULL '
+ 'END '
+ 'ELSE NULL '
+ ' END ';
OrderBy := ' ORDER BY TABLE_TYPE,TABLE_NAME ';
SQL := 'SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM,'
+ ' c.relname AS TABLE_NAME, ' + TableType + ' AS TABLE_TYPE,'
+ ' NULL AS REMARKS FROM pg_class c WHERE true ';
end;

if (Types = nil) or (High(Types) = 0) then
begin
SetLength(LTypes, 5);
LTypes[0] := 'TABLE';
LTypes[1] := 'VIEW';
LTypes[2] := 'INDEX';
LTypes[3] := 'SEQUENCE';
LTypes[4] := 'TEMPORARY TABLE';
end
else
LTypes := Types;

SQL := SQL + ' AND c.relname LIKE ''' + EscapeQuotes(ToLikeString(TableNamePattern))
+ ''' ';
//SC 21/10/2006
if (Length(Types) > 0) then
SQL := SQL + 'AND (false ';
//SC 21/10/2006
for I := 0 to High(Types) do
SQL := SQL + ' OR ( ' + TableTypeSQLExpression(LTypes, UseSchemas) + ' ) ';
//SC 21/10/2006
if (Length(Types) > 0) then
SQL := SQL + ' )';
//SC 21/10/2006

SQL := SQL + OrderBy;

Result := CopyToVirtualResultSet(
GetConnection.CreateStatement.ExecuteQuery(SQL),
ConstructVirtualResultSet(TableColumnsDynArray));
AddResultSetToCache(Key, Result);
end;
end;[/syntax]


Regards

Sandeep

[edit]Sourcecode formatted to make it readable ;-)[/edit]
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

Thanks for formatting the code. If the changes done pass the unit tests then could they be merged?

Regards

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

Post by sandeep_c24 »

Has anyone checked the above fix?

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 »

Hi Sandeep,

I hoped the editor of your post would have done this, but apparently not. I just added your 4 lines of code to the SVN Testing branch. (Rev 162)

Please check and confirm. So I can close this topic.
In about a week your change will be merged to Trunk and it will be included in next release build.

Mark
damien666
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 21.09.2005, 09:10

Post by damien666 »

hi , i using Rev 182

there is a bug here

Code: Select all

  if (Length(LTypes) > 0) then
      SQL := SQL + 'AND (false ';
    for I := 0 to High(Types) do
      SQL := SQL + ' OR ( ' + TableTypeSQLExpression(LTypes[i], UseSchemas) + ' ) ';
    SQL := SQL + ' )' + OrderBy;
    if (Length(LTypes) > 0) then
      SQL := SQL + ' )';
the fix from sandeep_c24 doesn't work for me
the real problem is
delphi:

Code: Select all

 for I := 0 to High(Types) do // must be LTypes
the working code

delphi:

Code: Select all

function TZPostgreSQLDatabaseMetadata.GetTables(const Catalog: string;
  const SchemaPattern: string; const TableNamePattern: string;
  const Types: TStringDynArray): IZResultSet;
var
  I: Integer;
  Key: string;
  TableType, OrderBy, SQL: string;
  UseSchemas: Boolean;
  LTypes: TStringDynArray;
begin
  Key := GetTablesMetaDataCacheKey(Catalog,SchemaPattern,TableNamePattern,Types);
  Result := GetResultSetFromCache(Key);
  if Result = nil then
  begin
    UseSchemas := True;

    if HaveMinimumServerVersion(7, 3) then
    begin
      SQL := ' SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM,'
        + ' c.relname AS TABLE_NAME,  '
        + ' CASE (n.nspname LIKE ''pg\\_%'')'
        + '   OR (n.nspname=''information_schema'')'
        + ' WHEN true THEN CASE n.nspname '
        + '   WHEN ''pg_catalog'' THEN CASE c.relkind '
        + '     WHEN ''r'' THEN ''SYSTEM TABLE'''
        + '     WHEN ''v'' THEN ''SYSTEM VIEW'' '
        + '     WHEN ''i'' THEN ''SYSTEM INDEX'' '
        + '     ELSE NULL '
        + '   END '
        + '   WHEN ''information_schema'' THEN CASE c.relkind '
        + '     WHEN ''r'' THEN ''SYSTEM TABLE'''
        + '     WHEN ''v'' THEN ''SYSTEM VIEW'' '
        + '     WHEN ''i'' THEN ''SYSTEM INDEX'' '
        + '     ELSE NULL '
        + '   END '
        + '   WHEN ''pg_toast'' THEN CASE c.relkind '
        + '     WHEN ''r'' THEN ''SYSTEM TOAST TABLE'' '
        + '     WHEN ''i'' THEN ''SYSTEM TOAST INDEX'' '
        + '     ELSE NULL '
        + '   END '
        + '   ELSE CASE c.relkind '
        + '	WHEN ''r'' THEN ''TEMPORARY TABLE'' '
        + '	WHEN ''i'' THEN ''TEMPORARY INDEX'' '
        + '	ELSE NULL '
        + '   END '
        + ' END '
        + ' WHEN false THEN CASE c.relkind '
        + '   WHEN ''r'' THEN ''TABLE'' '
        + '   WHEN ''i'' THEN ''INDEX'' '
        + '   WHEN ''S'' THEN ''SEQUENCE'' '
        + '   WHEN ''v'' THEN ''VIEW'' '
        + '   ELSE NULL '
        + ' END '
        + ' ELSE NULL '
        + ' END '
        + ' AS TABLE_TYPE, d.description AS REMARKS '
        + ' FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c '
        + ' LEFT JOIN pg_catalog.pg_description d'
        + ' ON (c.oid = d.objoid AND d.objsubid = 0) '
        + ' LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid'
        + ' AND dc.relname=''pg_class'') LEFT JOIN pg_catalog.pg_namespace dn'
        + ' ON (dn.oid=dc.relnamespace AND dn.nspname=''pg_catalog'') '
        + ' WHERE c.relnamespace = n.oid ';
     // if SchemaPattern <> '' then // cannot happen due to SchemaPattern := '%'
      begin
        SQL := SQL + ' AND n.nspname LIKE '''
          + EscapeQuotes(ToLikeString(SchemaPattern)) + ''' ';
      end;
      OrderBy := ' ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME ';
    end
    else
    begin
      UseSchemas := False;
      TableType := ' CASE c.relname LIKE ''pg\\_%'' '
        + 'WHEN true THEN CASE c.relname LIKE ''pg\\_toast\\_%'' '
        + 'WHEN true THEN CASE c.relkind '
        + '  WHEN ''r'' THEN ''SYSTEM TOAST TABLE'' '
        + '  WHEN ''i'' THEN ''SYSTEM TOAST INDEX'' '
        + '  ELSE NULL '
        + 'END '
        + 'WHEN false THEN CASE c.relname LIKE ''pg\\_temp\\_%'' '
        + '  WHEN true THEN CASE c.relkind '
        + '    WHEN ''r'' THEN ''TEMPORARY TABLE'' '
        + '    WHEN ''i'' THEN ''TEMPORARY INDEX'' '
        + '    ELSE NULL '
        + '  END '
        + '  WHEN false THEN CASE c.relkind '
        + '    WHEN ''r'' THEN ''SYSTEM TABLE'' '
        + '    WHEN ''v'' THEN ''SYSTEM VIEW'' '
        + '    WHEN ''i'' THEN ''SYSTEM INDEX'' '
        + '    ELSE NULL '
        + '  END '
        + '  ELSE NULL '
        + 'END '
        + 'ELSE NULL '
        + 'END '
        + 'WHEN false THEN CASE c.relkind '
        + '  WHEN ''r'' THEN ''TABLE'' '
        + '  WHEN ''i'' THEN ''INDEX'' '
        + '  WHEN ''S'' THEN ''SEQUENCE'' '
        + '  WHEN ''v'' THEN ''VIEW'' '
        + '  ELSE NULL '
        + 'END '
        + 'ELSE NULL '
        + ' END ';
      OrderBy := ' ORDER BY TABLE_TYPE,TABLE_NAME ';
      SQL := 'SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM,'
        + ' c.relname AS TABLE_NAME, ' + TableType + ' AS TABLE_TYPE,'
        + ' NULL AS REMARKS FROM pg_class c WHERE true ';
    end;

    if (Types = nil) or (High(Types) = 0) then
    begin
      SetLength(LTypes, 5);
      LTypes[0] := 'TABLE';
      LTypes[1] := 'VIEW';
      LTypes[2] := 'INDEX';
      LTypes[3] := 'SEQUENCE';
      LTypes[4] := 'TEMPORARY TABLE';
    end
    else
      LTypes := Types;

    SQL := SQL + ' AND c.relname LIKE ''' + EscapeQuotes(ToLikeString(TableNamePattern))
      + ''' AND (false ';
   // if (Length(LTypes) > 0) then
   //   SQL := SQL + 'AND (false ';
    for I := 0 to High(LTypes) do
      SQL := SQL + ' OR ( ' + TableTypeSQLExpression(LTypes[i], UseSchemas) + ' ) ';
    SQL := SQL + ' )' + OrderBy;
   // if (Length(LTypes) > 0) then
   //   SQL := SQL + ' )';
      
    Result := CopyToVirtualResultSet(
      GetConnection.CreateStatement.ExecuteQuery(SQL),
      ConstructVirtualResultSet(TableColumnsDynArray));
    AddResultSetToCache(Key, Result);
  end;
end;
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Merci Damien,

This fix looks logical. I've commited it to SVN (Testing Rev 188).

@Sandeep : can you please check this solution? I want this reportto be closed.

Code: Select all

    SQL := SQL + ' AND c.relname LIKE ''' + EscapeQuotes(ToLikeString(TableNamePattern))
      + ''' AND (false ';
    for I := 0 to High(LTypes) do
      SQL := SQL + ' OR ( ' + TableTypeSQLExpression(LTypes[i], UseSchemas) + ' ) ';
    SQL := SQL + ' )' + OrderBy;
Mark
damien666
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 21.09.2005, 09:10

Post by damien666 »

i check the fix with SVN (Testing Rev 188)

it's ok !
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

Hi Mdaems

I had a look at the fix provided by Merci Damien. I agree with Damien that LTypes should have been used and I think it's ok to use LTypes there.

The only thing wrong in following code...

Code: Select all

SQL := SQL + ' AND c.relname LIKE ''' + EscapeQuotes(ToLikeString(TableNamePattern))
      + ''' AND (false ';
    for I := 0 to High(LTypes) do
      SQL := SQL + ' OR ( ' + TableTypeSQLExpression(LTypes[i], UseSchemas) + ' ) ';
    SQL := SQL + ' )' + OrderBy; 
...is the use of 'AND (false '. If Length of LTypes is 0 then the sql statement ends up looking like

Code: Select all

select [something] from [table] where [condition] AND (false)
which doesn't fetch anything.


The proper fix I think would be as follows

Code: Select all

SQL := SQL + ' AND c.relname LIKE ''' + EscapeQuotes(ToLikeString(TableNamePattern))
      + ''' ';
    //SC  21/10/2006
    if (Length(LTypes) > 0) then
      SQL := SQL + 'AND (false ';
    //SC  21/10/2006
    for I := 0 to High(LTypes) do
      SQL := SQL + ' OR ( ' + TableTypeSQLExpression(LTypes[i], UseSchemas) + ' ) ';
    //SC  21/10/2006
    if (Length(LTypes) > 0) then
      SQL := SQL + ' )';
    //SC  21/10/2006

    SQL := SQL + OrderBy;
Regards

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

Post by sandeep_c24 »

Here is the complete method as I have it right now

Code: Select all

function TZPostgreSQLDatabaseMetadata.GetTables(const Catalog: string;
  const SchemaPattern: string; const TableNamePattern: string;
  const Types: TStringDynArray): IZResultSet;
var
  I: Integer;
  Key: string;
  TableType, OrderBy, SQL: string;
  UseSchemas: Boolean;
  LTypes: TStringDynArray;
begin
  Key := GetTablesMetaDataCacheKey(Catalog,SchemaPattern,TableNamePattern,Types);
  Result := GetResultSetFromCache(Key);
  if Result = nil then
  begin
    UseSchemas := True;

    if HaveMinimumServerVersion(7, 3) then
    begin
      SQL := ' SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM,'
        + ' c.relname AS TABLE_NAME,  '
        + ' CASE (n.nspname LIKE ''pg\\_%'')'
        + '   OR (n.nspname=''information_schema'')'
        + ' WHEN true THEN CASE n.nspname '
        + '   WHEN ''pg_catalog'' THEN CASE c.relkind '
        + '     WHEN ''r'' THEN ''SYSTEM TABLE'''
        + '     WHEN ''v'' THEN ''SYSTEM VIEW'' '
        + '     WHEN ''i'' THEN ''SYSTEM INDEX'' '
        + '     ELSE NULL '
        + '   END '
        + '   WHEN ''information_schema'' THEN CASE c.relkind '
        + '     WHEN ''r'' THEN ''SYSTEM TABLE'''
        + '     WHEN ''v'' THEN ''SYSTEM VIEW'' '
        + '     WHEN ''i'' THEN ''SYSTEM INDEX'' '
        + '     ELSE NULL '
        + '   END '
        + '   WHEN ''pg_toast'' THEN CASE c.relkind '
        + '     WHEN ''r'' THEN ''SYSTEM TOAST TABLE'' '
        + '     WHEN ''i'' THEN ''SYSTEM TOAST INDEX'' '
        + '     ELSE NULL '
        + '   END '
        + '   ELSE CASE c.relkind '
        + '	WHEN ''r'' THEN ''TEMPORARY TABLE'' '
        + '	WHEN ''i'' THEN ''TEMPORARY INDEX'' '
        + '	ELSE NULL '
        + '   END '
        + ' END '
        + ' WHEN false THEN CASE c.relkind '
        + '   WHEN ''r'' THEN ''TABLE'' '
        + '   WHEN ''i'' THEN ''INDEX'' '
        + '   WHEN ''S'' THEN ''SEQUENCE'' '
        + '   WHEN ''v'' THEN ''VIEW'' '
        + '   ELSE NULL '
        + ' END '
        + ' ELSE NULL '
        + ' END '
        + ' AS TABLE_TYPE, d.description AS REMARKS '
        + ' FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c '
        + ' LEFT JOIN pg_catalog.pg_description d'
        + ' ON (c.oid = d.objoid AND d.objsubid = 0) '
        + ' LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid'
        + ' AND dc.relname=''pg_class'') LEFT JOIN pg_catalog.pg_namespace dn'
        + ' ON (dn.oid=dc.relnamespace AND dn.nspname=''pg_catalog'') '
        + ' WHERE c.relnamespace = n.oid ';
      //if SchemaPattern <> '' then // cannot happen due to SchemaPattern := '%'
      begin
        SQL := SQL + ' AND n.nspname LIKE '''
          + EscapeQuotes(ToLikeString(SchemaPattern)) + ''' ';
      end;
      OrderBy := ' ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME ';
    end
    else
    begin
      UseSchemas := False;
      TableType := ' CASE c.relname LIKE ''pg\\_%'' '
        + 'WHEN true THEN CASE c.relname LIKE ''pg\\_toast\\_%'' '
        + 'WHEN true THEN CASE c.relkind '
        + '  WHEN ''r'' THEN ''SYSTEM TOAST TABLE'' '
        + '  WHEN ''i'' THEN ''SYSTEM TOAST INDEX'' '
        + '  ELSE NULL '
        + 'END '
        + 'WHEN false THEN CASE c.relname LIKE ''pg\\_temp\\_%'' '
        + '  WHEN true THEN CASE c.relkind '
        + '    WHEN ''r'' THEN ''TEMPORARY TABLE'' '
        + '    WHEN ''i'' THEN ''TEMPORARY INDEX'' '
        + '    ELSE NULL '
        + '  END '
        + '  WHEN false THEN CASE c.relkind '
        + '    WHEN ''r'' THEN ''SYSTEM TABLE'' '
        + '    WHEN ''v'' THEN ''SYSTEM VIEW'' '
        + '    WHEN ''i'' THEN ''SYSTEM INDEX'' '
        + '    ELSE NULL '
        + '  END '
        + '  ELSE NULL '
        + 'END '
        + 'ELSE NULL '
        + 'END '
        + 'WHEN false THEN CASE c.relkind '
        + '  WHEN ''r'' THEN ''TABLE'' '
        + '  WHEN ''i'' THEN ''INDEX'' '
        + '  WHEN ''S'' THEN ''SEQUENCE'' '
        + '  WHEN ''v'' THEN ''VIEW'' '
        + '  ELSE NULL '
        + 'END '
        + 'ELSE NULL '
        + ' END ';
      OrderBy := ' ORDER BY TABLE_TYPE,TABLE_NAME ';
      SQL := 'SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM,'
        + ' c.relname AS TABLE_NAME, ' + TableType + ' AS TABLE_TYPE,'
        + ' NULL AS REMARKS FROM pg_class c WHERE true ';
    end;
                               
    if (Types = nil) or (Length(Types) = 0) then //SC  08/12/2006
    begin
      SetLength(LTypes, 5);
      LTypes[0] := 'TABLE';
      LTypes[1] := 'VIEW';
      LTypes[2] := 'INDEX';
      LTypes[3] := 'SEQUENCE';
      LTypes[4] := 'TEMPORARY TABLE';
    end
    else
      LTypes := Types;
      
    SQL := SQL + ' AND c.relname LIKE ''' + EscapeQuotes(ToLikeString(TableNamePattern))
      + ''' ';
    //SC  21/10/2006
    if (Length(LTypes) > 0) then
      SQL := SQL + 'AND (false ';
    //SC  21/10/2006
    for I := 0 to High(LTypes) do
      SQL := SQL + ' OR ( ' + TableTypeSQLExpression(LTypes[i], UseSchemas) + ' ) ';
    //SC  21/10/2006
    if (Length(LTypes) > 0) then
      SQL := SQL + ' )';
    //SC  21/10/2006

    SQL := SQL + OrderBy;

    Result := CopyToVirtualResultSet(
      GetConnection.CreateStatement.ExecuteQuery(SQL),
      ConstructVirtualResultSet(TableColumnsDynArray));
    AddResultSetToCache(Key, Result);
  end;
end;
Please also have a look at line

Code: Select all

if (Types = nil) or (Length(Types) = 0) then 
I think it is better to test for Length rather than High.

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 »

Hi Sandeep,

Did you have situations where Length = 0? That should not be possible as in that case it would be filled with the defaults. Or am I wrong about that?

Did the version I committed work? In that case I'll leave the logic like it is but change the High() to Length().

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

Post by sandeep_c24 »

Hi Mark

I think you are right. There should never be a situation where the Length is 0. I think your changes are ok.

Regards

Sandeep
Post Reply