Marc Abramowitz
2013-07-26 15:03:03 UTC
I have some code that calls dbrpcparam [1] 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[0] = 38
data[1] = 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 [2], 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:
DBDECIMAL db_decimal
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?
Thanks,
Marc
[1] http://freetds.schemamania.org/reference/a00285.html#ga8
[2] http://lists.ibiblio.org/pipermail/freetds/2009q3/025076.html
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[0] = 38
data[1] = 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 [2], 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:
DBDECIMAL db_decimal
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?
Thanks,
Marc
[1] http://freetds.schemamania.org/reference/a00285.html#ga8
[2] http://lists.ibiblio.org/pipermail/freetds/2009q3/025076.html