problem with GetFieldValue and SQL_LONGVARCHAR 
Author Message
 problem with GetFieldValue and SQL_LONGVARCHAR

If I use CRecordSet::GetFieldValue to retrieve data from a field of type
SQL_LONGVARCHAR, I only get the first character of the data in the
field.  I am calling GetFieldData like this:

CDBVariant vData;
GetFieldValue(_T("field_name"), vData);

Stepping through the code in DBCORE.CPP, I step into
CRecordset::GetTextLen where the following code gets executed:

if (nSQLType == SQL_LONGVARCHAR || nSQLType == SQL_LONGVARBINARY)
{
  // Use a dummy length of 1 (will just get NULL terminator)
  nLen = 1;

Quote:
}

This would seem to be the cause of my problem as nLen is passed back to
be used in SQLGetData as the cbValueMax parameter.  Why is this code
doing what it's doing?  Is GetFieldValue simply not able to handle data
of type SQL_LONGVARCHAR?

Using RFX_Text as generated by the ClassWizard seems to work, but I need
to do dynamic column binding and I'm not sure how to do that with
RFX_Text, if it can even be done.

I am using MFC from VC++5.0 with the Visual Studio SP3 installed.

Regards,
Csaba Kormendy



Mon, 18 Sep 2000 03:00:00 GMT  
 problem with GetFieldValue and SQL_LONGVARCHAR

have a look at this KB article
BUG: GetFieldValue Returns Empty String for SQL_LONGVARCHAR
Article ID: Q157071
http://support.microsoft.com/support/kb/articles/q157/0/71.asp

--
-------------------------------------------------------
Rajesh Parikh
Microsoft Certified Solution Developer

-------------------------------------------------------

Quote:

>If I use CRecordSet::GetFieldValue to retrieve data from a field of type
>SQL_LONGVARCHAR, I only get the first character of the data in the
>field.  I am calling GetFieldData like this:

>CDBVariant vData;
>GetFieldValue(_T("field_name"), vData);

>Stepping through the code in DBCORE.CPP, I step into
>CRecordset::GetTextLen where the following code gets executed:

>if (nSQLType == SQL_LONGVARCHAR || nSQLType == SQL_LONGVARBINARY)
>{
>  // Use a dummy length of 1 (will just get NULL terminator)
>  nLen = 1;
>}

>This would seem to be the cause of my problem as nLen is passed back to
>be used in SQLGetData as the cbValueMax parameter.  Why is this code
>doing what it's doing?  Is GetFieldValue simply not able to handle data
>of type SQL_LONGVARCHAR?

>Using RFX_Text as generated by the ClassWizard seems to work, but I need
>to do dynamic column binding and I'm not sure how to do that with
>RFX_Text, if it can even be done.

>I am using MFC from VC++5.0 with the Visual Studio SP3 installed.

>Regards,
>Csaba Kormendy




Fri, 22 Sep 2000 03:00:00 GMT  
 problem with GetFieldValue and SQL_LONGVARCHAR

I should have mentioned that I had read that article before posting to
the newsgroup.  I too thought that it might have something to do with my
problem.  However, the version of MFC that I am using (from VC++5.0 with
the Visual Studio SP3 installed) seems to have the bugfix discussed in
the KB article applied to it.

The program does actually end up evaluating

  if (nLen <= nActualSize &&
     (nSQLType == SQL_LONGVARCHAR || nSQLType == SQL_LONGVARBINARY))

as TRUE because nLen=1, nActualSize=1, nSQLType=SQL_LONGVARCHAR.  It's
the code that immediately follows that ends up not working because (I
think) nLen is set incorrectly (In CRecordSet::GetTextLen nLen gets set
to 1 simply because the SQL type of the column that we are working with
is of type SQL_LONGVARCHAR.  It would seem more reasonable that it
should get set to the maximum precision of the column.):

  // Reallocate the size (this will copy the data)
  *ppvData = strValue.GetBufferSetLength(nActualSize + 1);

  // Get pointer, skipping over original data, but not the NULL
  int nOldLen = nLen - 1;
  *ppvData = (BYTE*)*ppvData + nOldLen;
  nLen = nActualSize + 1 - nOldLen;

  // Retrieve the column in question
  AFX_ODBC_CALL(::SQLGetData(hstmt, nFieldIndex,
                SQL_C_CHAR, *ppvData, nLen, &nActualSize));
  if (nRetCode == SQL_SUCCESS_WITH_INFO)
  {

nLen is being passed as the cbValueMax parameter of SQLGetData, which is
the maximum number of characters SQLData is supposed to return in
ppvData.  As a result, nRetCode gets set to SQL_SUCCESS_WITH_INFO (with
a message of "Warning: ODBC Success With Info on field 7.  Data
truncated column 8.").

I can fix this by creating my own subclass of CRecordSet that deals with
the problem, but am I supposed to?  Is this perhaps another bug in
CRecordset?

Csaba

Quote:

> have a look at this KB article
> BUG: GetFieldValue Returns Empty String for SQL_LONGVARCHAR
> Article ID: Q157071
> http://support.microsoft.com/support/kb/articles/q157/0/71.asp

> --
> -------------------------------------------------------
> Rajesh Parikh
> Microsoft Certified Solution Developer

> -------------------------------------------------------


> >If I use CRecordSet::GetFieldValue to retrieve data from a field of type
> >SQL_LONGVARCHAR, I only get the first character of the data in the
> >field.  I am calling GetFieldData like this:

> >CDBVariant vData;
> >GetFieldValue(_T("field_name"), vData);

> >Stepping through the code in DBCORE.CPP, I step into
> >CRecordset::GetTextLen where the following code gets executed:

> >if (nSQLType == SQL_LONGVARCHAR || nSQLType == SQL_LONGVARBINARY)
> >{
> >  // Use a dummy length of 1 (will just get NULL terminator)
> >  nLen = 1;
> >}

> >This would seem to be the cause of my problem as nLen is passed back to
> >be used in SQLGetData as the cbValueMax parameter.  Why is this code
> >doing what it's doing?  Is GetFieldValue simply not able to handle data
> >of type SQL_LONGVARCHAR?

> >Using RFX_Text as generated by the ClassWizard seems to work, but I need
> >to do dynamic column binding and I'm not sure how to do that with
> >RFX_Text, if it can even be done.

> >I am using MFC from VC++5.0 with the Visual Studio SP3 installed.

> >Regards,
> >Csaba Kormendy




Fri, 22 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. problem with GetFieldValue and SQL_LONGVARCHAR

2. CRecordset::GetFieldValue() incorrectly returns an empty string for SQL_LONGVARCHAR

3. Why CRecordset::GetFieldValue() incorrectly returns an empty string for SQL_LONGVARCHAR?

4. GetFieldValue problems with CRecordset

5. GetFieldValue problems with CRecordset

6. GetFieldValue error problem

7. Problem with recordset.GetfieldValue() method

8. GetFieldValue problem

9. Problems with CRecordset::GetFieldValue() on migrating Oracle 7.3 to 8

10. GetFieldValue problems with CRecordset

11. Reading/Writing SQL_LONGVARCHAR Types

12. CRecordset access of SQL_LONGVARCHAR types

 

 
Powered by phpBB® Forum Software