zeoslib  UNKNOWN
 All Files
ZAbstractTable.pas
Go to the documentation of this file.
1 {*********************************************************}
2 { }
3 { Zeos Database Objects }
4 { Abstract Table component }
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 ZAbstractTable;
53 
54 interface
55 
56 {$I ZComponent.inc}
57 
58 uses
59  SysUtils, Classes, {$IFDEF MSEgui}mclasses,{$ENDIF}
60  ZAbstractDataset;
61 
62 type
63 
64  {**
65  Abstract dataset component which works with one specified table.
66  }
67  TZAbstractTable = class(TZAbstractDataset)
68  private
69  FTableName: string;
70 
71  private
72  function GetExists: Boolean;
73  procedure SetTableName(const Value: string);
74 
75  protected
76  {$IFDEF WITH_IPROVIDER}
77  function PSIsSQLBased: Boolean; override;
78  {$IFDEF WITH_IPROVIDERWIDE}
79  function PSGetTableNameW: WideString; override;
80  {$ELSE}
81  function PSGetTableName: string; override;
82  {$ENDIF}
83  procedure PSSetCommandText(const ACommandText: string); override;
84  {$ENDIF}
85 
86  protected
87  property Exists: Boolean read GetExists;
88  property TableName: string read FTableName write SetTableName;
89  end;
90 
91 implementation
92 
93 
94 { TZAbstractTable }
95 
96 {**
97  Checks if a table with the corresponding name exists in the database.
98  @return <code>True</code> if the the table exists.
99 }
100 function TZAbstractTable.GetExists: Boolean;
101 var
102  TableList: TStringList;
103 begin
104  TableList := TStringList.Create;
105  try
106  CheckConnected;
107  Connection.GetTableNames(TableName, TableList);
108  TableList.CaseSensitive := False;
109  Result := (TableList.IndexOf(TableName) >= 0); // look for an exact match
110  finally
111  TableList.Free;
112  end;
113 end;
114 
115 {**
116  Sets a new table name and generates a related SQL statement.
117  @param Value a new name of table.
118 }
119 procedure TZAbstractTable.SetTableName(const Value: string);
120 begin
121  if FTableName <> Value then
122  begin
123  FTableName := Value;
124  if Value <> '' then
125  SQL.Text := Format('SELECT * FROM %s', [FTableName])
126  else SQL.Text := '';
127  end;
128 end;
129 
130 {$IFDEF WITH_IPROVIDER}
131 
132 {**
133  Checks if dataset can execute SQL queries?
134  @returns <code>True</code> if the query can execute SQL.
135 }
136 function TZAbstractTable.PSIsSQLBased: Boolean;
137 begin
138  Result := False;
139 end;
140 
141 {**
142  Gets the name of the table.
143  @returns the name of this table.
144 }
145 {$IFDEF WITH_IPROVIDERWIDE}
146 function TZAbstractTable.PSGetTableNameW: WideString;
147 {$ELSE}
148 function TZAbstractTable.PSGetTableName: string;
149 {$ENDIF}
150 begin
151  Result := TableName;
152 end;
153 
154 {**
155  Assignes a new name for this table.
156  @param ACommandText a new name for this table.
157 }
158 procedure TZAbstractTable.PSSetCommandText(const ACommandText: string);
159 begin
160  TableName := ACommandText;
161 end;
162 
163 {$ENDIF}
164 
165 end.