BlueWhaleERPSources\CMS\BlueWhale_Std_CMS_PublicImportC\PublicImportInfoDlg.pas消息 1007,级别 15,状态 1,第 4 行
数字 '106.4399999999999977262632455676794052124023' 超出了数值表示范围(最大精度为 38)。
语句:exec sp_executesql N'insert into BW_CSTMB
(COMPANY, CREATOR, CREATE_DATE, MODIFIER, MODI_DATE, FLAG, MB001, MB002, MB003, MB004, MB005, MB006)
values (@P1,...,@P12)'
,N'...@P11 float...', N'TESTCQLYD',..., 106.4399999999999977262632455676794052124023, 0
106.44 经 IEEE754 double 展开为 106.4399999999999977262632455676794052124023(43 位有效数字);
float 参数原样下发(@P11 float);BW_CSTMB.MB005 是 numeric(7,2)(实测确认),float→numeric 转换时 有效位超过 38 位上限 ⇒ 报 消息 1007。
为什么以前没报:项目在 EntityTopBaseClass.DSPUpdateData(2026-08-30)里已对
更新数据包的浮点字段做过"截断到 6 位小数"的处理;但导入这条路径走的是
PublicImportInfoDlg 自己的赋值逻辑,没有做浮点截断——那里只处理了"字符串字段防科学计数法"
(2026-08-25),浮点字段是直接 AsVariant 原样写入的:
// 原代码(3 处:1219 / 1460 / 1481)
if Field.DataType in [ftString, ftWideString, ftFixedChar, ftWideMemo, ftMemo] then
Field.AsString := FixExcelNumericText(SourceData.FieldByName(SourField))
else
Field.AsVariant:= SourceData.FieldByName(SourField).AsVariant; // ← 浮点噪声原样进入
procedure TPublicImportInfo_Dlg.SetFieldValue(AField, ASourceField: TField);
begin
if (AField=nil) or (ASourceField=nil) then Exit;
if AField.DataType in [ftString, ftWideString, ftFixedChar, ftWideMemo, ftMemo] then
AField.AsString:= FixExcelNumericText(ASourceField) // 字符串: 防科学计数法
else if AField.DataType in [ftFloat, ftBCD, ftFMTBcd, ftCurrency] then
begin
if ASourceField.IsNull then
AField.Clear
else
//浮点: 截断二进制展开噪声, 保留 6 位小数(与原 DSPUpdateData 口径一致)
AField.AsFloat:= StrToFloat(Format('%.6f',[ASourceField.AsFloat]));
end
else
AField.AsVariant:= ASourceField.AsVariant;
end;
> 用 Format('%.6f') + StrToFloat 而非 RoundTo,是为了不引入 Math 单元
> (该单元的 uses 只有 G_Library, SWConst)。
106.4399999999999977… → 106.440000 → 写入 numeric(7,2) 时正常四舍五入为 106.44。
| 行 | 位置 |
|---|---|
| 1219 | `DoImportMaster`(明细导入赋值) |
| 1460 | `InsertData`(记录不存在 → 新增分支) |
| 1481 | `InsertData`(记录存在 → 更新分支) |
Self.SetFieldValue(Field, SourceData.FieldByName(SourField));
BW_CSTMB.MB005 = numeric(7,2)、MB006 = numeric(7,2)、MB007 = nvarchar;106.44,不再触发 1007。BlueWhale_Std_CMS_PublicImportC(导入基本资料通用组件),重新编译后导入工单工时。
首次提交时把 procedure SetFieldValue(...) 的声明插在了字段 FStopFlag 与 RollBacks
之间,编译报:
[dcc32 Error] PublicImportInfoDlg.pas(104): E2169 Field definition not allowed after methods or properties
Delphi 要求字段必须全部位于方法之前。已将声明移到字段区末尾(RollBacks: Integer; 之后)、
其它方法之前:
private
Commits: Integer;
...
FStopFlag: Boolean;
RollBacks: Integer; // ← 字段区结束
//2026-09-18 add by CodeBuddy 统一赋值...
procedure SetFieldValue(AField, ASourceField: TField); // ← 方法声明
function DoImport(TableName: String): Boolean;
方法实现位置不变(文件末尾 InsertData 之后)。
服务端 BlueWhale_Std_CST_SumJobWorkTimeS\SumJobWorkTimeClassS.pas 的
DoInsertCSTMB 是用字符串拼接 SQL 插入的:
mSQL:=Format(' INSERT INTO BW_CSTMB (MB001,MB002,MB003,MB004,MB005,MB006,MB007 )'+
' values(''%s'',''%s'',''%s'',''%s'',%s,%s,''%s'' )' ,[...]);
若 FloatToStr 同样把 double 展开成 43 位,也会在拼接出的 SQL 里触发 1007。
本次报错路径是参数化的客户端保存(ApplyUpdates),故先修导入侧;
如"汇总工单工时"保存时也报 1007,需对这里的数值同样做 Format('%.6f') 处理。