00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Blob streams classes }
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 ZStreamBlob;
00055
00056 interface
00057
00058 {$I ZComponent.inc}
00059
00060 uses Classes, SysUtils, ZDbcIntfs, DB;
00061
00062 type
00063 {** Implements a class for blobs stream. }
00064 TZBlobStream = class(TMemoryStream)
00065 private
00066 FField: TBlobField;
00067 FBlob: IZBlob;
00068 FMode: TBlobStreamMode;
00069 protected
00070 property Blob: IZBlob read FBlob write FBlob;
00071 property Mode: TBlobStreamMode read FMode write FMode;
00072 public
00073 constructor Create(Field: TBlobField; Blob: IZBlob; Mode: TBlobStreamMode);
00074 destructor Destroy; override;
00075 end;
00076
00077 implementation
00078
00079 { TZBlobStream }
00080
00081 {**
00082 Constructs this object and assignes the main properties.
00083 @param Blob
00084 }
00085 constructor TZBlobStream.Create(Field: TBlobField; Blob: IZBlob; Mode: TBlobStreamMode);
00086 var
00087 TempStream: TStream;
00088 begin
00089 inherited Create;
00090
00091 FBlob := Blob;
00092 FMode := Mode;
00093 FField := Field;
00094 if (Mode in [bmRead, bmReadWrite]) and not Blob.IsEmpty then
00095 begin
00096 TempStream := Blob.GetStream;
00097 try
00098 TempStream.Position := 0;
00099 CopyFrom(TempStream, TempStream.Size);
00100 Position := 0;
00101 finally
00102 TempStream.Free;
00103 end;
00104 end;
00105 end;
00106
00107 type THackedDataset = class(TDataset);
00108
00109 {**
00110 Destroys this object and cleanups the memory.
00111 }
00112 destructor TZBlobStream.Destroy;
00113 begin
00114 if Mode in [bmWrite, bmReadWrite] then
00115 begin
00116 if Assigned(Self.Memory) then
00117 Blob.SetStream(Self)
00118 else Blob.SetStream(nil);
00119 try
00120 if Assigned(FField.Dataset) then
00121 THackedDataset(FField.DataSet).DataEvent(deFieldChange, LongInt(FField));
00122 except
00123 {$IFNDEF VER130BELOW}
00124 ApplicationHandleException(Self);
00125 {$ELSE}
00126 ShowException(ExceptObject, ExceptAddr);
00127 {$ENDIF}
00128 end;
00129 end;
00130 inherited Destroy;
00131 end;
00132
00133 end.
00134