Zeos 6.6.5-stable. Postgresql 8.4
Dataset.Open;
TmpStream := TFileStream.Create('c:\bplab1.jpg', fmOpenRead);
BlobField := Dataset.FieldByName('b_image2');
BlobStream := Dataset.CreateBlobStream(BlobField, bmReadWrite);
BlobStream.CopyFrom(TmpStream,TmpStream.Size);
TmpStream.Free;
BlobStream.Free;
Dataset.Post;
Dataset.Close;
Information is not Saved!!
In addition, the example ZBlobsMain does not work with BLOB, which comes in a stable version.
In what could be the problem? And how to solve it?
Not saved information in the field bytea. Postgresql 8.4
Moderators: gto, EgonHugeist
var
BlobStream: TStream;
FileStream: TStream;
begin
qrBlob.Open;
if not(qrBlob.State in [dsEdit, dsInsert])
then qrBlob.Edit;
BlobStream := qrBlob.CreateBlobStream(qrBlob.FieldByName('report_blob'), bmWrite);
try
FileStream := TFileStream.Create('C:\ProjSource\corp2\run\corp\bin\reports\zajav_ogl_teh_jur.fr3', fmOpenRead);
try
BlobStream.CopyFrom(FileStream, FileStream.Size);
finally
FileStream.Free;
end;
finally
BlobStream.Free;
end;
qrBlob.Post;
qrBlob.Close;
end;
Error - Invalid large-object descriptor: 0
begin
qrBlob.Open;
if not(qrBlob.State in [dsEdit, dsInsert])
then qrBlob.Edit;
qrBlobreport_blob.LoadFromFile('C:\ProjSource\corp2\run\corp\bin\reports\zajav_ogl_teh_jur.fr3');
qrBlob.Post;
qrBlob.Close;
end;
Error - Invalid large-object descriptor: 0
qrBlobreport_blob - type TBlobField
BlobStream: TStream;
FileStream: TStream;
begin
qrBlob.Open;
if not(qrBlob.State in [dsEdit, dsInsert])
then qrBlob.Edit;
BlobStream := qrBlob.CreateBlobStream(qrBlob.FieldByName('report_blob'), bmWrite);
try
FileStream := TFileStream.Create('C:\ProjSource\corp2\run\corp\bin\reports\zajav_ogl_teh_jur.fr3', fmOpenRead);
try
BlobStream.CopyFrom(FileStream, FileStream.Size);
finally
FileStream.Free;
end;
finally
BlobStream.Free;
end;
qrBlob.Post;
qrBlob.Close;
end;
Error - Invalid large-object descriptor: 0
begin
qrBlob.Open;
if not(qrBlob.State in [dsEdit, dsInsert])
then qrBlob.Edit;
qrBlobreport_blob.LoadFromFile('C:\ProjSource\corp2\run\corp\bin\reports\zajav_ogl_teh_jur.fr3');
qrBlob.Post;
qrBlob.Close;
end;
Error - Invalid large-object descriptor: 0
qrBlobreport_blob - type TBlobField
-
- Senior Boarder
- Posts: 93
- Joined: 01.07.2009, 16:07
Vary nice! So, i`m use SQL, NOT TZTable!rudjuk wrote:In general, knows how to work zeoslib with blob-fields of the database Postgresql?
And write to Postgre 8.3.11 is work. Try Post before TStream.free.
This is my code (C++):
Code: Select all
in this example q1 - is TZQuery
plg_db->q1->SQL->Add("update docum set doc_cname=:FNAME, doc_cont=:CNT where doc_code=:CODE");
plg_db->q1->ParamByName("code")->AsString = Code;
plg_db->q1->ParamByName("CNT")->LoadFromFile(win->edDocFile->Text, ftBlob);
plg_db->q1->ParamByName("FNAME")->AsString=ExtractFileName(win->edDocFile->Text);
plg_db->q1->ExecSQL();
Code: Select all
try
{
plg_db->StartTransaction();
plg_db->q2->SQL->Clear();
plg_db->q2->SQL->Add("select doc_cont, doc_cname from docum WHERE doc_code=:cod");
Code = plg_db->q8->FieldByName("doc_code")->AsString;
plg_db->q2->ParamByName("cod")->AsString = Code;
GUID = Code;
plg_db->q2->Open();
path = DM->TMP_PATH + "\" + Code;
dName = plg_db->q8->FieldByName("doc_cname")->AsString;
fname = path + "\" + dName; //+ ".7z";
ForceDirectories(path);
//---- CUT HERE!!!!!!!!!!!!!!!!!!!!!! ------------------------------
TFileStream *file = new TFileStream(fname, fmCreate);
TStream *bs = plg_db->q2->CreateBlobStream(plg_db->q2->FieldByName("doc_cont"), bmRead);
file->CopyFrom(bs, bs->Size);
delete file;
delete bs;
//---- CUT HERE!!!!!!!!!!!!!!!!!!!!!! ------------------------------
plg_db->Rollback();
}
catch (EXCEPTIONCLASS &E)
{
if (!plg_comdlg->CheckKnownErrors(E))
plg_comdlg->ShowError(this->ClassName(), "cmOpenContExecute",
plg_comdlg->TranslatePostgreERR(E), E.Message, false);
plg_db->Rollback();
}