-
October 25th, 2017, 09:49 AM
#1
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.
-
October 25th, 2017, 04:55 PM
#2
Re: Returning CDBVariant type
 Originally Posted by mesajflaviu
...
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"?
-
October 26th, 2017, 05:08 AM
#3
Re: Returning CDBVariant type
See also the table with C/SQL data type compatibility here.
Victor Nijegorodov
-
October 27th, 2017, 01:38 AM
#4
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 !
-
October 27th, 2017, 03:15 AM
#5
Re: Returning CDBVariant type
 Originally Posted by mesajflaviu
... 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
-
October 27th, 2017, 08:04 AM
#6
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 01:31 AM.
-
October 27th, 2017, 01:36 PM
#7
Re: Returning CDBVariant type
 Originally Posted by mesajflaviu
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|