1 {*********************************************************}
3 { Zeos Database Objects }
4 { SQL Metadata Dataset component }
6 { Originally written by Sergey Seroukhov }
8 {*********************************************************}
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
13 { License Agreement: }
15 { This library is distributed in the hope that it will be }
16 { useful, but WITHOUT ANY WARRANTY; without even the }
17 { implied warranty of MERCHANTABILITY or FITNESS FOR }
18 { A PARTICULAR PURPOSE. See the GNU Lesser General }
19 { Public License for more details. }
21 { The source code of the ZEOS Libraries and packages are }
22 { distributed under the Library GNU General Public }
23 { License (see the file COPYING / COPYING.ZEOS) }
24 { with the following modification: }
25 { As a special exception, the copyright holders of this }
26 { library give you permission to link this library with }
27 { independent modules to produce an executable, }
28 { regardless of the license terms of these independent }
29 { modules, and to copy and distribute the resulting }
30 { executable under terms of your choice, provided that }
31 { you also meet, for each linked independent module, }
32 { the terms and conditions of the license of that module. }
33 { An independent module is a module which is not derived }
34 { from or based on this library. If you modify this }
35 { library, you may extend this exception to your version }
36 { of the library, but you are not obligated to do so. }
37 { If you do not wish to do so, delete this exception }
38 { statement from your version. }
41 { The project web site is located on: }
42 { http://zeos.firmos.at (FORUM) }
43 { http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
44 { svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
46 { http://www.sourceforge.net/projects/zeoslib. }
49 { Zeos Development Group. }
50 {********************************************************@}
59 SysUtils, Classes, ZDbcIntfs, ZAbstractRODataset;
63 {** Defines an enumiration for SQL metadata resultsets. }
64 TZMetadataType = (mdProcedures, mdProcedureColumns, mdTables, mdSchemas,
65 mdCatalogs, mdTableTypes, mdColumns, mdColumnPrivileges, mdTablePrivileges,
66 mdBestRowIdentifier, mdVersionColumns, mdPrimaryKeys, mdImportedKeys,
67 mdExportedKeys, mdCrossReference, mdTypeInfo, mdTriggers, mdIndexInfo, mdSequences,
71 Abstract dataset component which works with one specified table.
73 TZSQLMetadata = class(TZAbstractRODataset)
75 FMetadataType: TZMetadataType;
81 FProcedureName: string;
84 FForeignCatalog: string;
85 FForeignSchema: string;
86 FForeignTableName: string;
88 FApproximate: Boolean;
90 FSequenceName: string;
92 procedure SetMetadataType(Value: TZMetadataType);
94 function CreateResultSet(const SQL: string; MaxRows: Integer): IZResultSet;
96 procedure CheckSQLQuery; override;
98 property MetadataType: TZMetadataType read FMetadataType write SetMetadataType;
99 property Catalog: string read FCatalog write FCatalog;
100 property Schema: string read FSchema write FSchema;
101 property TableName: string read FTableName write FTableName;
102 property ColumnName: string read FColumnName write FColumnName;
103 property ProcedureName: string read FProcedureName write FProcedureName;
104 property Scope: Integer read FScope write FScope default 0;
105 property Nullable: Boolean read FNullable write FNullable default False;
106 property ForeignCatalog: string read FForeignCatalog write FForeignCatalog;
107 property ForeignSchema: string read FForeignSchema write FForeignSchema;
108 property ForeignTableName: string read FForeignTableName write FForeignTableName;
109 property Unique: Boolean read FUnique write FUnique default False;
110 property Approximate: Boolean read FApproximate write FApproximate default False;
111 property TypeName: string read FTypeName write FTypeName;
112 property SequenceName: string read FSequenceName write FSequenceName;
113 property TriggerName: String read FTriggerName write FTriggerName;
115 property MasterFields;
116 property MasterSource;
117 property LinkedFields; {renamed by bangfauzan}
125 Sets a new SQL metadata type.
126 @param Value a new SQL metadata type.
128 procedure TZSQLMetadata.SetMetadataType(Value: TZMetadataType);
130 if FMetadataType <> Value then
133 FMetadataType := Value;
138 Creates a DBC resultset for the query.
139 @param SQL an SQL query.
140 @param MaxRows a maximum rows number (-1 for all).
141 @returns a created DBC resultset.
146 function TZSQLMetadata.CreateResultSet(const SQL: string; MaxRows: Integer):
149 Metadata: IZDatabaseMetadata;
151 Connection.ShowSQLHourGlass;
153 Metadata := Connection.DbcConnection.GetMetadata;
155 case FMetadataType of
157 Result := Metadata.GetProcedures(FCatalog, FSchema, FProcedureName);
159 Result := Metadata.GetProcedureColumns(FCatalog, FSchema,
160 FProcedureName, FColumnName);
162 Result := Metadata.GetTables(FCatalog, FSchema, FTableName, nil);
164 Result := Metadata.GetSchemas;
166 Result := Metadata.GetCatalogs;
168 Result := Metadata.GetTableTypes;
170 Result := Metadata.GetTriggers(FCatalog, FSchema, FTableName, FTriggerName);
172 Result := Metadata.GetColumns(FCatalog, FSchema, FTableName,
175 Result := Metadata.GetColumnPrivileges(FCatalog, FSchema, FTableName,
178 Result := Metadata.GetTablePrivileges(FCatalog, FSchema, FTableName);
180 Result := Metadata.GetBestRowIdentifier(FCatalog, FSchema, FTableName,
183 Result := Metadata.GetVersionColumns(FCatalog, FSchema, FTableName);
185 Result := Metadata.GetPrimaryKeys(FCatalog, FSchema, FTableName);
187 Result := Metadata.GetImportedKeys(FCatalog, FSchema, FTableName);
189 Result := Metadata.GetExportedKeys(FCatalog, FSchema, FTableName);
191 Result := Metadata.GetCrossReference(FCatalog, FSchema, FTableName,
192 FForeignCatalog, FForeignSchema, FForeignTableName);
194 Result := Metadata.GetTypeInfo;
196 Result := Metadata.GetIndexInfo(FCatalog, FSchema, FTableName, FUnique,
199 Result := Metadata.GetSequences(FCatalog, FSchema, FSequenceName);
201 Result := Metadata.GetUDTs(FCatalog, FSchema, FTypeName, nil);
204 Connection.HideSQLHourGlass;
212 Checks the SQL query. The query has no meaning for this class.
214 procedure TZSQLMetadata.CheckSQLQuery;
216 // Here sql has no meaning. So it should not be tested.