Have encountered an strange behaviour in Poco.
I am connecting to MSSQL and running a simple stored procedure.
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[sp_UpdatePrice]
@PID INT,
@Ask float,
@Bid float,
@Currency NVARCHAR(50),
@TradeDate char(12)
AS
BEGIN
IF EXISTS (SELECT 1 FROM Price WHERE PID = @PID)
BEGIN
UPDATE Price
SET Ask = @Ask,
Bid = @Bid,
Currency = @Currency,
TradeDate = @TradeDate
WHERE PID = @PID;
END
ELSE
BEGIN
INSERT INTO Price (PID, Ask, Bid, Currency, TradeDate)
VALUES (@PID, @Ask, @Bid, @Currency, @TradeDate);
END
END
GO
GRANT EXECUTE ON [dbo].[sp_UpdatePrice] TO [public] AS [dbo]
GO
But I am receiving the following error
SQLSTATE = 42000
Native Error Code = 2628
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]String or binary data would be truncated in table 'msdb.dbo.Price', column 'TradeDate'. Truncated value: '2'.
Code:
struct price
{
std::string id;
std::string currency;
float ask
float bid;
std::string trade_date;
};
ODBC::Connector::registerConnector();
Session session("ODBC", "...");
Statement statement(session);
// create dummy price
price price{...};
// Bind parameters to the statement
statement << "{call sp_UpdatePrice(?,?,?,?,?) }",
use(price.trade_date()), ...; // Other parameters
// Execute the stored procedure
statement.execute();
// Unregister the ODBC connector
ODBC::Connector::unregisterConnector();
I have a simple price struct, the data comes from the wire. The date is a string in this format "21 MAR 2024".
As a note, this is legacy application being migrated. Unless I really have to update stored procedures, I would prefer not to. Or perhaps not use Poco if its not the best tool for the job.
At this point I want to re-use what is, and be able to add Poco to improve on the code base.