MYSQL_ROW and zero terminated strings
Posted by: Jean-Philippe Léveillé
Date: November 15, 2005 04:52PM

I hope no other thread is related to the following "issue" I think I encountered. I'm trying to figure out how to deal with rows returned by mysql_fetch_row(). I'm using MySQL 4.1 (planning to move to 5.0 ASAP) and I recently noticed how "fuzzy" the documentation was. It tells that if a field may contain binary content, you cannot use strlen() to determine the length of its content, which makes sense because it may contain byte 0x0 somewhere else than at the end of the said content. Problem is: what are the fields that return content fetch as binary content?

I'm fetching information from an int field (unsigned) and when I convert fetched content of the field (from char *) to unsigned int, I sometime get the wrong result (to not say "often"). I thought that fetched content from a field of type int would strictly be in a zero terminated string because it would only contain bytes representing characters 0 to 9 (and '-' in case of a signed field). I might be doing something wrong, but does MYSQL_ROW contains 0x0 at the end of values for fields of type "int" making strlen() working well on them or does this rule only apply on varchar, char, text and other "text" fields?

The documentation isn't clear about it, as I said, it only tells that mysql_fetch_lengths() is useful for binary fields. Am I wrong or fetched content from field of type int (and float and decimal) "should not" be considered binary?

Options: ReplyQuote


Subject
Views
Written By
Posted
MYSQL_ROW and zero terminated strings
903
November 15, 2005 04:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.