zeoslib  UNKNOWN
 All Files
ZPropertyEditor.pas
Go to the documentation of this file.
1 {*********************************************************}
2 { }
3 { Zeos Database Objects }
4 { Component Property Editors }
5 { }
6 { Originally written by Sergey Seroukhov }
7 { }
8 {*********************************************************}
9 
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
12 { }
13 { License Agreement: }
14 { }
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. }
20 { }
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. }
39 { }
40 { }
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) }
45 { }
46 { http://www.sourceforge.net/projects/zeoslib. }
47 { }
48 { }
49 { Zeos Development Group. }
50 {********************************************************@}
51 
52 unit ZPropertyEditor;
53 
54 interface
55 
56 {$I ZComponent.inc}
57 
58 {$IFDEF WITH_PROPERTY_EDITOR}
59 
60 uses
61  Types, Classes, ZClasses, ZCompatibility, ZDbcIntfs,
62  ZConnectionGroup, ZAbstractConnection, ZURL,
63 {$IFDEF BDS4_UP}
64  WideStrings,
65 {$ENDIF}
66 {$IFNDEF FPC}
67  DesignIntf, DesignEditors;
68 {$ELSE}
69  PropEdits;
70 {$ENDIF}
71 
72 type
73 
74  {** Implements the basic methods of the property editor. }
75  TZStringProperty = class(TStringProperty)
76  public
77  function GetAttributes: TPropertyAttributes; override;
78  procedure GetValueList(List: TStrings); virtual; abstract;
79  procedure GetValues(Proc: TGetStrProc); override;
80  function GetZComponent:TPersistent; virtual;
81  end;
82 
83  {** Shows all Fields received from FieldDefs. }
84  TZDataFieldPropertyEditor = class(TZStringProperty)
85  public
86  procedure GetValueList(List: TStrings); override;
87  end;
88 
89  {** Shows all Fields received from IndexDefs - not used yet. }
90  TZIndexFieldPropertyEditor = class(TZStringProperty)
91  public
92  procedure GetValueList(List: TStrings); override;
93  end;
94 
95  {** Shows all Fields received from the MasterSource's DataSet.FieldDefs. }
96  TZMasterFieldPropertyEditor = class(TZStringProperty)
97  public
98  procedure GetValueList(List: TStrings); override;
99  end;
100 
101  {** Shows all Tables received from Connection.IZDatabaseMetadata. }
102  TZTableNamePropertyEditor = class(TZStringProperty)
103  public
104  procedure GetValueList(List: TStrings); override;
105  end;
106 
107  {** Shows all Procedures received from Connection.IZDatabaseMetadata. }
108  TZProcedureNamePropertyEditor = class(TZStringProperty)
109  public
110  procedure GetValueList(List: TStrings); override;
111  end;
112 
113  {** Shows all Sequences received from Connection.IZDatabaseMetadata. }
114  TZSequenceNamePropertyEditor = class(TZStringProperty)
115  public
116  procedure GetValueList(List: TStrings); override;
117  end;
118 
119  {** Implements a property editor for ZConnection.Protocol property. }
120  TZProtocolPropertyEditor = class(TZStringProperty)
121  public
122  function GetValue: string; override;
123  procedure GetValueList(List: TStrings); override;
124  procedure SetValue(const Value: string); override;
125  end;
126 
127  {** Implements a property editor for ZConnection.ClientCodePage property. }
128  TZClientCodePagePropertyEditor = class(TZStringProperty)
129  public
130  function GetValue: string; override;
131  procedure GetValueList(List: TStrings); override;
132  procedure SetValue(const Value: string); override;
133  end;
134 
135  {** Implements a property editor for ZConnection.Database property. }
136  TZDatabasePropertyEditor = class(TZStringProperty)
137  public
138  function GetAttributes: TPropertyAttributes; override;
139  function GetValue: string; override;
140  procedure Edit; override;
141  procedure GetValueList(List: TStrings); override;
142  procedure SetValue(const Value: string); override;
143  end;
144 
145  {** Implements a property editor for ZConnection.LibLocation property. }
146  TZLibLocationPropertyEditor = class(TZStringProperty)
147  public
148  function GetAttributes: TPropertyAttributes; override;
149  function GetValue: string; override;
150  procedure Edit; override;
151  procedure SetValue(const Value: string); override;
152  end;
153 
154  // Modified by Una.Bicicleta 2010/10/31
155  {** Implements a property editor for ZConnectionGroup.Database property. }
156  TZConnectionGroupPropertyEditor = class(TZStringProperty)
157  public
158  function GetAttributes: TPropertyAttributes; override;
159  function GetValue: string; override;
160  procedure Edit; override;
161  procedure GetValueList(List: TStrings); override;
162  procedure SetValue(const Value: string); override;
163  end;
164 
165  {** Implements a property editor for ZGroupedConnection.Catalog property. }
166  TZGroupedConnectionCatalogPropertyEditor = class(TZStringProperty)
167  public
168  function GetValue: string; override;
169  procedure GetValueList(List: TStrings); override;
170  procedure SetValue(const Value: string); override;
171  end;
172 
173  {** Implements a property editor for ZGroupedConnection.LibLocation property. }
174  {** added 2013/02/20 }
175  TZConnectionGroupLibLocationPropertyEditor = class(TZStringProperty)
176  public
177  function GetAttributes: TPropertyAttributes; override;
178  function GetValue: string; override;
179  procedure Edit; override;
180  procedure SetValue(const Value: string); override;
181  end;
182  /////////////////////////////////////////////////////////
183 
184 
185  {** Implements a property editor for ZConnection.Catalog property. }
186  TZCatalogPropertyEditor = class(TZStringProperty)
187  public
188  function GetValue: string; override;
189  procedure GetValueList(List: TStrings); override;
190  procedure SetValue(const Value: string); override;
191  end;
192 
193 {$IFDEF USE_METADATA}
194  {** Shows all Catalogs received from Connection.IZDatabaseMetadata. }
195  TZCatalogProperty = class(TZStringProperty)
196  public
197  procedure GetValueList(List: TStrings); override;
198  end;
199 
200  {** Shows all Columns received from Connection.IZDatabaseMetadata. }
201  TZColumnNamePropertyEditor = class(TZStringProperty)
202  public
203  procedure GetValueList(List: TStrings); override;
204  end;
205 
206  {** Shows all Schemes received from Connection.IZDatabaseMetadata. }
207  TZSchemaPropertyEditor = class(TZStringProperty)
208  public
209  procedure GetValueList(List: TStrings); override;
210  end;
211 
212  {** Shows all Types received from Connection.IZDatabaseMetadata. }
213  TZTypeNamePropertyEditor = class(TZStringProperty)
214  public
215  procedure GetValueList(List: TStrings); override;
216  end;
217 {$ENDIF}
218 
219 const
220  CRLF = LineEnding;
221 
222 {$ENDIF}
223 
224 implementation
225 
226 {$IFDEF WITH_PROPERTY_EDITOR}
227 
228 uses SysUtils, Forms, Dialogs, Controls, DB, TypInfo, ZSysUtils, ZSelectSchema
229 {$IFDEF USE_METADATA}
230  , ZSqlMetadata
231 {$ENDIF}
232 {$IFNDEF UNIX}
233  {$IFNDEF FPC}
234  {$IFDEF ENABLE_ADO}
235 , ZDbcAdoUtils
236  {$ENDIF}
237  {$ENDIF}
238 {$ENDIF}
239 {$IFDEF SHOW_WARNING}
240 ,ZMessages
241 {$ENDIF SHOW_WARNING}
242 ;
243 
244 {$IFDEF FPC}
245 procedure GetItemNames(FieldDefs: TFieldDefs; List: TStrings); overload;
246 var
247  i: Integer;
248 begin
249  List.Clear;
250  for i := 0 to Pred(FieldDefs.Count) do
251  List.Append(FieldDefs[i].Name);
252 end;
253 
254 procedure GetItemNames(IndexDefs: TIndexDefs; List: TStrings); overload;
255 var
256  i: Integer;
257 begin
258  List.Clear;
259  for i := 0 to Pred(IndexDefs.Count) do
260  List.Append(IndexDefs[i].Name);
261 end;
262 {$ENDIF}
263 
264 { Returns the IndexDefs from Dataset }
265 function GetIndexDefs(Component: TPersistent): TIndexDefs;
266 var
267  DataSet: TDataSet;
268 begin
269  DataSet := Component as TDataSet;
270  Result := GetObjectProp(DataSet, 'IndexDefs') as TIndexDefs;
271  if Assigned(Result) then
272  begin
273  Result.Updated := False;
274  Result.Update;
275  end;
276 end;
277 
278 function IsEmpty(const s: string): Boolean;
279 begin
280  Result := Trim(s) = '';
281 end;
282 
283 { TZStringProperty }
284 
285 {**
286  Gets a type of property attributes.
287  @return a type of property attributes.
288 }
289 function TZStringProperty.GetAttributes: TPropertyAttributes;
290 begin
291  Result := [paValueList, paSortList];
292 end;
293 
294 {**
295  Processes a list of list items.
296  @param Proc a procedure to process the list items.
297 }
298 procedure TZStringProperty.GetValues(Proc: TGetStrProc);
299 var
300  i: Integer;
301  Values: TStringList;
302 begin
303  Values := TStringList.Create;
304  try
305  GetValueList(Values);
306  for i := 0 to Pred(Values.Count) do
307  Proc(Values[i]);
308  finally
309  Values.Free;
310  end;
311 end;
312 
313 {**
314  Gets the component that has the property.
315 }
316 function TZStringProperty.GetZComponent:TPersistent;
317 begin
318  Result:=GetComponent(0);
319 end;
320 
321 { TZDataFieldPropertyEditor }
322 
323 {**
324  Processes a list of list items.
325  @param List the list to process the list items.
326 }
327 procedure TZDataFieldPropertyEditor.GetValueList(List: TStrings);
328 begin
329  try
330  with (GetZComponent as TDataSet) do
331  begin
332  // Update the FieldDefs and return the Fieldnames
333  FieldDefs.Updated := False;
334  FieldDefs.Update;
335  {$IFNDEF FPC}
336  FieldDefs.GetItemNames(List);
337  {$ELSE}
338  GetItemNames(FieldDefs, List);
339  {$ENDIF}
340  end;
341  except
342  end;
343 end;
344 
345 { TZIndexFieldPropertyEditor }
346 
347 procedure TZIndexFieldPropertyEditor.GetValueList(List: TStrings);
348 begin
349  {$IFNDEF FPC}
350  GetIndexDefs(GetZComponent).GetItemNames(List);
351  {$ELSE}
352  GetItemNames(GetIndexDefs(GetZComponent), List);
353  {$ENDIF}
354 end;
355 
356 { TZMasterFieldPropertyEditor }
357 
358 procedure TZMasterFieldPropertyEditor.GetValueList(List: TStrings);
359 var
360  DataSource: TDataSource;
361 begin
362  DataSource := GetObjectProp(GetZComponent, 'MasterSource') as TDataSource;
363  if (DataSource <> nil) and (DataSource.DataSet <> nil) then
364  {$IFDEF WITH_WIDESTRINGS_GETFIELDNAMES}
365  DataSource.DataSet.GetFieldNames(TWideStrings(List));
366  {$ELSE}
367  DataSource.DataSet.GetFieldNames(List);
368  {$ENDIF}
369 end;
370 
371 { TZTableNamePropertyEditor }
372 
373 {**
374  Processes a list of list items.
375  @param List the list to process the list items.
376 }
377 procedure TZTableNamePropertyEditor.GetValueList(List: TStrings);
378 var
379  Connection: TZAbstractConnection;
380  Metadata: IZDatabaseMetadata;
381  ResultSet: IZResultSet;
382  Schema, Tablename:String;
383  IdentifierConvertor: IZIdentifierConvertor;
384  Catalog: string;
385 begin
386  Connection := GetObjectProp(GetZComponent, 'Connection') as TZAbstractConnection;
387  if Assigned(Connection) and Connection.Connected then
388  begin
389  Metadata := Connection.DbcConnection.GetMetadata;
390  IdentifierConvertor := Metadata.GetIdentifierConvertor;
391  Catalog := Connection.Catalog;
392  Schema := '';
393 {$IFDEF USE_METADATA}
394  if GetZComponent is TZSqlMetadata then
395  begin
396  Catalog := GetStrProp(GetZComponent, 'Catalog');
397  Schema := GetStrProp(GetZComponent, 'Schema');
398 {$IFDEF SHOW_WARNING}
399  if not (IsEmpty(Catalog) and IsEmpty(Schema)) or
400  (MessageDlg(SPropertyQuery + CRLF + SPropertyTables + CRLF +
401  SPropertyExecute, mtWarning, [mbYes,mbNo], 0) = mrYes) then
402  begin
403  // continue
404  end
405  else
406  exit;
407 {$ENDIF}
408  end;
409 {$ENDIF}
410  begin
411  try
412  // Look for the Tables of the defined Catalog and Schema
413  ResultSet := Metadata.GetTables(Catalog, Schema, '', nil);
414  while ResultSet.Next do
415  begin
416  TableName := ResultSet.GetStringByName('TABLE_NAME');
417  TableName := IdentifierConvertor.Quote(TableName);
418  Schema := ResultSet.GetStringByName('TABLE_SCHEM');
419  (*if Connection.DbcConnection.GetMetadata.GetDatabaseInfo.SupportsCatalogsInTableDefinitions then
420  if Catalog <> '' then
421  if Schema <> '' then
422  TableName := IdentifierConvertor.Quote(Catalog) + IdentifierConvertor.Quote(Schema) + '.' + TableName
423  else
424  TableName := {IdentifierConvertor.Quote(Catalog) + '.' + }TableName
425  else
426  if Schema <> '' then
427  TableName := IdentifierConvertor.Quote(Schema) + '.' + TableName
428  else
429  TableName := TableName
430  else
431  if Schema <> '' then
432  TableName := IdentifierConvertor.Quote(Schema) + '.' + TableName
433  else
434  TableName := TableName;*)
435  if Schema <> '' then
436  TableName := IdentifierConvertor.Quote(Schema) + '.' + TableName;
437  if Catalog <> '' then
438  TableName := IdentifierConvertor.Quote(Catalog) + '.' + TableName;
439  List.Add(TableName);
440  end;
441  finally
442  ResultSet.Close;
443  end;
444  end;
445  end;
446 end;
447 
448 { TZProcedureNamePropertyEditor }
449 
450 {**
451  Processes a list of list items.
452  @param List the list to process the list items.
453 }
454 procedure TZProcedureNamePropertyEditor.GetValueList(List: TStrings);
455 var
456  Connection: TZAbstractConnection;
457  Metadata: IZDatabaseMetadata;
458  IdentifierConvertor: IZIdentifierConvertor;
459  ResultSet: IZResultSet;
460  Catalog, Schema: string;
461  ProcedureName: string;
462 
463  procedure ExtractOverload(OverloadSeparator: String);
464  var
465  I: Integer;
466  SL: TStrings;
467  begin
468  SL := TStringList.Create;
469  PutSplitString(SL, ProcedureName, OverloadSeparator);
470  if SL.Count > 1 then
471  begin
472  SL.Delete(SL.Count -1);
473  ProcedureName := '';
474  for i := 0 to SL.Count -1 do
475  if ProcedureName = '' then
476  ProcedureName := ProcedureName + SL[i]
477  else
478  ProcedureName := ProcedureName +OverloadSeparator+ SL[i]; //don't forget to give the delimiter back too
479  end;
480  end;
481 begin
482  Connection := GetObjectProp(GetZComponent, 'Connection') as TZAbstractConnection;
483  if Assigned(Connection) and Connection.Connected then
484  begin
485  Metadata := Connection.DbcConnection.GetMetadata;
486  IdentifierConvertor := Metadata.GetIdentifierConvertor;
487  Catalog := Connection.Catalog;
488  Schema := '';
489 {$IFDEF USE_METADATA}
490  if GetZComponent is TZSqlMetadata then
491  begin
492  Catalog := GetStrProp(GetZComponent, 'Catalog');
493  Schema := GetStrProp(GetZComponent, 'Schema');
494 {$IFDEF SHOW_WARNING}
495  if not (IsEmpty(Catalog) and IsEmpty(Schema)) or
496  (MessageDlg(SPropertyQuery + CRLF + SPropertyProcedures + CRLF +
497  SPropertyExecute, mtWarning, [mbYes,mbNo], 0) = mrYes) then
498  begin
499  // continue
500  end
501  else
502  exit;
503 {$ENDIF}
504  end;
505 {$ENDIF}
506  begin
507  try
508  Metadata := Connection.DbcConnection.GetMetadata;
509  // Look for the Procedures
510  ResultSet := Metadata.GetProcedures(Catalog, Schema, '');
511  while ResultSet.Next do
512  begin
513  ProcedureName := ResultSet.GetStringByName('PROCEDURE_NAME');
514  if ( not Metadata.GetDatabaseInfo.SupportsOverloadPrefixInStoredProcedureName ) then
515  if not ( StartsWith(ProcedureName, MetaData.GetDatabaseInfo.GetIdentifierQuoteString) or
516  EndsWith(ProcedureName, MetaData.GetDatabaseInfo.GetIdentifierQuoteString) or
517  (Pos('.', ProcedureName) > 0) ) then
518  ProcedureName := IdentifierConvertor.Quote(ProcedureName);
519  Schema := ResultSet.GetStringByName('PROCEDURE_SCHEM');
520  if Metadata.GetDatabaseInfo.SupportsCatalogsInProcedureCalls then
521  if Catalog <> '' then
522  if Schema <> '' then
523  ProcedureName := IdentifierConvertor.Quote(Catalog) +'.'+ IdentifierConvertor.Quote(Schema) + '.' + ProcedureName
524  else
525  ProcedureName := ProcedureName
526  else
527  if Schema <> '' then
528  ProcedureName := IdentifierConvertor.Quote(Schema) + '.' + ProcedureName
529  else
530  ProcedureName := ProcedureName
531  else
532  if Schema <> '' then
533  ProcedureName := IdentifierConvertor.Quote(Schema) + '.' + ProcedureName
534  else
535  ProcedureName := ProcedureName;
536  List.Add(ProcedureName);
537  end;
538  finally
539  ResultSet.Close;
540  end;
541  end;
542  end;
543 end;
544 
545 { TZSequenceNamePropertyEditor }
546 
547 {**
548  Gets a selected string value.
549  @return a selected string value.
550 }
551 procedure TZSequenceNamePropertyEditor.GetValueList(List: TStrings);
552 var
553  Connection: TZAbstractConnection;
554  Metadata: IZDatabaseMetadata;
555  ResultSet: IZResultSet;
556 {$IFDEF USE_METADATA}
557  Catalog, Schema: string;
558 {$ENDIF}
559 begin
560  Connection := GetObjectProp(GetZComponent, 'Connection') as TZAbstractConnection;
561  if Assigned(Connection) and Connection.Connected then
562  begin
563 {$IFDEF USE_METADATA}
564  if GetZComponent is TZSqlMetadata then
565  begin
566  Catalog := GetStrProp(GetZComponent, 'Catalog');
567  Schema := GetStrProp(GetZComponent, 'Schema');
568 {$IFDEF SHOW_WARNING}
569  if not (IsEmpty(Catalog) and IsEmpty(Schema)) or
570  (MessageDlg(SPropertyQuery + CRLF + SPropertySequences + CRLF +
571  SPropertyExecute, mtWarning, [mbYes,mbNo], 0) = mrYes) then
572 {$ENDIF}
573  try
574  Metadata := Connection.DbcConnection.GetMetadata;
575  // Look for the Procedures of the defined Catalog and Schema
576  ResultSet := Metadata.GetSequences(Catalog, Schema, '');
577  while ResultSet.Next do
578  List.Add(ResultSet.GetStringByName('SEQUENCE_NAME'));
579  finally
580  ResultSet.Close;
581  end;
582  end
583  else
584 {$ENDIF}
585  begin
586  try
587  Metadata := Connection.DbcConnection.GetMetadata;
588  // Look for the Procedures
589  ResultSet := Metadata.GetSequences(Connection.Catalog, '', '');
590  while ResultSet.Next do
591  if ResultSet.GetStringByName('SEQUENCE_SCHEM') <> '' then
592  List.Add(ResultSet.GetStringByName('SEQUENCE_SCHEM')+
593  '.'+ResultSet.GetStringByName('SEQUENCE_NAME'))
594  else
595  List.Add(ResultSet.GetStringByName('SEQUENCE_NAME'));
596  finally
597  ResultSet.Close;
598  end;
599  end;
600  end;
601 end;
602 
603 { TZProtocolPropertyEditor }
604 
605 {**
606  Gets a selected string value.
607  @return a selected string value.
608 }
609 function TZProtocolPropertyEditor.GetValue: string;
610 begin
611  Result := GetStrValue;
612 end;
613 
614 {**
615  Sets a new selected string value.
616  @param Value a new selected string value.
617 }
618 procedure TZProtocolPropertyEditor.SetValue(const Value: string);
619 begin
620  SetStrValue(Value);
621  if GetZComponent is TZAbstractConnection then
622  (GetZComponent as TZAbstractConnection).Connected := False;
623 end;
624 
625 {**
626  Processes a list of list items.
627  @param List the list to process the list items.
628 }
629 procedure TZProtocolPropertyEditor.GetValueList(List: TStrings);
630 var
631  I, J: Integer;
632  Drivers: IZCollection;
633  Protocols: TStringDynArray;
634 begin
635  Drivers := DriverManager.GetDrivers;
636  Protocols := nil;
637  for I := 0 to Drivers.Count - 1 do
638  begin
639  Protocols := (Drivers[I] as IZDriver).GetSupportedProtocols;
640  for J := Low(Protocols) to High(Protocols) do
641  List.Append(Protocols[J]);
642  end;
643 end;
644 
645 {TZClientCodePagePropertyEditor -> EgonHugeist 19.01.2012}
646 
647 {**
648  Sets a new selected string value.
649  @param Value a new selected string value.
650 }
651 function TZClientCodePagePropertyEditor.GetValue: string;
652 begin
653  Result := GetStrValue;
654 end;
655 
656 {**
657  Processes a list of list items.
658  @param List the list to process the list items.
659 }
660 procedure TZClientCodePagePropertyEditor.GetValueList(List: TStrings);
661 var
662  Connection: TZAbstractConnection;
663  I: Integer;
664  SDyn: TStringDynArray;
665  Url: TZURL;
666 begin
667 
668  if GetZComponent is TZAbstractConnection then
669  Connection := (GetZComponent as TZAbstractConnection)
670  else
671  Connection := nil;
672 
673  if Assigned(Connection) then
674  begin
675  if Connection.Protocol = '' then
676  List.Append('No Protocol selected!')
677  else
678  begin
679  Url := TZURL.Create;
680  Url.Protocol := Connection.Protocol;
681  SDyn := DriverManager.GetDriver(Url.URL).GetSupportedClientCodePages(Url,
682  {$IFNDEF UNICODE}Connection.AutoEncodeStrings, {$ENDIF}True, Connection.ControlsCodePage);
683  Url.Free;
684  for i := 0 to high(SDyn) do
685  List.Append(SDyn[i]);
686 
687  TStringList(List).Sort;
688  end;
689  end;
690 end;
691 
692 {**
693  Sets a new selected string value.
694  @param Value a new selected string value.
695 }
696 procedure TZClientCodePagePropertyEditor.SetValue(const Value: string);
697 begin
698  SetStrValue(Value);
699  if GetZComponent is TZAbstractConnection then
700  (GetZComponent as TZAbstractConnection).Connected := False;
701 end;
702 
703 
704 { TZDatabasePropertyEditor }
705 
706 {**
707  Gets a type of property attributes.
708  @return a type of property attributes.
709 }
710 function TZDatabasePropertyEditor.GetAttributes: TPropertyAttributes;
711 begin
712  if GetZComponent is TZAbstractConnection then
713  begin
714  if ((GetZComponent as TZAbstractConnection).Protocol = 'mssql') or
715  ((GetZComponent as TZAbstractConnection).Protocol = 'sybase') then
716  Result := inherited GetAttributes
717  else
718  Result := [paDialog];
719  end;
720 end;
721 
722 {**
723  Gets a selected string value.
724  @return a selected string value.
725 }
726 function TZDatabasePropertyEditor.GetValue: string;
727 begin
728  Result := GetStrValue;
729 end;
730 
731 {**
732  Sets a new selected string value.
733  @param Value a new selected string value.
734 }
735 procedure TZDatabasePropertyEditor.SetValue(const Value: string);
736 begin
737  SetStrValue(Value);
738  if GetZComponent is TZAbstractConnection then
739  (GetZComponent as TZAbstractConnection).Connected := False;
740 end;
741 
742 {**
743  Processes a list of list items.
744  @param List the list to process the list items.
745 }
746 procedure TZDatabasePropertyEditor.GetValueList(List: TStrings);
747 var
748  DbcConnection: IZConnection;
749  Url: string;
750 begin
751  if GetZComponent is TZAbstractConnection then
752  try
753  URL := (GetZComponent as TZAbstractConnection).GetURL;
754  (GetZComponent as TZAbstractConnection).ShowSqlHourGlass;
755  try
756  DbcConnection := DriverManager.GetConnectionWithParams(Url,
757  (GetZComponent as TZAbstractConnection).Properties);
758 
759  with DbcConnection.GetMetadata.GetCatalogs do
760  try
761  while Next do
762  List.Append(GetStringByName('TABLE_CAT'));
763  finally
764  Close;
765  end;
766 
767  finally
768  (GetZComponent as TZAbstractConnection).HideSqlHourGlass;
769  end;
770  except
771 // raise;
772  end;
773 end;
774 
775 {**
776  Brings up the proper database property editor dialog.
777 }
778 procedure TZDatabasePropertyEditor.Edit;
779 var
780  OD: TOpenDialog;
781 begin
782  if GetZComponent is TZAbstractConnection then
783  begin
784  if ((GetZComponent as TZAbstractConnection).Protocol = 'mssql') or
785  ((GetZComponent as TZAbstractConnection).Protocol = 'sybase') then
786  inherited
787 {$IFNDEF UNIX}
788 {$IFNDEF FPC}
789 {$IFDEF ENABLE_ADO}
790  else
791  if ((GetZComponent as TZAbstractConnection).Protocol = 'ado') then
792  (GetZComponent as TZAbstractConnection).Database := PromptDataSource(Application.Handle,
793  (GetZComponent as TZAbstractConnection).Database)
794 {$ENDIF}
795 {$ENDIF}
796 {$ENDIF}
797  else
798  begin
799  OD := TOpenDialog.Create(nil);
800  try
801  OD.InitialDir := ExtractFilePath((GetZComponent as TZAbstractConnection).Database);
802  if OD.Execute then
803  (GetZComponent as TZAbstractConnection).Database := OD.FileName;
804  finally
805  OD.Free;
806  end;
807  end;
808  end
809  else
810  inherited;
811 end;
812 
813 { TZLibLocationPropertyEditor }
814 
815 {**
816  Gets a type of property attributes.
817  @return a type of property attributes.
818 }
819 function TZLibLocationPropertyEditor.GetAttributes: TPropertyAttributes;
820 begin
821  if GetZComponent is TZAbstractConnection then
822  Result := [paDialog];
823 end;
824 
825 {**
826  Gets a selected string value.
827  @return a selected string value.
828 }
829 function TZLibLocationPropertyEditor.GetValue: string;
830 begin
831  Result := GetStrValue;
832 end;
833 
834 {**
835  Sets a new selected string value.
836  @param Value a new selected string value.
837 }
838 procedure TZLibLocationPropertyEditor.SetValue(const Value: string);
839 begin
840  SetStrValue(Value);
841  if GetZComponent is TZAbstractConnection then
842  (GetZComponent as TZAbstractConnection).Connected := False;
843 end;
844 
845 {**
846  Brings up the proper LibLocation property editor dialog.
847 }
848 procedure TZLibLocationPropertyEditor.Edit;
849 var
850  OD: TOpenDialog;
851 begin
852  if GetZComponent is TZAbstractConnection then
853  begin
854  OD := TOpenDialog.Create(nil);
855  try
856  OD.InitialDir := ExtractFilePath((GetZComponent as TZAbstractConnection).LibLocation);
857  if OD.Execute then
858  (GetZComponent as TZAbstractConnection).LibLocation := OD.FileName;
859  finally
860  OD.Free;
861  end;
862  end
863  else
864  inherited;
865 end;
866 
867 { TZCatalogPropertyEditor }
868 
869 {**
870  Gets a selected string value.
871  @return a selected string value.
872 }
873 function TZCatalogPropertyEditor.GetValue: string;
874 begin
875  Result := GetStrValue;
876 end;
877 
878 {**
879  Sets a new selected string value.
880  @param Value a new selected string value.
881 }
882 procedure TZCatalogPropertyEditor.SetValue(const Value: string);
883 begin
884  SetStrValue(Value);
885 end;
886 
887 {**
888  Processes a list of list items.
889  @param List the list to process the list items.
890 }
891 procedure TZCatalogPropertyEditor.GetValueList(List: TStrings);
892 var
893  DbcConnection: IZConnection;
894  Url: string;
895 begin
896  if GetZComponent is TZAbstractConnection then
897  try
898  URL := (GetZComponent as TZAbstractConnection).GetURL;
899  (GetZComponent as TZAbstractConnection).ShowSqlHourGlass;
900  try
901  DbcConnection := DriverManager.GetConnectionWithParams(Url,
902  (GetZComponent as TZAbstractConnection).Properties);
903 
904  if Assigned(DbcConnection) then
905  if DbcConnection.GetMetadata.GetDatabaseInfo.SupportsCatalogsInDataManipulation then
906  with DbcConnection.GetMetadata.GetCatalogs do
907  try
908  while Next do
909  List.Append(GetStringByName('TABLE_CAT'));
910  finally
911  Close;
912  end
913  else if DbcConnection.GetMetadata.GetDatabaseInfo.SupportsSchemasInDataManipulation then
914  with DbcConnection.GetMetadata.GetSchemas do
915  try
916  while Next do
917  List.Append(GetStringByName('TABLE_SCHEM'));
918  finally
919  Close;
920  end;
921  finally
922  (GetZComponent as TZAbstractConnection).HideSqlHourGlass;
923  end;
924  except
925 // raise;
926  end;
927 end;
928 
929 {$IFDEF USE_METADATA}
930 
931 { TZCatalogProperty }
932 
933 {**
934  Processes a list of list items.
935  @param List the list to process the list items.
936 }
937 procedure TZCatalogProperty.GetValueList(List: TStrings);
938 var
939  Connection: TZAbstractConnection;
940  Metadata: IZDatabaseMetadata;
941  ResultSet: IZResultSet;
942 begin
943  Connection := GetObjectProp(GetZComponent, 'Connection') as TZAbstractConnection;
944  if Assigned(Connection) and Connection.Connected then
945  try
946  Metadata := Connection.DbcConnection.GetMetadata;
947  ResultSet := Metadata.GetCatalogs;
948  while ResultSet.Next do
949  List.Add(ResultSet.GetStringByName('TABLE_CAT'));
950  finally
951  ResultSet.Close;
952  end;
953 end;
954 
955 { TZColumnNamePropertyEditor }
956 
957 {**
958  Processes a list of list items.
959  @param List the list to process the list items.
960 }
961 procedure TZColumnNamePropertyEditor.GetValueList(List: TStrings);
962 var
963  Connection: TZAbstractConnection;
964  Metadata: IZDatabaseMetadata;
965  ResultSet: IZResultSet;
966  Catalog, Schema, TableName: string;
967 begin
968  Connection := GetObjectProp(GetZComponent, 'Connection') as TZAbstractConnection;
969  if Assigned(Connection) and Connection.Connected then
970  begin
971  Catalog := GetStrProp(GetZComponent, 'Catalog');
972  Schema := GetStrProp(GetZComponent, 'Schema');
973  TableName := GetStrProp(GetZComponent, 'TableName');
974 {$IFDEF SHOW_WARNING}
975  if not IsEmpty(TableName) or not (IsEmpty(Schema) and IsEmpty(Schema)) or
976  (MessageDlg(SPropertyQuery + CRLF + SPropertyTables + CRLF +
977  SPropertyExecute, mtWarning, [mbYes,mbNo], 0) = mrYes) then
978 {$ENDIF}
979  try
980  Metadata := Connection.DbcConnection.GetMetadata;
981  // Look for the Columns of the defined Catalog, Schema and TableName
982  ResultSet := Metadata.GetColumns(Catalog, Schema, TableName, '');
983  while ResultSet.Next do
984  if List.IndexOf(ResultSet.GetStringByName('COLUMN_NAME')) = -1 then
985  List.Add(ResultSet.GetStringByName('COLUMN_NAME'));
986  finally
987  ResultSet.Close;
988  end;
989  end;
990 end;
991 
992 { TZSchemaPropertyEditor }
993 
994 {**
995  Processes a list of list items.
996  @param List the list to process the list items.
997 }
998 procedure TZSchemaPropertyEditor.GetValueList(List: TStrings);
999 var
1000  Connection: TZAbstractConnection;
1001  Metadata: IZDatabaseMetadata;
1002  ResultSet: IZResultSet;
1003 begin
1004  Connection := GetObjectProp(GetZComponent, 'Connection') as TZAbstractConnection;
1005  if Assigned(Connection) and Connection.Connected then
1006  try
1007  Metadata := Connection.DbcConnection.GetMetadata;
1008  ResultSet := Metadata.GetSchemas;
1009  while ResultSet.Next do
1010  List.Add(ResultSet.GetStringByName('TABLE_SCHEM'));
1011  finally
1012  ResultSet.Close;
1013  end;
1014 end;
1015 
1016 { TZTypeNamePropertyEditor }
1017 
1018 {**
1019  Processes a list of list items.
1020  @param List the list to process the list items.
1021 }
1022 procedure TZTypeNamePropertyEditor.GetValueList(List: TStrings);
1023 var
1024  Connection: TZAbstractConnection;
1025  Metadata: IZDatabaseMetadata;
1026  ResultSet: IZResultSet;
1027 begin
1028  Connection := GetObjectProp(GetZComponent, 'Connection') as TZAbstractConnection;
1029  if Assigned(Connection) and Connection.Connected then
1030  try
1031  Metadata := Connection.DbcConnection.GetMetadata;
1032  ResultSet := Metadata.GetTypeInfo;
1033  while ResultSet.Next do
1034  List.Add(ResultSet.GetStringByName('TYPE_NAME'));
1035  finally
1036  ResultSet.Close;
1037  end;
1038 end;
1039 
1040 
1041 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1042 
1043 { TZConnectionGroupCatalogPropertyEditor }
1044 
1045 
1046 function TZGroupedConnectionCatalogPropertyEditor.GetValue: string;
1047 begin
1048  Result := GetStrValue;
1049 end;
1050 
1051 procedure TZGroupedConnectionCatalogPropertyEditor.SetValue(const Value: string);
1052 begin
1053  SetStrValue(Value);
1054 end;
1055 
1056 procedure TZGroupedConnectionCatalogPropertyEditor.GetValueList(List: TStrings);
1057 var
1058  DbcConnection: IZConnection;
1059  Url: string;
1060 begin
1061  if GetZComponent is TZAbstractConnection then
1062  try
1063  URL := (GetZComponent as TZAbstractConnection).GetURL;
1064  (GetZComponent as TZAbstractConnection).ShowSqlHourGlass;
1065  try
1066  DbcConnection := DriverManager.GetConnectionWithParams(Url,
1067  (GetZComponent as TZAbstractConnection).Properties);
1068 
1069  with DbcConnection.GetMetadata.GetCatalogs do
1070  try
1071  while Next do
1072  List.Append(GetStringByName('TABLE_CAT'));
1073  finally
1074  Close;
1075  end;
1076 
1077  finally
1078  (GetZComponent as TZAbstractConnection).HideSqlHourGlass;
1079  end;
1080  except
1081 // raise;
1082  end;
1083 end;
1084 
1085 
1086 
1087 
1088 { TZConnectionGroupPropertyEditor }
1089 
1090 {**
1091  Gets a type of property attributes.
1092  @return a type of property attributes.
1093 }
1094 function TZConnectionGroupPropertyEditor.GetAttributes: TPropertyAttributes;
1095 begin
1096  if GetZComponent is TZConnectionGroup then
1097  begin
1098  if ((GetZComponent as TZConnectionGroup).Protocol = 'mssql') or
1099  ((GetZComponent as TZConnectionGroup).Protocol = 'sybase') then
1100  Result := inherited GetAttributes
1101  else
1102  Result := [paDialog];
1103  end;
1104 end;
1105 
1106 {**
1107  Gets a selected string value.
1108  @return a selected string value.
1109 }
1110 function TZConnectionGroupPropertyEditor.GetValue: string;
1111 begin
1112  Result := GetStrValue;
1113 end;
1114 
1115 {**
1116  Sets a new selected string value.
1117  @param Value a new selected string value.
1118 }
1119 procedure TZConnectionGroupPropertyEditor.SetValue(const Value: string);
1120 begin
1121  SetStrValue(Value);
1122 // if GetZComponent is TZConnectionGroup then
1123 // (GetZComponent as TZConnectionGroup).Connected := False;
1124 end;
1125 
1126 {**
1127  Processes a list of list items.
1128  @param List the list to process the list items.
1129 }
1130 procedure TZConnectionGroupPropertyEditor.GetValueList(List: TStrings);
1131 var
1132  DbcConnection: IZConnection;
1133 begin
1134  if GetZComponent is TZConnectionGroup then
1135  try
1136  DbcConnection := (GetZComponent as TZAbstractConnection).DbcConnection;
1137  with DbcConnection.GetMetadata.GetCatalogs do
1138  try
1139  while Next do
1140  List.Append(GetStringByName('TABLE_CAT'));
1141  finally
1142  Close;
1143  end;
1144  except
1145 // raise;
1146  end;
1147 end;
1148 
1149 {**
1150  Brings up the proper database property editor dialog.
1151 }
1152 procedure TZConnectionGroupPropertyEditor.Edit;
1153 var
1154  OD: TOpenDialog;
1155 begin
1156  if GetZComponent is TZConnectionGroup then
1157  begin
1158  if ((GetZComponent as TZConnectionGroup).Protocol = 'mssql') or
1159  ((GetZComponent as TZConnectionGroup).Protocol = 'sybase') then
1160  inherited
1161 {$IFNDEF UNIX}
1162 {$IFNDEF FPC}
1163 {$IFDEF ENABLE_ADO}
1164  else
1165  if ((GetZComponent as TZConnectionGroup).Protocol = 'ado') then
1166  (GetZComponent as TZConnectionGroup).Database := PromptDataSource(Application.Handle,
1167  (GetZComponent as TZConnectionGroup).Database)
1168 {$ENDIF}
1169 {$ENDIF}
1170 {$ENDIF}
1171  else
1172  begin
1173  OD := TOpenDialog.Create(nil);
1174  try
1175  OD.InitialDir := ExtractFilePath((GetZComponent as TZConnectionGroup).Database);
1176  if OD.Execute then
1177  (GetZComponent as TZConnectionGroup).Database := OD.FileName;
1178  finally
1179  OD.Free;
1180  end;
1181  end;
1182  end
1183  else
1184  inherited;
1185 end;
1186 
1187 {** added 2013/02/20 }
1188 { TZConnectionGroupLibLocationPropertyEditor }
1189 
1190 {**
1191  Gets a type of property attributes.
1192  @return a type of property attributes.
1193 }
1194 function TZConnectionGroupLibLocationPropertyEditor.GetAttributes: TPropertyAttributes;
1195 begin
1196  if GetZComponent is TZConnectionGroup then
1197  Result := [paDialog];
1198 end;
1199 
1200 {**
1201  Gets a selected string value.
1202  @return a selected string value.
1203 }
1204 function TZConnectionGroupLibLocationPropertyEditor.GetValue: string;
1205 begin
1206  Result := GetStrValue;
1207 end;
1208 
1209 {**
1210  Sets a new selected string value.
1211  @param Value a new selected string value.
1212 }
1213 procedure TZConnectionGroupLibLocationPropertyEditor.SetValue(const Value: string);
1214 begin
1215  SetStrValue(Value);
1216  //if GetZComponent is TZAbstractConnection then
1217  // (GetZComponent as TZAbstractConnection).Connected := False;
1218 end;
1219 
1220 {**
1221  Brings up the proper LibLocation property editor dialog.
1222 }
1223 procedure TZConnectionGroupLibLocationPropertyEditor.Edit;
1224 var
1225  OD: TOpenDialog;
1226 begin
1227  if GetZComponent is TZConnectionGroup then
1228  begin
1229  OD := TOpenDialog.Create(nil);
1230  try
1231  OD.InitialDir := ExtractFilePath((GetZComponent as TZConnectionGroup).LibraryLocation);
1232  if OD.Execute then
1233  (GetZComponent as TZConnectionGroup).LibraryLocation := OD.FileName;
1234  finally
1235  OD.Free;
1236  end;
1237  end
1238  else
1239  inherited;
1240 end;
1241 
1242 {$ENDIF}
1243 
1244 {$ENDIF}
1245 
1246 end.
1247 
1248