Params.asBlob FireDAC 下的赋值给出 W1058
Params.asBlob assignment under FireDAC gives W1058
FireDAC 示例项目(演示 ArrayDML)c:\Users\Public\Documents\Embarcadero\Studio.0\Samples\Object Pascal\Database\FireDAC\Samples\Comp Layer\TFDQuery\ExecSQL\Batch\Batch.dproj
在 //W 1058
指示的 Params[2].AsBlobs
分配上带有两个 // W1058 Implicit string cast with potential data loss from string to rawbytestring
警告编译:
procedure TfrmBatch.btnExecSQLClick(Sender: TObject);
var
i: Integer;
iTm: LongWord;
begin
qrySelect.Open;
qrySelect.ServerDeleteAll(True);
qrySelect.Close;
with qryBatch do
if cbxBatchExec.Checked then begin
Params.ArraySize := StrToInt(edtArraySize.Text);
iTm := GetTickCount;
for i := 0 to Params.ArraySize - 1 do begin
Params[0].AsIntegers[i] := i;
Params[1].AsStrings[i] := 'string' + IntToStr(i);
Params[1].Size := 20;
if cbxInsertBlob.Checked then
Params[2].AsBlobs[i] := 'blob' + IntToStr(i); // W1058
end;
Execute(Params.ArraySize);
iTm := GetTickCount - iTm;
end
else begin
Params.ArraySize := 1;
iTm := GetTickCount;
for i := 0 to StrToInt(edtArraySize.Text) - 1 do begin
Params[0].AsInteger := i;
Params[1].AsString := 'string' + IntToStr(i);
Params[1].Size := 20;
if cbxInsertBlob.Checked then
Params[2].AsBlob := 'blob' + IntToStr(i); // W1058
ExecSQL;
end;
iTm := GetTickCount - iTm;
end;
StatusBar1.SimpleText := 'Time executing is ' + FloatToStr(iTm / 1000.0) + ' sec.';
qrySelect.Open;
end;
解决这个问题的正确方法是什么? (在 FireDAC 下,AsBlobs 已更改为 Windows 下的 TFDByteString
= RawByteString
)。转换为 RawByteString()
或 Params[2].Value
赋值都会使编译器警告消失,但我不确定这是否会导致潜在问题...
如果您决定在分配参数值之前将二进制 BLOB 数据存储在 String type variable, you can lose them, and by adding typecast to RawByteString 中,您只需说编译器,即您同意潜在的数据丢失。仅此而已。
正确的方法是将 BLOB 数据存储在此类参数的 RawByteString 类型变量中。
FireDAC 示例项目(演示 ArrayDML)c:\Users\Public\Documents\Embarcadero\Studio.0\Samples\Object Pascal\Database\FireDAC\Samples\Comp Layer\TFDQuery\ExecSQL\Batch\Batch.dproj
在 //W 1058
指示的 Params[2].AsBlobs
分配上带有两个 // W1058 Implicit string cast with potential data loss from string to rawbytestring
警告编译:
procedure TfrmBatch.btnExecSQLClick(Sender: TObject);
var
i: Integer;
iTm: LongWord;
begin
qrySelect.Open;
qrySelect.ServerDeleteAll(True);
qrySelect.Close;
with qryBatch do
if cbxBatchExec.Checked then begin
Params.ArraySize := StrToInt(edtArraySize.Text);
iTm := GetTickCount;
for i := 0 to Params.ArraySize - 1 do begin
Params[0].AsIntegers[i] := i;
Params[1].AsStrings[i] := 'string' + IntToStr(i);
Params[1].Size := 20;
if cbxInsertBlob.Checked then
Params[2].AsBlobs[i] := 'blob' + IntToStr(i); // W1058
end;
Execute(Params.ArraySize);
iTm := GetTickCount - iTm;
end
else begin
Params.ArraySize := 1;
iTm := GetTickCount;
for i := 0 to StrToInt(edtArraySize.Text) - 1 do begin
Params[0].AsInteger := i;
Params[1].AsString := 'string' + IntToStr(i);
Params[1].Size := 20;
if cbxInsertBlob.Checked then
Params[2].AsBlob := 'blob' + IntToStr(i); // W1058
ExecSQL;
end;
iTm := GetTickCount - iTm;
end;
StatusBar1.SimpleText := 'Time executing is ' + FloatToStr(iTm / 1000.0) + ' sec.';
qrySelect.Open;
end;
解决这个问题的正确方法是什么? (在 FireDAC 下,AsBlobs 已更改为 Windows 下的 TFDByteString
= RawByteString
)。转换为 RawByteString()
或 Params[2].Value
赋值都会使编译器警告消失,但我不确定这是否会导致潜在问题...
如果您决定在分配参数值之前将二进制 BLOB 数据存储在 String type variable, you can lose them, and by adding typecast to RawByteString 中,您只需说编译器,即您同意潜在的数据丢失。仅此而已。
正确的方法是将 BLOB 数据存储在此类参数的 RawByteString 类型变量中。