{
name:
UpdateTextBlobField_Ex
usage:
update a blob field
parameter:
theTableName - table name
thePrimaryKeyName - name of the primary key
thePrimaryKeyValue - value of the primary key
theFieldName - field name of the blob field
theText - field value
return parameter:
theErrorStr - error message
return:
false on error
notes:
- additional to UpdateTextBlobField name of the
primary key is needed
}
function UpdateTextBlobField_Ex(
const theTableName:
String;
const thePrimaryKeyName:
String; thePrimaryKeyValue: Integer;
const theFieldName:
String;
const theText:
String;
var theErrorStr:
String): Boolean;
var
FQuerySQL : TQuery;
begin
Result:= False;
theErrorStr:= S_internal_error;
try
FQuerySQL := CreateQuery;
// TQuery.Create ...
try
with FQuerySQL
do
begin
DataBaseName:= C_ALIASNAME;
// Konstante
SQL.Add('
Update '+theTableName+'
Set ');
SQL.Add(theFieldName+'
=:'+theFieldName);
SQL.Add('
Where '+thePrimaryKeyName+'
=:Id');
ParamByName('
Id').AsInteger:= thePrimaryKeyValue;
if theText='
'
then
begin
ParamByName(theFieldName).DataType:= ftBlob;
ParamByName(theFieldName).Clear;
ParamByName(theFieldName).Bound:= True;
end
else
begin
ParamByName(theFieldName).AsBlob:= theText;
end;
ExecSQL;
end;
{ with FQuerySQL do }
Result:= True;
finally
FQuerySQL.Free;
end;
except
on E:
Exception do theErrorStr:= E.
message;
end;
end;
{ UpdateTextBlobField_Ex }
{
name:
LoadTextBlobField_Ex
usage:
load the text from the blob field
parameter:
theTableName - table name
thePrimaryKeyName - name of the primary key
thePrimaryKeyValue - value of the primary key
theFieldName - field name of the blob field
return parameter
theText - the loaded field value
theErrorStr - error message
return:
false on error
notes:
- additional to LoadTextBlobField name of the
primary key is needed
}
function LoadTextBlobField_Ex(
const theTableName:
String;
const thePrimaryKeyName:
String; thePrimaryKeyValue: Integer;
const theFieldName:
String;
var theText:
String;
var theErrorStr:
String): Boolean;
var
FQuerySQL : TQuery;
StringStream : TStringStream;
Stream : TStream;
bOK : Boolean;
begin
bOK:= False;
theErrorStr:= S_internal_error;
theText:= '
';
try
FQuerySQL := CreateQuery;
// TQuery.Create ...
StringStream := TStringStream.Create('
');
try
with FQuerySQL
do
begin
SQL.Add('
Select '+theFieldName+'
From '+theTableName);
SQL.Add('
Where '+thePrimaryKeyName+'
=:Id');
ParamByName('
Id').AsInteger:= thePrimaryKeyValue;
Open;
try
if QueryIsNotEmpty
then
begin
Stream:= CreateBlobStream(FieldByName(theFieldName),bmRead);
try
StringStream.CopyFrom(Stream,0);
finally
Stream.Free;
end;
theText:= StringStream.DataString;
bOK:= True;
end;
finally
Close;
end;
end;
{ with FQuerySQL do }
finally
FQuerySQL.Free;
StringStream.Free;
end;
except
on E:
Exception do
begin
theErrorStr:= E.
message;
end;
end;
Result:= bOK;
end;
{ LoadTextBlobField_Ex }