Returning CDBVariant type
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Returning CDBVariant type

  1. #1
    Join Date
    Jan 2009
    Posts
    196

    Returning CDBVariant type

    I have the following method to format data type returned from SQL:
    Code:
    CString CMyDoc::FormatData(CDBVariant* pDBVariant)
    {
    	CString sRet;
    *
    	switch(pDBVariant->m_dwType)
    	{
    	case DBVT_LONG:
    		TRACE("DBVT_LONG\n");
    		sRet.Format(_T("%d"), pDBVariant->m_lVal);
    		break;
    	case DBVT_DOUBLE:
    		TRACE("DBVT_DOUBLE\n");
    		break;
    	case DBVT_SHORT:
    		TRACE("DBVT_SHORT\n");
    		break;
    	case DBVT_SINGLE:
    		TRACE("DBVT_SINGLE\n");
    		break;
    	case DBVT_STRING:
    		TRACE("DBVT_STRING\n");
    		break;
    	case DBVT_ASTRING:
    		TRACE("DBVT_ASTRING\n");
    		sRet = *pDBVariant->m_pstring;
    		break;
    	case DBVT_DATE:
    		TRACE("DBVT_DATE\n");
    		break;
    	case DBVT_WSTRING:
    		TRACE("DBVT_WSTRING\n");
    		CStringW wstring = *pDBVariant->m_pstringW;
    		sRet = CString(wstring);
    		break;
    	}
    *
    	return sRet;
    }
    I have the following SQL:
    Code:
    SELECT nUser FROM my_table
    In DB, nUser has "int" type. The result in FormatData method: DBVT_LONG

    I have another SQL:
    Code:
    SELECT sName FROM my_table
    In DB, dValue has "varchar(1024)" type. The result in FormatData method: DBVT_ASTRING - correct.

    I have another SQL:
    Code:
    SELECT dValue FROM my_table
    In DB, dValue has "decimal (10.2)" type. The result in FormatData method: DBVT_ASTRING !? Why ?

    I noticed that any king of column type in DB, except "int" type, return DBVT_ASTRING in FormatData method ... why ?

    I have tried to get data with CRecordset as dynaset, snaphot and dynamic ... every one of them had the same result ...

    Can you help me ?
    Thank you.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,995

    Re: Returning CDBVariant type

    Quote Originally Posted by mesajflaviu View Post
    ...
    I have another SQL:
    Code:
    SELECT dValue FROM my_table
    In DB, dValue has "decimal (10.2)" type. The result in FormatData method: DBVT_ASTRING !? Why ?

    I noticed that any king of column type in DB, except "int" type, return DBVT_ASTRING in FormatData method ... why ?

    I have tried to get data with CRecordset as dynaset, snaphot and dynamic ... every one of them had the same result ...
    Maybe because CDBVariant class has no such a type as "decimal"?

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,995

    Re: Returning CDBVariant type

    See also the table with C/SQL data type compatibility here.
    Victor Nijegorodov

  4. #4
    Join Date
    Jan 2009
    Posts
    196

    Re: Returning CDBVariant type

    Hi Victor. I saw from the above table, that setting up SQL_DECIMAL in my database, is returning SQL_C_CHAR in CDBVariant ... so, helped by you, I have found the source of the problem ... however, I don't know if I can change this decimal type in DB, I will see this after I talk with my SQL colleagues ...

    Kindly thank you for your answers !

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,995

    Re: Returning CDBVariant type

    Quote Originally Posted by mesajflaviu View Post
    ... however, I don't know if I can change this decimal type in DB, ...
    But why do you think you have to "change this decimal type in DB"?
    You do not need it!
    Victor Nijegorodov

  6. #6
    Join Date
    Jan 2009
    Posts
    196

    Re: Returning CDBVariant type

    No ? This is mean I don't understand the solution ...

    So, if the SQL data type are decimal SQL_DECIMAL, I retrieve SQL_C_CHAR in my CDBVariant ... I am right ?
    Last edited by mesajflaviu; October 29th, 2017 at 02:31 AM.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,995

    Re: Returning CDBVariant type

    Quote Originally Posted by mesajflaviu View Post
    So, if the SL data type are decimal SQL_DECIMAL, I retrieve SQL_C_CHAR in my CDBVariant ... I am right ?
    Yes!
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)