I want to store crypted data in a Varbinary or Varchar Field.
when entering data in mysql with the mysql-QueryBrowser for example:
insert into test values (default,null,'\n\0\n',null);
=#10#00#10
it works and the data is stored correctly in the database.
in my example function u find the create-table and some of my tries.
Code: Select all
procedure TForm1.CastTest();
var binstr:string;
ftb:Tblobfield;
ftbin:TBytesField;
st:TStringStream;
begin
{
CREATE TABLE .`test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`fieldBlob` text,
`fieldChar` varchar(48) DEFAULT NULL,
`bin1` varbinary(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=latin1;
}
//the binary data :
binstr:='123'#0'4567';
//First: This is Working:
st:=TStringStream.Create(binstr);
try
ftb:=(ZQuery1.FieldByName('FieldBlob') as TBlobField);
ftb.LoadFromStream(st);
finally
st.free;
end;
//........
//Second: this doesnt work:
ZQuery1.FieldByName('FieldChar').asString:=binstr;
//the string will be '123' (cut from #0, as expected)
//calling the "FieldChar" as TBlobField this will cause a typecast error
// (ZQuery1.FieldByName('FieldChar') as TBlobField)
//Calling a typecast 4 the bin1 field as TByesField:
ftbin:=(ZQuery1.FieldByName('bin1') as TBytesField);
ftbin.AsString:=binstr;
//this gives an Read Accessviolation at : 0041885B read from adress: 14000000
//at line : 1319 in ZAbstractRODataset.pas
{....
else if Field.DataType = ftBytes then
begin
RowAccessor.SetBytes(ColumnIndex, VarToBytes(PVariant(Buffer)^)); //<<<<<<<<<<<ERORR
end
}
end;
What is the best way to write data over the fields?
You can see, doing this over Blobs works.
I have to write many records, so doing by foot over
'insert' scritps is not a solution.
Thx for your answers
Karsten