Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error truncating string data

0 views
Skip to first unread message

Matt

unread,
Jan 17, 2000, 3:00:00 AM1/17/00
to
Hello,


I am having a problem with the ATL Consumer Template classes when I
attempt to retrieve string data from the database.

Here it is...

I create the table and set one column to a length of 2, then fill it with
data. All of this i done with scripts.(SQL Server or Oracle)

Next, I attempt to bind a string variable and call CCommand::Open. Even
though I specifiy a max width of 2 when binding, I only get one character
back. if I give it a max length of 10, then I only get 9 back, etc...

I have played around with it and have found that the templates seem to only
retrieve X - 1 characters, instead of X. Anyone see this before? Maybe it
assumes a "end-of-string" marker as that last char? I have looked through
the MSDN support site, but can't seem to find any mention of this type of
bug.

-Matt

Bob Beauchemin

unread,
Jan 17, 2000, 3:00:00 AM1/17/00
to
Hi Matt,
If you are using a string data type (like DBTYPE_STR) then your buffer
must include the trailing null character. This character does not get
written to the data store. If you do not include the trailing null character
(for example read a field defined as VARCHAR(100) that contains 100 bytes of
data into a 40 byte buffer using DBTYPE_STR) you will get 39 bytes of data,
a trailing null and a status (in the status portion if you bind it) of
DBSTATUS_S_TRUNCATED. The length portion (if you bind it) will contain the
actual length of the field (ie 100). Same occurs with reading a 40 bytes of
data into a 40 byte buffer. You get 39 bytes, trailing null, status of
truncated and length of 40.
Hope this helps,

Bob Beauchemin
bo...@develop.com


Matt <mh...@one.net> wrote in message news:OvoF9XQY$GA.202@cppssbbsa05...

Matt

unread,
Jan 17, 2000, 3:00:00 AM1/17/00
to
hello,
yes, I am using DBTYPE_STR.

the buffer that I bind is allocated by new char[MaxLength + 1] for that
reason.

However, it looks like the providers just assume that you have not done
that. They always return MaxLength - 1 characters.

-Matt

Bob Beauchemin

unread,
Jan 17, 2000, 3:00:00 AM1/17/00
to
Which accessor type are you using? With CAccessor<CUserClass> or
CDynamicAccessor it should work correctly. MaxLength should be the length
of your buffer (including the trailing null), not the length of the field.
If you are retrieving ulColumnSize from IColumnsInfo::GetColumnInfo,
cbMaxLength and your buffer size should be ulColumnSize + 1. If you are
still having problems, a code snippet might help

Bob Beauchemin
bo...@develop.com


Matt <mh...@one.net> wrote in message

news:#tudfOUY$GA....@cppssbbsa02.microsoft.com...

Matt

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to
I am using a CManualAccessor and retrieving my column lengths from
CColumns.m_nMaxLength.

and I allocate length+1 for binding.

The length that I get from CColumns is the correct max length. And if I bind
length+1 as the MaxLength in AddBindEntry(), then it works fine with no
other changes.

it seems to me that the problem is the with the ATL classes assuming that
the bound MaxLength is the real MaxLength + 1. So they truncate the data.


-matt

Bob Beauchemin

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to
I don't see any CColumns variable in atldbcli.h, but if you are getting
your column length from IColumnsInfo::GetColumnInfo, that is the actual
length of the column. You must add one to bind it as a string in
CManualAccessor::AddBindEntry. So, if my CCommand object is called cmd,
then.

cmd.GetColumnInfo(&ulColumns, &pColumnInfo, &pStrings);
// lines omitted
cmd.AddBindEntry(0, DBTYPE_STR, pColumnInfo->ulColumnSize +1.....)

The fact that atldbcli.h refers to the 3rd parameter of AddBindEntry as
"column size" is misleading, as it just feeds that value into the accessor
as maxLength.

Bob Beauchemin
bo...@develop.com


Matt <mh...@one.net> wrote in message news:eJvsVJeY$GA.260@cppssbbsa04...

Matt

unread,
Jan 20, 2000, 3:00:00 AM1/20/00
to
I see....


CColumns is a class that allows access to column info. I found it in the
MDSN help. As for the column length, I understand what you are saying now.
Now I understand why I was having problems.

Thanks for the info!

-Matt

0 new messages