MySQL :: MySQL 8.4 C API Developer Guide :: 5.4.21 mysql_fetch_lengths() (original) (raw)

The world's most popular open source database

5.4.21 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, youmust use this function to determine the size of the data, becausestrlen() returns incorrect results for any field containing null characters.

The length for empty columns and for columns containingNULL values is zero. To see how to distinguish these two cases, see the description formysql_fetch_row().

Return Values

An array of unsigned long integers representing the size of each column (not including any terminating null bytes).NULL if an error occurred.

Example

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]);
    }
}