Possible type mismatch for t_comm parameter in C version of TRF5_1?
Closed this issue · 4 comments
While running dbt5-run I encountered exceptions in TradeResult, but it appears that the error message of exception thrown in
dbt5/src/transactions/pgsql/DBConnection.cpp
Lines 218 to 220 in 5575431
dbt5/src/BrokerageHouse/BrokerageHouse.cpp
Lines 197 to 203 in 5575431
str
to be a garbage value.Therefore I ran TestTxn with gdb and got the followings:
(gdb) p sql
$1 = 0x7fffe8009de0 "SELECT * FROM TradeResultFrame5(4300000001,19.54,'CMPT','2024-5-22 0:53:15',200000008728315,27.14)"
(gdb) printf "%s", (const char *)PQresultErrorMessage(res)
ERROR: numeric field overflow
DETAIL: A field with precision 10, scale 2 must round to an absolute value less than 10^8.
CONTEXT: SQL statement "UPDATE trade
SET t_comm = $1
, t_dts = $2
, t_st_id = $3
, t_trade_price = $4
WHERE t_id = $5"
This statement appears to be TRF5_1 and upon checking the implementation I found that all values related with comm_amount
is processed using float8/double, and there is not another mention of FLOAT4OID in the repo. After changing it to FLOAT8OID the exception is no longer thrown, but I cannot figure out a reason, and I am also wondering whether there are any rationale behind using FLOAT4 specifically for this parameter? Thanks.
dbt5/storedproc/pgsql/c/trade_result.c
Lines 208 to 214 in 5575431
dbt5/storedproc/pgsql/c/trade_result.c
Line 1654 in 5575431
dbt5/storedproc/pgsql/c/trade_result.c
Lines 1667 to 1668 in 5575431
dbt5/storedproc/pgsql/c/trade_result.c
Line 367 in 5575431
Thanks for catching that. The old C user defined functions need some TLC. :)
I believe float4 was used because S_PRICE_T was defined in a way that float4 should have been big enough. I have seen in other publications that vendors are increasing the size of S_PRICE_T, and I tried to do the same in a couple places. So I think it's correct to make sure we are using float8 instead....
Thanks for confirming! Another thing I spotted, as in the beginning of this issue, is that the string pointed to msg.str().c_str()
seemed to be freed while the exception is being thrown, and this makes the str
value in the catch block unable to be used. Fixing this can be helpful as logging str
in error message can save some effort making it to run with a debugger. So is it a good idea to create a new issue for this? Thanks
Yeah, please go ahead and submit another patch for fixing that logging bit, if you have one ready. Thanks!