Page 1 of 1

How to write data from buffer to BLOB field? (MyDac 5.10 + Codegear C++ Builder 2007)

Posted: Wed 04 Jun 2008 11:17
by Dave_Scream
Hi. Im trying to save buffer to BLOB field "buffer", but after Post() Im always get

error message: "#42000You have an error in your SQL syntax; check manual that corresponds to your MySQL server version for the right syntax to use near " at line 4."

first part of code (normal):

Code: Select all

void *buffer = &qitem->buffer;
int size = qitem->lpspec->numConst;

query->SQL->Text = "SELECT buffer FROM areas WHERE area_id = '"+IntToStr(qitem->area_id)+"';";
query->Execute();
data->DataSet->First();
data->DataSet->Edit();

// .... second part .....
second parts:
try 1:

Code: Select all

data->DataSet->CreateBlobStream(data->DataSet->Fields->FieldByName("buffer"),bmWrite)->WriteBuffer(buffer,size);
data->DataSet->Post(); // here error
try2:

Code: Select all

TMemoryStream *stream = new TMemoryStream();
stream->WriteBuffer(buffer,size);
TBlobField *blob = (TBlobField*)data->DataSet->Fields->FieldByName("buffer");
blob->LoadFromStream(stream);
data->DataSet->Post();  // here error
try3

Code: Select all

TField *field = data->DataSet->Fields->FieldByName("buffer");
field->SetFieldType(ftBlob);
TBlobStream *stream = new TBlobStream(field,bmWrite);
stream->WriteBuffer(buffer,size);

data->DataSet->Post();

//Compile Errors:
//[BCC32 Error] main.cpp(203): E2015 Ambiguity between 'TBlobStream' and 'Dbtables::TBlobStream'
//[BCC32 Error] main.cpp(203): E2285 Could not find a match for 'TBlobStream::TBlobStream(TField *,TBlobStreamMode)'
try4

Code: Select all

TField *field = data->DataSet->Fields->FieldByName("buffer");
field->SetFieldType(ftBlob);
Dbtables::TBlobStream *stream = new Dbtables::TBlobStream(field,bmWrite);
stream->WriteBuffer(buffer,size);

data->DataSet->Post();

// Compile Error:
// [BCC32 Error] main.cpp(203): E2285 Could not find a match for 'Dbtables::TBlobStream::TBlobStream(TField *,TBlobStreamMode)'
---
what I'm using:
- Codegear C++ Builder 2007
- MyDac v5.10
- MySql server version: 4.1.9-max
- table description (look at BLOB field called 'buffer' ):

Code: Select all

CREATE TABLE pooler.areas (
  area_id INT(11) UNSIGNED AUTO_INCREMENT COMMENT 'ID области данных',
  port INT(8) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'COM порт',
  device_address INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Номер устройства',
  data_address BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Адрес данных',
  type VARCHAR(20) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '' COMMENT 'Тип данных',
  channels INT(11) UNSIGNED DEFAULT NULL COMMENT 'Количество каналов',
  period TIME NOT NULL DEFAULT '00:00:00' COMMENT 'Период опроса',
  modifyed TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP COMMENT 'Когда были внесены последние изменения',
  buffer BLOB DEFAULT NULL COMMENT 'Приемный буффер',
  PRIMARY KEY (area_id)
)
ENGINE = INNODB
ROW_FORMAT = DYNAMIC
AUTO_INCREMENT = 3
CHARACTER SET cp1251 COLLATE cp1251_general_ci;
---
how i can write (int)size bytes of (void*)buffer to BLOB field in my DB?

Posted: Thu 05 Jun 2008 12:08
by Antaeus
I could not reproduce this problem with the last MyDAC. Try to download the last build of MyDAC (5.50.0.34) from our site. It contains some fixes related to BLOB. If the problem persists in the last MyDAC, send me a complete small sample at mydac*crlab*com to demonstrate it.