Rechercher dans le manuel MySQL
28. 7. 7. 20 mysql _fetch _lengths ()
unsigned long *mysql_fetch_lengths(MYSQL_RES
*result)
Description
Returns the lengths of the columns of the current row within a
result set. If you plan to copy field values, this length
information is also useful for optimization, because you can
avoid calling strlen()
. In addition, if the
result set contains binary data, you
must use this function to
determine the size of the data, because
strlen()
returns incorrect results for any
field containing null characters.
The length for empty columns and for columns containing
NULL
values is zero. To see how to
distinguish these two cases, see the description for
mysql_fetch_row()
.
An array of unsigned long integers representing the size of
each column (not including any terminating null bytes).
NULL
if an error occurred.
mysql_fetch_lengths()
is valid
only for the current row of the result set. It returns
NULL
if you call it before calling
mysql_fetch_row()
or after
retrieving all rows in the result.
MYSQL_ROW row;
unsigned long *lengths;
unsigned int num_fields;
unsigned int i;
row = mysql_fetch_row(result);
if (row)
{
num_fields = mysql_num_fields(result);
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
{
printf("Column %u is %lu bytes in length.\n",
i, lengths[i]);
}
}
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-mysql-fetch-lengths.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.