473,605 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help needed converting C float value to DBNUMERIC ...

Hello all,

I need to return back to TSQL two numeric values from an
Extended Stored Procedure developed in C. As result my C
dll program produces two float values, the TSQL side expects
to have exactly: numeric(10, 5) and numeric.

Given that the structure to fill-up is DBNUMERIC defined
as:

typedef struct dbnumeric // Numeric (and decimal)
{
BYTE precision; // Precision
BYTE scale; // Scale
BYTE sign; // 1 = Positive, 0 = Negative
BYTE val[MAXNUMERICLEN]; // Padded little endian value
} DBNUMERIC;

I do not have any clue how to convert the float C datatype
to DBNUMERIC, specifically how to convert the float to an
array of bytes "BYTE val[MAXNUMERICLEN]".

Thanks in advance,
Best Regards,
Giovanni

Jul 20 '05 #1
1 4379
[posted and mailed, please reply in news]

Giovanni Azua (br******@hotma il.com) writes:
I need to return back to TSQL two numeric values from an
Extended Stored Procedure developed in C. As result my C
dll program produces two float values, the TSQL side expects
to have exactly: numeric(10, 5) and numeric.

Given that the structure to fill-up is DBNUMERIC defined
as:

typedef struct dbnumeric // Numeric (and decimal)
{
BYTE precision; // Precision
BYTE scale; // Scale
BYTE sign; // 1 = Positive, 0 = Negative
BYTE val[MAXNUMERICLEN]; // Padded little endian value
} DBNUMERIC;

I do not have any clue how to convert the float C datatype
to DBNUMERIC, specifically how to convert the float to an
array of bytes "BYTE val[MAXNUMERICLEN]".


A quick glance makes me believe that srv_convert is able to do the task.
There is some documentation on how to work with DBNUMERIC.

Else you can use the IDataConvert object from OLE DB:

static IDataConvert * data_convert_pt r = NULL;

// Call this once when you DLL is loaded, and keep the object.
ret = CoCreateInstanc e(CLSID_OLEDB_C ONVERSIONLIBRAR Y,
NULL, CLSCTX_INPROC_S ERVER,
IID_IDataConver t,
(void **) &data_convert_p tr);
// Here is a sample routine. Don't bother about the SV, that's a Perl
// thing which holds the double value.
BOOL SV_to_decimal(S V * sv,
BYTE precision,
BYTE scale,
DB_NUMERIC &decimalval)
{
HRESULT ret;

double dbl = SvNV(sv);
ret = data_convert_pt r->DataConvert(
DBTYPE_R8, DBTYPE_NUMERIC, sizeof(double), NULL,
&dbl, &decimalval, NULL, DBSTATUS_S_OK, NULL,
precision, scale, 0);
return SUCCEEDED(ret);
}

Don't really remember which include files that has which, but these
are the ones that I include in my code (which access SQL Server through
SQLOLEDB, and has nothing to do with XPs):

#include <cguid.h>
#include <oledb.h>
#include <oledberr.h>
#include <msdasc.h>
#include <msdadc.h>
#include <msdaguid.h>
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3051
by: Robert P. Stearns | last post by:
I have been trying to convert the following simple table into CSS. <table> <tr><th colspan=2>Header Area</th></tr> <tr><th>Navigation Area</th><th>Information Area</th></tr> <tr><th colspan=2>Footer Area</th></tr> </table> |=========================| | Header Area |
7
8677
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and developing a mid-sized Access database (60 tables, 25 simultaneous users). Although I've been tossing up if I should try to convert the back end to SQL server (We have a license), the performance has been good enough that it always seemed a waste of time,...
5
1907
by: el prinCipante | last post by:
I'm getting tired of the following error message. Compiler Error message : Error: Need explicit cast to convert from: float to: float * I am trying to use a routine from the Numerical Recipes library called amebsa.c. The routine requires several parameters of the following form. *iter, **p, *yb.... . How does one initialize these variables? If I declare them as pointer (in this case, *yb and *iter) the compiler still tells me that it...
7
2692
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards Totto
116
35792
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused problems elsewhere in another part of the system where that figure was used for some calculation and some eventual truncation led to the system going haywire. So my question is, given this code: int main() { float f = 59.89F;
4
5542
by: mirangk | last post by:
Heyy Guys... Im very new to vb. Im using vb6 and i want to convert a 32 bit ieee 754 number into a floating point number. for example. 'BE C3 F2 DF' (in hexa representation) should be converted to -0.382712.... i have worked this c++ code over which seems to be running fine. Need to convert the code in VB. please help me guys.
4
4793
by: Yasin Cepeci | last post by:
I ve get float data from serial port. I ve taken it in the form of hex by modbus protocol. I know it is float but I couldnt convert it there is a few sample data below; B3 33 43 34 = 180.699997 33 33 43 33 = 179.199997 B3 33 43 34= 180.699997 CC CD 43 33=179.800003 But how can I found it. I couldnt resolve it.
10
3227
by: Hank Stalica | last post by:
I'm having this weird problem where my code does the following conversion from string to float: 27000000.0 -27000000.00 2973999.99 -29740000.00 2989999.13 -2989999.25 The number on the left is the string I get after tokenizing a bigger string. The number on the right is the number I get after the conversion.
2
2879
by: John Fisher | last post by:
Hi Group, troubles with converting signed 32.32, little-endian, 2's complement back to floating point. I have been trying to brew it myself. I am running Python 2.5 on a Mac. Here is the C-code I have been trying to leverage: double FPuint8ArrayToFPDouble(uint8 *buffer, int startIndex) { uint32 resultDec = 0;
0
8004
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7934
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8425
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.