Insert BlobField problem (was TMyConnection Charset problem)
Posted: Wed 25 Feb 2009 04:56
Hi all,
I'm developing an application for member management, which will require using Chinese characters for member name. I used to use GB2312 charset, which works fine, but I have to switch to GBK charset, since GBK could display more characters that Gb2312 could not display.
I have changed the MySQL database and tables to work fine with GBK charset, but when I switch the TMyConnection->Options->Charset setting to GBK, it gives error #42000. The member name field has been converted to some garbage that my application could not handle.
See error screenshot:

What I'm trying to do is copy the selected member data to another table (both tables have identical field design, the destination table serves as a temporary holder for selected members data) for information printout.
Here is the code snippet for the copy operation, I'm using MyDAC 5.55.0.39, MySQL 5.0.24 and Borland C++ Builder 6 Enterprise and WinXP Professional SP3 (Chinese Traditional edition, but configure to work with Chinese Simplified applications).
CardT is the destination table and MemSrcGrid is the TCRDBGrid containing the source data.
Can anyone tell me how to make GBK charset work (GB2312 works fine with the exact same code), please?
I'm developing an application for member management, which will require using Chinese characters for member name. I used to use GB2312 charset, which works fine, but I have to switch to GBK charset, since GBK could display more characters that Gb2312 could not display.
I have changed the MySQL database and tables to work fine with GBK charset, but when I switch the TMyConnection->Options->Charset setting to GBK, it gives error #42000. The member name field has been converted to some garbage that my application could not handle.
See error screenshot:

What I'm trying to do is copy the selected member data to another table (both tables have identical field design, the destination table serves as a temporary holder for selected members data) for information printout.
Here is the code snippet for the copy operation, I'm using MyDAC 5.55.0.39, MySQL 5.0.24 and Borland C++ Builder 6 Enterprise and WinXP Professional SP3 (Chinese Traditional edition, but configure to work with Chinese Simplified applications).
Code: Select all
TDataSet *ds = MemSrcGrid->DataSource->DataSet;
TBlobField *dstblob;
TStream *srcstream;
for(int i=0; iSelectedRows->Count; i++)
{
ds->GotoBookmark((void *)MemSrcGrid->SelectedRows->Items[i].c_str());
CardT->Append();
CardT->FieldByName("mem_id")->AsString = "*" + ds->FieldByName("mem_id")->AsString + "*";
CardT->FieldByName("mem_name1")->AsString = ds->FieldByName("mem_name1")->AsString;
CardT->FieldByName("mem_name2")->AsString = ds->FieldByName("mem_name2")->AsString;
CardT->FieldByName("mem_year")->AsString = ds->FieldByName("mem_year")->AsString;
CardT->FieldByName("mem_class")->AsString = ds->FieldByName("mem_class")->AsString;
CardT->FieldByName("mem_sex")->AsString = ds->FieldByName("mem_sex")->AsString;
srcstream = ds->CreateBlobStream(ds->FieldByName("mem_photo"), bmRead);
dstblob = (TBlobField *)CardT->FieldByName("mem_photo");
dstblob->LoadFromStream(srcstream);
CardT->FieldByName("mem_kodsek")->AsString = ds->FieldByName("mem_kodsek")->AsString;
CardT->Post();
}
Can anyone tell me how to make GBK charset work (GB2312 works fine with the exact same code), please?