You are not logged in.
Pages: 1
Hi,
I had to do a project in order to create and print receipts. So I used mORMot + Mustache + WPTools + ZEOS.
I am at the end of my project. But I have a little problem with a blob. In fact, I sent my templates (created with mustache) on a PgSQL database. And now I would like to retrieve these blob using mORMot. On my database, the type is "bytea". So my question is : how can I retrieve the blob as text (because my template is html/css). Wich type can I use ?
Thank you
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
TSQLticket_template = class(TSQLRecord)
private
flibelle_template :RawUTF8;
fbin :RawByteString;
fblbid, fid_type_rapport :Integer;
published
property libelle_template: RawUTF8 Read flibelle_template Write flibelle_template;
property bin: RawByteString Read fbin Write fbin;
property blbid: Integer Read fblbid Write fblbid;
property id_type_rapport: Integer Read fid_type_rapport Write fid_type_rapport;
public
end;
procedure TTicketClient.LoadTemplate2(idTemplate: Integer);
var
aTemplate: TSQLticket_template;
begin
aTemplate := TSQLticket_template.CreateAndFillPrepare(CTicket.Database, 'id = ?', [idTemplate]);
try
while aTemplate.FillOne do
begin
FTemplate.Text := aTemplate.bin;
end;
finally
aTemplate.Free;
end;
end;
I have that. But It seems like my FTemplate.text is empty
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
For a BINARY blob, do not use RawByteString, but TSQLRawBlob published property.
Then get the blob explicitly: it is not retrieve by default with other fields.
Use TSQLRest.RetrieveBlob method instead.
See http://synopse.info/files/html/Synopse% … l#TITLE_59
and search for the BLOB keyword in the documentation.
But in your case, you want to store only text, I guess.
So use a plain RawUTF8 field, without any "index ###" length attribute.
It would be stored as a CLOB in th external DB.
And you have nothing special to do.
Online
procedure TTicketClient.LoadTemplate2(idTemplate: Integer);
var
aTemplate: TSQLticket_template;
begin
aTemplate := TSQLticket_template.CreateAndFillPrepare(CTicket.Database, 'id = ?', [idTemplate]);
try
while aTemplate.FillOne do
begin
TSQLRest.RetrieveBlob(TSQLticket_template,idTemplate, ??? ,aTemplate.bin);
end;
finally
aTemplate.Free;
end;
end;
Something like that ?
Last edited by Thomas-Acia (2015-08-27 13:56:47)
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
For a BINARY blob, do not use RawByteString, but TSQLRawBlob published property.
Then get the blob explicitly: it is not retrieve by default with other fields.
Use TSQLRest.RetrieveBlob method instead.See http://synopse.info/files/html/Synopse% … l#TITLE_59
and search for the BLOB keyword in the documentation.But in your case, you want to store only text, I guess.
So use a plain RawUTF8 field, without any "index ###" length attribute.
It would be stored as a CLOB in th external DB.
And you have nothing special to do.
Yes, it's only a template which contains a text.
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
I don't know know to fill all the arguments.
TSQLRecordClass = TSQLticket_template
aID = idTemplate
const BlobFieldName : RawUTF8 = ??
BlobData : I think = aTemplate.bin
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
Please follow http://synopse.info/files/html/Synopse% … l#TITL_146 for external database definition of TSQLRecord classes.
Online
TSQLticket_template = class(TSQLRecord)
private
flibelle_template :RawUTF8;
fbin :TSQLRawBlob;
fblbid, fid_type_rapport :Integer;
published
property libelle_template: RawUTF8 Read flibelle_template Write flibelle_template;
property bin: TSQLRawBlob Read fbin Write fbin;
property blbid: Integer Read fblbid Write fblbid;
property id_type_rapport: Integer Read fid_type_rapport Write fid_type_rapport;
public
end;
I think my TSQLRecord definition is right. I have a TSQLRawBlob. And then I don't know which args to use
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
Please read the doc about how to define properties.
If your template is plain text, do not use a TSQLRawBlob, but a RawUTF8.
TSQLticket_template = class(TSQLRecord)
private
flibelle_template :RawUTF8;
fbin : RawUTF8;
fblbid, fid_type_rapport :Integer;
published
property libelle_template: RawUTF8 index 50 Read flibelle_template Write flibelle_template; // note the INDEX 50 here to create a VARCHAR(50)
property bin: RawUTF8 Read fbin Write fbin; // no INDEX here to create a VARCHAR(max) = CLOB
property blbid: Integer Read fblbid Write fblbid;
property id_type_rapport: Integer Read fid_type_rapport Write fid_type_rapport;
public
end;
Online
Ah !!!! And to retrieve it ??
Last edited by Thomas-Acia (2015-08-28 07:25:19)
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
So do you think I can do that :
FTemplate.Text := aTemplate.bin;
Edit : When I do that: my text value is :
PGh0bWw+DQoNCjxzdHlsZSB0.....
Last edited by Thomas-Acia (2015-08-28 07:38:50)
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
Finally, I used a TSQLRawBlob and the method : RetrieveBlob(). It works perfectly.
I have a last question. I sometimes have a problem with my server :
I think it's a problem with the PostgreSQL connection, maybe a timeout ??
Edit : I saw the ConnectionTimeOutMinutes method in the doc, I tried it, without success.
Last edited by Thomas-Acia (2015-09-02 12:53:03)
Delphi 2010 - Delphi XE5 (x64 Apps) - CodeTyphon - Typhon IDE v 5.7 - FPC 3.1.1 - mORMot 1.18
Windows 7 - VirtualBox : Linux Debian 8.5 Jessie 32 bits
Offline
Pages: 1