[freetds] dbrpcparam with SQLDECIMAL output parameter
marca at surveymonkey.com
Fri Jul 26 11:03:03 EDT 2013
I have some code that calls dbrpcparam  with type = SQLDECIMAL and DBRPCRETURN. It is attempting to get back a DECIMAL(6, 5) from a stored proc.
What I am seeing is that the data returned has a scale of 0 — i.e.: the value I get back looks like this:
data = 38
data = 0
So it appears that I'm getting a DECIMAL(38, 0) and thus losing everything after the decimal point.
I found an old message on the list about this , which suggested that one should send a DBDECIMAL structure with the desired precision and scale (code was added by Freddy for this at that time). I tried that and thus far have still not gotten it to send back the expected value. I am wondering if I have something wrong still — I am unclear on what I should be sending for maxlen and datalen for instance. I've tried a number of combinations of 0, -1, and sizeof(DBDECIMAL) and so far they all have returned the same DECIMAL(38, 0) or I have gotten back an error about using an invalid length.
Currently, I have something like this:
db_decimal.precision = 18
db_decimal.scale = 5
dbrpcparam(dbproc, "@odecimal", DBRPCRETURN, SQLDECIMAL, sizeof(DBDECIMAL), 0, (BYTE *) &db_decimal) // SQLDECIMAL = 106; sizeof(DBDECIMAL) = 35
Am I doing this wrong? Anyone have a working example of returning a SQLDECIMAL?
More information about the FreeTDS