Search code examples
c++11sql-server-2012oledb

Write NAN (from C++ code) to sql server 2012


I have a float, null parameter in a DB table.
From my C++11 application, I want to write nan value to DB table as NULL.

I am doing following:
1. Converting nan to L"NULL" and store in CComBSTR
2. In DB, converting this string back to NULL and write this against float column.

My question: any better way of writing nan to DB in this case?
Specifically I want to avoid this CComBstr conversion as frequency of updates are quiet high and using many float parameters in table.


Solution

  • I got another solution which looks better than this, so thought to share this:
    There are multiple macros used for reading/writing data from DB like COLUMN_ENTRY_STATUS, COLUMN_ENTRY_TYPE_STATUS etc...

    These takes status flag for each DB field.
    -While writing, if value is NAN, set status flag to DBSTATUS_S_ISNULL, DB itself will set float field value to NULL.
    -While reading if status flag is DBSTATUS_S_ISNULL set value to NAN.