00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Abstract Table 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 ZAbstractTable;
00055
00056 interface
00057
00058 {$I ZComponent.inc}
00059
00060 uses
00061 SysUtils, DB, Classes, ZAbstractDataset;
00062
00063 type
00064
00065 {**
00066 Abstract dataset component which works with one specified table.
00067 }
00068 TZAbstractTable = class(TZAbstractDataset)
00069 private
00070 FTableName: string;
00071
00072 private
00073 function GetExists: Boolean;
00074 procedure SetTableName(const Value: string);
00075
00076 protected
00077 {$IFDEF WITH_IPROVIDER}
00078 function PSIsSQLBased: Boolean; override;
00079 {$IFDEF BDS4_UP}
00080 function PSGetTableNameW: WideString; override;
00081 {$ELSE}
00082 function PSGetTableName: string; override;
00083 {$ENDIF}
00084 procedure PSSetCommandText(const ACommandText: string); override;
00085 {$ENDIF}
00086
00087 protected
00088 property Exists: Boolean read GetExists;
00089 property TableName: string read FTableName write SetTableName;
00090 end;
00091
00092 implementation
00093
00094
00095 { TZAbstractTable }
00096
00097 {**
00098 Checks if a table with the corresponding name exists in the database.
00099 @return <code>True</code> if the the table exists.
00100 }
00101 function TZAbstractTable.GetExists: Boolean;
00102 var
00103 TableList: TStringList;
00104 begin
00105 TableList := TStringList.Create;
00106 try
00107 CheckConnected;
00108 Connection.GetTableNames(TableName, TableList);
00109 {$IFNDEF VER130BELOW}TableList.CaseSensitive := False;{$ENDIF}
00110 Result := (TableList.IndexOf(TableName) >= 0);
00111 finally
00112 TableList.Free;
00113 end;
00114 end;
00115
00116 {**
00117 Sets a new table name and generates a related SQL statement.
00118 @param Value a new name of table.
00119 }
00120 procedure TZAbstractTable.SetTableName(const Value: string);
00121 begin
00122 if FTableName <> Value then
00123 begin
00124 FTableName := Value;
00125 if Value <> '' then
00126 SQL.Text := Format('SELECT * FROM %s', [FTableName])
00127 else SQL.Text := '';
00128 end;
00129 end;
00130
00131 {$IFDEF WITH_IPROVIDER}
00132
00133 {**
00134 Checks if dataset can execute SQL queries?
00135 @returns <code>True</code> if the query can execute SQL.
00136 }
00137 function TZAbstractTable.PSIsSQLBased: Boolean;
00138 begin
00139 Result := False;
00140 end;
00141
00142 {**
00143 Gets the name of the table.
00144 @returns the name of this table.
00145 }
00146 {$IFDEF BDS4_UP}
00147 function TZAbstractTable.PSGetTableNameW: WideString;
00148 {$ELSE}
00149 function TZAbstractTable.PSGetTableName: string;
00150 {$ENDIF}
00151 begin
00152 Result := TableName;
00153 end;
00154
00155 {**
00156 Assignes a new name for this table.
00157 @param ACommandText a new name for this table.
00158 }
00159 procedure TZAbstractTable.PSSetCommandText(const ACommandText: string);
00160 begin
00161 TableName := ACommandText;
00162 end;
00163
00164 {$ENDIF}
00165
00166 end.