By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,225 Members | 1,051 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,225 IT Pros & Developers. It's quick & easy.

access varchar error

P: n/a
In my application,I use SQLBindCol to retrive the information, however
I found that in one table there is a varchar(10) column,
if the buffer size specified in the SQLBindCol is also ten,and the
buffer is ten length, then the result will be turned into 9.If the
buffer size specified as 11, then the result will be ok.
Does anyone explane for this?

Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ja**********@yahoo.com.cn wrote:
In my application,I use SQLBindCol to retrive the information, however
I found that in one table there is a varchar(10) column,
if the buffer size specified in the SQLBindCol is also ten,and the
buffer is ten length, then the result will be turned into 9.If the
buffer size specified as 11, then the result will be ok.
Does anyone explane for this?


The issue lies in the handling of strings in the C programming language. A
string is terminated by a trailing '\0' (= 0x00) byte to denote the end.
If you provide a buffer of 10 bytes, then only 9 bytes are available for
the actual data and the last byte is needed for the termination character.
That's a standard C/C++ thing, which needs to be solved by using buffers
that have (at least) one more byte than is needed for the real data.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Nov 12 '05 #2

P: n/a

Knut Stolze wrote:
The issue lies in the handling of strings in the C programming language. A
string is terminated by a trailing '\0' (= 0x00) byte to denote the end.
If you provide a buffer of 10 bytes, then only 9 bytes are available for
the actual data and the last byte is needed for the termination character.
That's a standard C/C++ thing, which needs to be solved by using buffers
that have (at least) one more byte than is needed for the real data.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany


sorry,I don't think so.In fact I have considered that.In my
application,I allocate 11 bypes but I specify the length as 10 in the
function then the problem happen. And for the oracle, almost the same
function works well.
Does this mean I have to specify the parameter one more than the length
in the database?

Nov 12 '05 #3

P: n/a
jacky shi wrote:

Knut Stolze wrote:
The issue lies in the handling of strings in the C programming language.
A string is terminated by a trailing '\0' (= 0x00) byte to denote the
end. If you provide a buffer of 10 bytes, then only 9 bytes are available
for the actual data and the last byte is needed for the termination
character. That's a standard C/C++ thing, which needs to be solved by
using buffers that have (at least) one more byte than is needed for the
real data.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
sorry,I don't think so.In fact I have considered that.In my
application,I allocate 11 bypes but I specify the length as 10 in the
function then the problem happen.


How should DB2 know how much space you allocated unless you tell it so? You
say that there are 10 bytes, so DB2 has 9 bytes for data and 1 byte for the
termination character.
And for the oracle, almost the same
function works well.
Does this mean I have to specify the parameter one more than the length
in the database?


Yes, the documentation for SQLBindCol() says so:

Note that for character data, the driver _counts_ the NULL termination
character and so space must be allocated for it.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Nov 12 '05 #4

P: n/a
Thank you very much. I have read the document of the api, however,
there isn't any thing refering that. Would you please tell me which
documentation you refered?

Nov 12 '05 #5

P: n/a
jacky shi wrote:
Thank you very much. I have read the document of the api, however,
there isn't any thing refering that. Would you please tell me which
documentation you refered?


Did you try searchable online documentation available at:

http://publib.boulder.ibm.com/infoce...help/index.jsp

Specifically, for SQLBindCol() call you will find:

"Note that for character data, the driver counts the NULL termination character
and so space must be allocated for it."
Jan M. Nelken
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.