Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2002.07.04;
Скачать: CL | DM;

Вниз

BLOB как параметр UDF   Найти похожие ветки 

 
Patrick ©   (2002-06-10 13:49) [0]

Во входных параметрах UDF использую тип BLOB, UDF компилируется прекрасно. Она должна добавлять строку в поле типа BLOB.

DECLARE EXTERNAL FUNCTION ADDTOBLOB
CSTRING(256),
BLOB
RETURNS PARAMETER 2
ENTRY_POINT "AddToBlob" MODULE_NAME "FreeUDFLib.dll";

исходный текст библиотеки:

export
function InternalPutBlob(Blob: PBlob; Buffer: Pointer; Size: Integer): ULong; cdecl; export;
function AddToBlob(Value: PChar; Blob: PBlob): PBlob; cdecl; export;
.....

function InternalPutBlob(Blob: PBlob; Buffer: Pointer; Size: Integer): ULong; cdecl; export;
var
BytesToWrite: Integer;
begin
Result:= 0;
if Assigned(Blob) then
with Blob^ do
if (Assigned(BlobHandle)) and (Assigned(PutSegment))
then while (Size > 0) do begin
BytesToWrite:= Min(MaxSegmentLength, Size);
PutSegment(BlobHandle, PChar(Buffer) + Result, BytesToWrite);
Dec(Size, BytesToWrite);
Inc(Result, BytesToWrite);
end;
end;

function AddToBlob(Value: PChar; Blob: PBlob): PBlob; cdecl; export;
begin
Result:= Blob;
if Assigned(Result) and Assigned(Value) then
with Result^ do
try
if Assigned(BlobHandle) and Assigned(PutSegment) then
InternalPutBlob(Result, Value, StrLen(Value) + 1)
else
Result:= nil;
except
Result:= nil;
end;
end;


а при вызове UDF в запросе
например

update complect
set history = addtoblob("строка",history)
where complectcode = 0;

выдается ошибка
Unsuccessful execution caused by system error that does not preclude successful execution of subsequent statements.
A fatal exception occurred during the execution of a user defined function.
cannot update old BLOB.

и причем подобное сообщение выдается при вызове любой процедуры в данной библиотеке. Ранее всё работало, но добавив вышеописанные функции, всё съехало.


 
Digitman ©   (2002-06-10 17:14) [1]

примерно так.
код InternalGetBlob() на предмет проверок, предотвращающих утечку, причесывай сам.


function InternalGetBlob(Blob: PBlob; Buffer: Pointer; Size: Integer): ULong;
var
BytesRead: Integer;
begin
Result:= 0;
if Assigned(Blob) then with Blob^ do
if Assigned(BlobHandle) and Assigned(GetSegment) then
while (Size > 0) and Boolean(GetSegment(BlobHandle, PChar(Buffer) + Result, Size, BytesRead)) do begin
Inc(Result, BytesRead);
Dec(Size, BytesRead);
end;
end;


function AddToBlob(Value: PChar; SRCBlob, DSTBlob: PBlob): PBlob; cdecl; export;
var
p: PChar;
begin
Result:= DSTBlob;
if Assigned(Result) and Assigned(Value) then
with Result^ do
try
p := nil;
if Assigned(SRCBlob) and (SRCBlob.TotalSize > 0) then begin
GetMem(p, SRCBlob.TotalSize);
SRCBlob.TotalSize := InternalGetBlob(SRCBlob, p, SRCBlob.TotalSize);
if Assigned(BlobHandle) and Assigned(PutSegment) then begin
if Assigned(p) then begin
InternalPutBlob(Result, p, SRCBlob.TotalSize);
FreeMem(p);
end;
InternalPutBlob(Result, Value, StrLen(Value) + 1);
end else
Result:= nil;
except
Result:= nil;
end;
end


DECLARE EXTERNAL FUNCTION AddToBlob
CSTRING(32767),
BLOB,
BLOB
RETURNS PARAMETER 3
ENTRY_POINT "StringToBlob" MODULE_NAME "audf.dll";







Страницы: 1 вся ветка

Текущий архив: 2002.07.04;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.009 c
1-9797
Shrek
2002-06-24 00:31
2002.07.04
Формы без 3D. Нет обёмных кнопок.


3-9712
Стас
2002-06-07 11:52
2002.07.04
INSERT в Query с параметрами


3-9760
fool
2002-06-13 11:29
2002.07.04
Глюк с полем типа text


1-9890
GrayFox
2002-06-21 19:50
2002.07.04
В TListView caption элемента отображается не полностью


4-10069
Eugene_Jek_Efimochkin
2002-05-02 22:35
2002.07.04
заставить программу думать, что мышка двигается над ней