00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { SQL Metadata Dataset component }
00005 { }
00006 { Originally written by Sergey Seroukhov }
00007 { }
00008 {*********************************************************}
00009
00010 {@********************************************************}
00011 { Copyright (c) 1999-2006 Zeos Development Group }
00012 { }
00013 { License Agreement: }
00014 { }
00015 { This library is distributed in the hope that it will be }
00016 { useful, but WITHOUT ANY WARRANTY; without even the }
00017 { implied warranty of MERCHANTABILITY or FITNESS FOR }
00018 { A PARTICULAR PURPOSE. See the GNU Lesser General }
00019 { Public License for more details. }
00020 { }
00021 { The source code of the ZEOS Libraries and packages are }
00022 { distributed under the Library GNU General Public }
00023 { License (see the file COPYING / COPYING.ZEOS) }
00024 { with the following modification: }
00025 { As a special exception, the copyright holders of this }
00026 { library give you permission to link this library with }
00027 { independent modules to produce an executable, }
00028 { regardless of the license terms of these independent }
00029 { modules, and to copy and distribute the resulting }
00030 { executable under terms of your choice, provided that }
00031 { you also meet, for each linked independent module, }
00032 { the terms and conditions of the license of that module. }
00033 { An independent module is a module which is not derived }
00034 { from or based on this library. If you modify this }
00035 { library, you may extend this exception to your version }
00036 { of the library, but you are not obligated to do so. }
00037 { If you do not wish to do so, delete this exception }
00038 { statement from your version. }
00039 { }
00040 { }
00041 { The project web site is located on: }
00042 { http:
00043 { http:
00044 { svn:
00045 { }
00046 { http:
00047 { http:
00048 { }
00049 { }
00050 { }
00051 { Zeos Development Group. }
00052 {********************************************************@}
00053
00054 unit ZSqlMetadata;
00055
00056 interface
00057
00058 {$I ZComponent.inc}
00059
00060 uses
00061 SysUtils, DB, Classes, ZDbcIntfs, ZAbstractRODataset;
00062
00063 type
00064
00065 {** Defines an enumiration for SQL metadata resultsets. }
00066 TZMetadataType = (mdProcedures, mdProcedureColumns, mdTables, mdSchemas,
00067 mdCatalogs, mdTableTypes, mdColumns, mdColumnPrivileges, mdTablePrivileges,
00068 mdBestRowIdentifier, mdVersionColumns, mdPrimaryKeys, mdImportedKeys,
00069 mdExportedKeys, mdCrossReference, mdTypeInfo, mdIndexInfo, mdSequences,
00070 mdUserDefinedTypes);
00071
00072 {**
00073 Abstract dataset component which works with one specified table.
00074 }
00075 TZSQLMetadata = class(TZAbstractRODataset)
00076 private
00077 FMetadataType: TZMetadataType;
00078 FCatalog: string;
00079 FSchema: string;
00080 FTableName: string;
00081 FColumnName: string;
00082 FProcedureName: string;
00083 FScope: Integer;
00084 FNullable: Boolean;
00085 FForeignCatalog: string;
00086 FForeignSchema: string;
00087 FForeignTableName: string;
00088 FUnique: Boolean;
00089 FApproximate: Boolean;
00090 FTypeName: string;
00091 FSequenceName: string;
00092
00093 procedure SetMetadataType(Value: TZMetadataType);
00094 protected
00095 function CreateResultSet(const SQL: string; MaxRows: Integer): IZResultSet;
00096 override;
00097 procedure CheckSQLQuery; override;
00098 published
00099 property MetadataType: TZMetadataType read FMetadataType write SetMetadataType;
00100 property Catalog: string read FCatalog write FCatalog;
00101 property Schema: string read FSchema write FSchema;
00102 property TableName: string read FTableName write FTableName;
00103 property ColumnName: string read FColumnName write FColumnName;
00104 property ProcedureName: string read FProcedureName write FProcedureName;
00105 property Scope: Integer read FScope write FScope default 0;
00106 property Nullable: Boolean read FNullable write FNullable default False;
00107 property ForeignCatalog: string read FForeignCatalog write FForeignCatalog;
00108 property ForeignSchema: string read FForeignSchema write FForeignSchema;
00109 property ForeignTableName: string read FForeignTableName write FForeignTableName;
00110 property Unique: Boolean read FUnique write FUnique default False;
00111 property Approximate: Boolean read FApproximate write FApproximate default False;
00112 property TypeName: string read FTypeName write FTypeName;
00113 property SequenceName: string read FSequenceName write FSequenceName;
00114
00115 property Active;
00116 property MasterFields;
00117 property MasterSource;
00118 property LinkedFields; {renamed by bangfauzan}
00119 end;
00120
00121 implementation
00122
00123 { TZSQLMetadata }
00124
00125 {**
00126 Sets a new SQL metadata type.
00127 @param Value a new SQL metadata type.
00128 }
00129 procedure TZSQLMetadata.SetMetadataType(Value: TZMetadataType);
00130 begin
00131 if FMetadataType <> Value then
00132 begin
00133 Active := False;
00134 FMetadataType := Value;
00135 end;
00136 end;
00137
00138 {**
00139 Creates a DBC resultset for the query.
00140 @param SQL an SQL query.
00141 @param MaxRows a maximum rows number (-1 for all).
00142 @returns a created DBC resultset.
00143 }
00144 function TZSQLMetadata.CreateResultSet(const SQL: string; MaxRows: Integer):
00145 IZResultSet;
00146 var
00147 Metadata: IZDatabaseMetadata;
00148 begin
00149 Connection.ShowSQLHourGlass;
00150 try
00151 Metadata := Connection.DbcConnection.GetMetadata;
00152
00153 case FMetadataType of
00154 mdProcedures:
00155 Result := Metadata.GetProcedures(FCatalog, FSchema, FProcedureName);
00156 mdProcedureColumns:
00157 Result := Metadata.GetProcedureColumns(FCatalog, FSchema,
00158 FProcedureName, FColumnName);
00159 mdTables:
00160 Result := Metadata.GetTables(FCatalog, FSchema, FTableName, nil);
00161 mdSchemas:
00162 Result := Metadata.GetSchemas;
00163 mdCatalogs:
00164 Result := Metadata.GetCatalogs;
00165 mdTableTypes:
00166 Result := Metadata.GetTableTypes;
00167 mdColumns:
00168 Result := Metadata.GetColumns(FCatalog, FSchema, FTableName,
00169 FColumnName);
00170 mdColumnPrivileges:
00171 Result := Metadata.GetColumnPrivileges(FCatalog, FSchema, FTableName,
00172 FColumnName);
00173 mdTablePrivileges:
00174 Result := Metadata.GetTablePrivileges(FCatalog, FSchema, FTableName);
00175 mdBestRowIdentifier:
00176 Result := Metadata.GetBestRowIdentifier(FCatalog, FSchema, FTableName,
00177 FScope, FNullable);
00178 mdVersionColumns:
00179 Result := Metadata.GetVersionColumns(FCatalog, FSchema, FTableName);
00180 mdPrimaryKeys:
00181 Result := Metadata.GetPrimaryKeys(FCatalog, FSchema, FTableName);
00182 mdImportedKeys:
00183 Result := Metadata.GetImportedKeys(FCatalog, FSchema, FTableName);
00184 mdExportedKeys:
00185 Result := Metadata.GetExportedKeys(FCatalog, FSchema, FTableName);
00186 mdCrossReference:
00187 Result := Metadata.GetCrossReference(FCatalog, FSchema, FTableName,
00188 FForeignCatalog, FForeignSchema, FForeignTableName);
00189 mdTypeInfo:
00190 Result := Metadata.GetTypeInfo;
00191 mdIndexInfo:
00192 Result := Metadata.GetIndexInfo(FCatalog, FSchema, FTableName, FUnique,
00193 FApproximate);
00194 mdSequences:
00195 Result := Metadata.GetSequences(FCatalog, FSchema, FSequenceName);
00196 mdUserDefinedTypes:
00197 Result := Metadata.GetUDTs(FCatalog, FSchema, FTypeName, nil);
00198 end;
00199 finally
00200 Connection.HideSQLHourGlass;
00201 end;
00202 end;
00203
00204 {**
00205 Checks the SQL query. The query has no meaning for this class.
00206 }
00207 procedure TZSQLMetadata.CheckSQLQuery;
00208 begin
00209
00210 end;
00211
00212 end.