Home > Back-end >  How Sql to add images on the table?
How Sql to add images on the table?

Time:11-02

Photo: rdphoto (need to support flow deposit)

CodePudding user response:

This is my the source of the project:
//save picture
Procedure TfrmSetPrintFormat. SaveImage ();
Var
Stream: TMemoryStream;
The begin
If imgTicket. Picture. Width=0 then
//no PIC
The Exit;
Stream:=TMemoryStream. Create;//create a memory stream
Case intPictureType of
1:
ImgTicket. Picture. Graphic. SaveToStream (Stream);//save the picture the memory stream
2:
ImgTicket. Picture. Bitmap. SaveToStream (Stream).//save the picture the memory stream
0:
ImgTicket. Picture. Bitmap. SaveToStream (Stream).//save the picture the memory stream
end;

ImgTicket. Picture. Graphic. SaveToStream (Stream);//save the picture the memory stream
QSet. Close;
QSet. The Parameters. The Clear;
QSet. SQL. The Clear;
QSet. SQL. Add (' UPDATE PrintScheme SET Photo=: Photo of PhotoType='+
IntToStr (intPictureType) + 'WHERE ID=' + IntToStr (intSchemeContentID));
QSet. The Parameters. ParamByName (' photo.) LoadFromStream (Stream, ftBlob);//read save memory map
QSet. ExecSQL;
Stream. Free;//release the memory flow
end;
//load the picture
Procedure TfrmSetPrintFormat. LoadImage;
Var
Stream: TMemoryStream;
Jpg: TjpegImage;
PNG: TPngImage;
The begin
If not OpenSQL (qSet, 'the SELECT Photo, PhotoType FROM PrintScheme WHERE ID=' + IntToStr (intSchemeContentID)) then
The Exit;
If qSet. Eof then
The Exit;
If not qSet. FieldByName (' Photo.) IsNull then
The begin
//read picture type
IntPictureType:=qSet FieldByName (' PhotoType). AsInteger;
//load the picture
Stream:=TMemoryStream. Create;
TBlobField (qSet FieldByName (' Photo ')). SaveToStream (Stream);//display into BlobField and save the memory stream
Stream. Position:=0;
Case intPictureType of
1:
The begin
Jpg:=TjpegImage. Create;
Jpg. LoadFromStream (Stream);//load the picture
ImgTicket. Picture. Graphic. Assign (Jpg);
Jpg. Free;
end;
2:
The begin
PNG:=TPngImage. Create;
PNG. LoadFromStream (Stream);//load the picture
ImgTicket. Picture. The Bitmap. The Assign (Png);
PNG. Free;
end;
0:
ImgTicket. Picture. Bitmap. LoadFromStream (Stream).
The else
ImgTicket. Picture:=nil;
end;
Stream. Free;
End
The else
The begin
ImgTicket. Picture:=nil;
end;
end;

CodePudding user response:

reference 1st floor xrbaa response:
this is my the source of the project:
The begin
If not OpenSQL (qSet, 'the SELECT Photo, PhotoType FROM PrintScheme WHERE ID=' + IntToStr (intSchemeContentID)) then
The Exit;
If qSet. Eof then
The Exit;
If not qSet. FieldByName (' Photo.) IsNull then
The begin
end;

Please explain what OpenSQL usage, I can't check this function, thank you

CodePudding user response:

May is a function of his own writing ~ ~ ~

CodePudding user response:

Is a function of my own writing:
//open the SQL statement and returns True on success
The function TfrmMain. OpenSQL (query: TADOQuery; StrSQL: string) : Boolean;
The begin
Result:=True;
Query. Close;
Query. SQL. The Clear;
Query. SQL. The Add (strSQL);
Try
Query. The Open;
Except,
Result:=False;
end;
end;

CodePudding user response:

reference 1st floor xrbaa response:
this is my the source of the project:
//save picture
Procedure TfrmSetPrintFormat. SaveImage ();
Var
Stream: TMemoryStream;
The begin
If imgTicket. Picture. Width=0 then
//no PIC
The Exit;
Stream:=TMemoryStream. Create;//create a memory stream
Case intPictureType of
1:
ImgTicket. Picture. Graphic. SaveToStream (Stream);//save the picture the memory stream
2:
ImgTicket. Picture. Bitmap. SaveToStream (Stream).//save the picture the memory stream
0:
ImgTicket. Picture. Bitmap. SaveToStream (Stream).//save the picture the memory stream
end;

ImgTicket. Picture. Graphic. SaveToStream (Stream);//save the picture the memory stream
QSet. Close;
QSet. The Parameters. The Clear;
QSet. SQL. The Clear;
QSet. SQL. Add (' UPDATE PrintScheme SET Photo=: Photo of PhotoType='+
IntToStr (intPictureType) + 'WHERE ID=' + IntToStr (intSchemeContentID));
QSet. The Parameters. ParamByName (' photo.) LoadFromStream (Stream, ftBlob);//read save memory map
QSet. ExecSQL;
Stream. Free;//release the memory flow
end;
//load the picture
Procedure TfrmSetPrintFormat. LoadImage;
Var
Stream: TMemoryStream;
Jpg: TjpegImage;
PNG: TPngImage;
The begin
If not OpenSQL (qSet, 'the SELECT Photo, PhotoType FROM PrintScheme WHERE ID=' + IntToStr (intSchemeContentID)) then
The Exit;
If qSet. Eof then
The Exit;
If not qSet. FieldByName (' Photo.) IsNull then
The begin
//read picture type
IntPictureType:=qSet FieldByName (' PhotoType). AsInteger;
//load the picture
Stream:=TMemoryStream. Create;
TBlobField (qSet FieldByName (' Photo ')). SaveToStream (Stream);//display into BlobField and save the memory stream
Stream. Position:=0;
Case intPictureType of
1:
The begin
Jpg:=TjpegImage. Create;
Jpg. LoadFromStream (Stream);//load the picture
ImgTicket. Picture. Graphic. Assign (Jpg);
Jpg. Free;
end;
2:
The begin
PNG:=TPngImage. Create;
PNG. LoadFromStream (Stream);//load the picture
ImgTicket. Picture. The Bitmap. The Assign (Png);
PNG. Free;
end;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related