Problem with "gbk and blob field"
Problem with "gbk and blob field"
database: mydql 5.0
db access Compoents: mydac4.3
mysql default character set: gbk
when i post a picture to blob field of a table, a error occur. while set mydac connection character set to spsce, it works ok.
why?
db access Compoents: mydac4.3
mysql default character set: gbk
when i post a picture to blob field of a table, a error occur. while set mydac connection character set to spsce, it works ok.
why?
Please supply us following information:
- Exact version of Delphi, C++ Builder or Kylix
- Exact version of MyDAC. You can see it in About sheet of TMyConnection Editor
- Exact version of MySQL server and MySQL client. You can see it in Info sheet of TMyConnection Editor
- Exact definition of the field used to store BLOBs
- Exact version of Delphi, C++ Builder or Kylix
- Exact version of MyDAC. You can see it in About sheet of TMyConnection Editor
- Exact version of MySQL server and MySQL client. You can see it in Info sheet of TMyConnection Editor
- Exact definition of the field used to store BLOBs
thanks.
Exact version of Delphi: 7.0 build 8.1
Exact version of MyDAC: 4.30.0.11 trial for delphi 7
Exact version of MySQL server and MySQL client :
MySQL server version: 5.0.22-community-nt
MySQL client version: Direct
- Exact definition of the field used to store BLOBs:
CREATE TABLE `b0001_pic` (
`Pic_Id` smallint(6) unsigned NOT NULL auto_increment,
`Pic_Image` longblob,
PRIMARY KEY (`Pic_Id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
Exact version of Delphi: 7.0 build 8.1
Exact version of MyDAC: 4.30.0.11 trial for delphi 7
Exact version of MySQL server and MySQL client :
MySQL server version: 5.0.22-community-nt
MySQL client version: Direct
- Exact definition of the field used to store BLOBs:
CREATE TABLE `b0001_pic` (
`Pic_Id` smallint(6) unsigned NOT NULL auto_increment,
`Pic_Image` longblob,
PRIMARY KEY (`Pic_Id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
I store Image info in blob field , so, I modify the procedure:
procedure TData.WriteBlob(FieldNo: word; RecBuf: IntPtr; Position: longint;
Count: longint; Source: IntPtr);
var
Blob: TBlob;
S: string;
Ws: WideString;
Buf: IntPtr;
begin
Blob := TBlob(GetObject(FieldNo, RecBuf));
Blob.EnableRollback;
Blob.Write(Position, Count, Source); // add by vga
{ //delete by vga
if not Blob.FIsUnicode then
Blob.Write(Position, Count, Source)
else
begin
S := Marshal.PtrToStringAnsi(Source, Count);
Ws := S;
Buf := Marshal.StringToHGlobalUni(Ws);
try
Blob.Write(Position shl 1, Count shl 1, Buf);
finally
Marshal.FreeCoTaskMem(Buf);
end;
end;
} // delete
SetNull(FieldNo, RecBuf, False);
end;
thanks.
procedure TData.WriteBlob(FieldNo: word; RecBuf: IntPtr; Position: longint;
Count: longint; Source: IntPtr);
var
Blob: TBlob;
S: string;
Ws: WideString;
Buf: IntPtr;
begin
Blob := TBlob(GetObject(FieldNo, RecBuf));
Blob.EnableRollback;
Blob.Write(Position, Count, Source); // add by vga
{ //delete by vga
if not Blob.FIsUnicode then
Blob.Write(Position, Count, Source)
else
begin
S := Marshal.PtrToStringAnsi(Source, Count);
Ws := S;
Buf := Marshal.StringToHGlobalUni(Ws);
try
Blob.Write(Position shl 1, Count shl 1, Buf);
finally
Marshal.FreeCoTaskMem(Buf);
end;
end;
} // delete
SetNull(FieldNo, RecBuf, False);
end;
thanks.
DM.SQLQuery_JobInfo.SQL.Text :=
'select * from `' + JobInfoTable + '` limit 1';
DM.SQLQuery_JobInfo.Active := True;
if DM.SQLQuery_JobInfo.IsEmpty then
DM.SQLQuery_JobInfo.Append
else
DM.SQLQuery_JobInfo.Edit;
TBlobField(DM.SQLQuery_JobInfo.FieldByName('Pic_Image')).LoadFromFile(edtSamplePicName.Text);
gExtName := ExtractFileExt(edtSamplePicName.Text);
DM.SQLQuery_JobInfo.FieldByName('ExtName').AsString := gExtName;
DM.SQLQuery_JobInfo.FieldByName('UseFirstPage').AsString := gFirstPage;
DM.SQLQuery_JobInfo.Post; // error occured here
'select * from `' + JobInfoTable + '` limit 1';
DM.SQLQuery_JobInfo.Active := True;
if DM.SQLQuery_JobInfo.IsEmpty then
DM.SQLQuery_JobInfo.Append
else
DM.SQLQuery_JobInfo.Edit;
TBlobField(DM.SQLQuery_JobInfo.FieldByName('Pic_Image')).LoadFromFile(edtSamplePicName.Text);
gExtName := ExtractFileExt(edtSamplePicName.Text);
DM.SQLQuery_JobInfo.FieldByName('ExtName').AsString := gExtName;
DM.SQLQuery_JobInfo.FieldByName('UseFirstPage').AsString := gFirstPage;
DM.SQLQuery_JobInfo.Post; // error occured here
Thank you for the sample. Your sample shows that the problem does not concern working with a BLOB field. As we can see, the UseUnicode option of the connection object is set to True. So try to use:
instead of:
Code: Select all
ParamByName('xxx').AsWideString := ;Code: Select all
ParamByName('xxx').AsString := ;