Page 1 of 1

Problem with BLOB fields

Posted: 05.11.2006, 14:03
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!!!

Posted: 09.11.2006, 18:53
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;

Posted: 09.11.2006, 18:55
by martinrame
P.S.: The dots must be replaced with -> (i'm Delphi developer)

Posted: 23.11.2006, 23:55
by Anton7
Sorry, i could not answer earlier.
Only this code workes correctly:

Code: Select all

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