Re: Specify decimal scale/precision for output parameter

Frediano Ziglio <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
2009/8/27 Damien Churchill <[email protected]>:
> 2009/8/27 Frediano Ziglio <[email protected]>:
>> 2009/8/27 Damien Churchill <[email protected]>:
>>> 2009/8/27 Frediano Ziglio <[email protected]>:
>>>> 2009/8/27 Damien Churchill <[email protected]>:
>>>>> I was wondering how you would specify the scale/precision for an
>>>>> output parameter of a RPC call that is null to begin with, since if
>>>>> you don't currently it just uses decimal(38,0) which looses everything
>>>>> trailing the decimal point.
>>>>>
>>>>> Any one know how??
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Damien
>>>>
>>>> Using which library ??
>>>>
>>>
>>> Using db-lib and the dbrpcparam etc functions.
>>
>> In theory you should pass in value a DBDECIMAL initialized with
>> precision/scale even for NULLs. Currently I think this does not works
>> that fine (although I have a small patch).
>>
>
> Is there any chance I would be able to test/experiment with this patch?

Here you are.

freddy77

_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
numeric_scale_prec.diff (application/octet-stream, 1020 B)
Index: freetds83/src/dblib/rpc.c
===================================================================
--- freetds83.orig/src/dblib/rpc.c	2009-08-31 14:05:04.452550659 +0200
+++ freetds83/src/dblib/rpc.c	2009-08-31 14:05:04.652587182 +0200
@@ -398,6 +398,15 @@
 
 		tdsdump_log(TDS_DBG_INFO1, "parm_info_alloc(): parameter null-ness = %d\n", param_is_null);
 
+		pcol = params->columns[i];
+
+		if (temp_value && is_numeric_type(temp_type)) {
+			DBDECIMAL *dec = (DBDECIMAL*) temp_value;
+			pcol->column_prec = dec->precision;
+			pcol->column_scale = dec->scale;
+			if (dec->precision > 0 && dec->precision <= MAXPRECISION)
+				temp_datalen = tds_numeric_bytes_per_prec[dec->precision] + 2;
+		}
 		if (param_is_null || (p->status & DBRPCRETURN)) {
 			if (param_is_null) {
 				temp_datalen = 0;
@@ -410,8 +419,6 @@
 			temp_datalen = tds_get_size_by_type(temp_type);
 		}
 
-		pcol = params->columns[i];
-
 		/* meta data */
 		if (p->name) {
 			tds_strlcpy(pcol->column_name, p->name, sizeof(pcol->column_name));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.