Bug #28735 | fetch_result_str bug | ||
---|---|---|---|
Submitted: | 29 May 2007 6:58 | Modified: | 26 Jun 2009 15:10 |
Reporter: | David Anderson | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: C API (client library) | Severity: | S3 (Non-critical) |
Version: | 5.0.41 | OS: | Any |
Assigned to: | [ name withheld ] | CPU Architecture: | Any |
Tags: | documentation, prepared statement |
[29 May 2007 6:58]
David Anderson
[29 May 2007 6:59]
David Anderson
Sample code to reproduce problem
Attachment: mysql_bug_report.c (text/plain), 1.16 KiB.
[29 May 2007 7:49]
David Anderson
After writing some code to work around this in my application, I think the suggestion for MySQL to add 1 to the length output for the user is bad and would be inconsistent with common convention -- please disregard it.
[15 Jun 2007 11:39]
Valeriy Kravchuk
Thank you for a problem report. So, from your point of view, is this a bug that should be somehow fixed, or just a request for documenting properly?
[15 Jun 2007 15:14]
David Anderson
It is a bug in both cases; the fix depends on the expected behaviour, which is what I couldn't find in the documentation. I think this should be changed: *param->error= copy_length < length; To be <= instead, and the documentation should say that the null terminator isn't included in the outputted size. Thanks :)
[26 Jun 2009 15:10]
Valeriy Kravchuk
Sorry for a delay with this bug report. While anybody can repeat your findings on any version of MySQL, our documentation (http://dev.mysql.com/doc/refman/5.1/en/c-api-prepared-statement-datatypes.html, for example) clearly says that NULL terminator is not included: "For output value binding, the return value of mysql_stmt_fetch() determines the interpretation of the length: * If mysql_stmt_fetch() returns 0, *length indicates the actual length of the parameter value." So, application programmer that expects null terminator at the end of the string should just allocate buffer one byte longer. To summarize, current behavior (including error code 0 in case like yours) is expected by zillion of programs and should not be changed. There is also no big need to document anything additionally, IMHO.
[10 Feb 2015 8:05]
Greg Hazel
On the contrary, I just bumped my head on this issue as well, and could not find adequate documentation. C strings which are not NULL terminated are quite surprising. If the application needs to do something special (add 1? add 1 and NULL terminate after reading?) it would be very helpful to document that specifically.