Problem with BLOB fields

Code samples and contributions from users for ZeosLib's DBOs of version 6.x

Moderators: gto, cipto_kh, EgonHugeist, mdaems

Post Reply
Anton7
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 29.09.2006, 00:39

Problem with BLOB fields

Post by Anton7 »

How i can insert data in blob field?
next code doesn`t work correct:

Code: Select all

    TStream *Stream2;
    Form2->ZQ2->Insert();
    Stream2 = Form2->ZQ2->CreateBlobStream(Form2->ZQ2->FieldByName("Question"), bmWrite);
    Form2->ZQ2->FieldByName("Question_id")->AsInteger=a;
    Stream2->Write("lalalala",8);
//or Stream2->CopyFrom(..........);
    Form2->ZQ2->Post();
Field "Question_id" have value, but Field "Question" is empty!!!

But code:

Code: Select all

    TStream *Stream2;
    Form2->ZQ2->Insert();
    Form2->ZQ2->FieldByName("Question_id")->AsInteger=a;
    Form2->ZQ2->FieldByName("Question")->AsString="lalalala";
    Form2->ZQ2->Post();
work correct.

I work in C++Builder6 with embedded MySQL 4.1 and ZEOSLIB(rev 113)

PLEASE HELP!!!
martinrame
Junior Boarder
Junior Boarder
Posts: 25
Joined: 24.10.2006, 18:29
Location: Córdoba, Argentina
Contact:

Post by martinrame »

I'm not a C++ developer, but i'll try to help you.

First, replace the TZTables with TZQuery.

Add the insert SQL sentence into the SQL->Text field of TZQuery:

Code: Select all

myQuery->Sql->Text := "Insert into TABLE(IdQuestion, Question) values(:idquestion, :question)";

Now assign the parameters (:idquestion and :question)

// assign a value to idquestion
myQuery->ParamByName("idquestion").AsInteger = a; // a is an integer

// this adds a stream into the param question
// (of course Stream2 must be initialized and contain data)
myQuery->ParamByName("question").LoadFromStream(Stram2, ftBlob);

// exec query
myQuery->ExecSql;
martinrame
Junior Boarder
Junior Boarder
Posts: 25
Joined: 24.10.2006, 18:29
Location: Córdoba, Argentina
Contact:

Post by martinrame »

P.S.: The dots must be replaced with -> (i'm Delphi developer)
Anton7
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 29.09.2006, 00:39

Post by Anton7 »

Sorry, i could not answer earlier.
Only this code workes correctly:

Code: Select all

((TBlobField*)Form2->ZQ2->FieldByName("Question"))->LoadFromStream(str1);
Post Reply