Page 1 of 1

Not saved information in the field bytea. Postgresql 8.4

Posted: 12.11.2009, 09:52
by rudjuk
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?

Posted: 12.11.2009, 11:41
by rudjuk
When the running example "ZBlobsMain.dpr" I get an error: SQL Error: Error: Invalid large-object descriptor: 0

Posted: 15.11.2009, 15:25
by seawolf
Have you tried adding ZConnection.Properties.Add('?oidasblob=true')?

Posted: 09.09.2010, 13:10
by rudjuk
seawolf wrote:Have you tried adding ZConnection.Properties.Add('?oidasblob=true')?
Yes.

oidasblob=true

Posted: 09.09.2010, 13:14
by rudjuk
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

Posted: 09.09.2010, 13:53
by rudjuk
In general, knows how to work zeoslib with blob-fields of the database Postgresql?

Posted: 09.09.2010, 17:54
by guidoaerts

Posted: 10.09.2010, 16:14
by mrLion
rudjuk wrote:In general, knows how to work zeoslib with blob-fields of the database Postgresql?
Vary nice! So, i`m use SQL, NOT TZTable!
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();
and

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();
 }