Example not working/incorrect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan

    #1

    Example not working/incorrect

    I am trying to determine the field names using the C API using the
    example from mysql manual
    (http://dev.mysql.com/doc/mysql/en/my...-fields.html):

    MYSQL_FIELD *mysql_fetch_fi elds(MYSQL_RES *result)

    Description

    Returns an array of all MYSQL_FIELD structures for a result set. Each
    structure provides the field definition for one column of the result set.

    Return Values

    An array of MYSQL_FIELD structures for all columns of a result set.

    Errors

    None.

    Example

    unsigned int num_fields;
    unsigned int i;
    MYSQL_FIELD *fields;

    num_fields = mysql_num_field s(result);
    fields = mysql_fetch_fie lds(result);
    for(i = 0; i < num_fields; i++)
    {
    printf("Field %u is %s\n", i, fields[i].name);
    }

    The manual says that the function returns an array. I ran a query which
    returns data in six columns so to my opinion the valid indexes should be
    0 upto and including 5. The definition of the variables does not
    indicate an array being declared for fields to my opinion. It seems to
    ve more like a field definition to me.

    The first time I run thel loop (i=0) everything works perfectly, but
    when I run the loop for the second time (i=1) the system crashes with an
    access violation.

    I added a watch to see whether the result was really an array and it
    does *not* seem to be an array. Can someone tell me if I do something
    wrong or if there could be a bug in the C API functions.

    System:
    Microsoft Visual C++ 6
    Mysql 4.1.11-nt

    Thanks in advance!

    Jonathan

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
  • Jonathan

    #2
    Re: Example not working/incorrect

    Jonathan wrote:[color=blue]
    > I am trying to determine the field names using the C API using the
    > example from mysql manual
    > (http://dev.mysql.com/doc/mysql/en/my...-fields.html):
    >
    > MYSQL_FIELD *mysql_fetch_fi elds(MYSQL_RES *result)
    >
    > Description
    >
    > Returns an array of all MYSQL_FIELD structures for a result set. Each
    > structure provides the field definition for one column of the result set.
    >
    > Return Values
    >
    > An array of MYSQL_FIELD structures for all columns of a result set.
    >
    > Errors
    >
    > None.
    >
    > Example
    >
    > unsigned int num_fields;
    > unsigned int i;
    > MYSQL_FIELD *fields;
    >
    > num_fields = mysql_num_field s(result);
    > fields = mysql_fetch_fie lds(result);
    > for(i = 0; i < num_fields; i++)
    > {
    > printf("Field %u is %s\n", i, fields[i].name);
    > }
    >
    > The manual says that the function returns an array. I ran a query which
    > returns data in six columns so to my opinion the valid indexes should be
    > 0 upto and including 5. The definition of the variables does not
    > indicate an array being declared for fields to my opinion. It seems to
    > ve more like a field definition to me.
    >
    > The first time I run thel loop (i=0) everything works perfectly, but
    > when I run the loop for the second time (i=1) the system crashes with an
    > access violation.
    >
    > I added a watch to see whether the result was really an array and it
    > does *not* seem to be an array. Can someone tell me if I do something
    > wrong or if there could be a bug in the C API functions.
    >
    > System:
    > Microsoft Visual C++ 6
    > Mysql 4.1.11-nt
    >
    > Thanks in advance!
    >
    > Jonathan
    >[/color]

    I resolved the problem with the use of the MYSQL support team!

    It turnde out to be the program using an older version of the
    libmysql.dll in the windows\system3 2 directory instead of the linked
    library I explicitly specified.

    Jonathan

    http://bugs.mysql.com/bug.php?id=10645

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?

    Comment

    Working...