<This looks like it was generated using mysqlbug, but actually I took
another post and pasted in the values.>

>Description:
The mysql_fetch_field() function returns a MYSQL_FIELD structure with
the flags field set to a value including NOT_NULL_FLAG even if the field
is an aggregate, if that aggregate is on the primary key.

If there are no rows in the table, then MAX(pri_key_column) will return
NULL.  However, the MYSQL_FIELD structure will indicate that the
MAX(pri_key_column) field does not allow NULL.

If the column is not a primary key, but is NOT NULL, then the
MYSQL_FIELD flags will correctly indicate that the aggregate can allow
NULL.

>How-To-Repeat:
In MySQL: CREATE TABLE foo (bar int PRIMARY KEY);

In C:
  MYSQL *cnn = mysql_init(NULL);
  mysql_real_connect(cnn, NULL, NULL, NULL, "test", 0, NULL, 0);

  const char* select_query = "SELECT MAX(bar) FROM foo";
  mysql_query(cnn, select_query);
  MYSQL_RES* res = mysql_store_result(cnn);

  MYSQL_FIELD* fld = mysql_fetch_field(res);
  char* name = strdup(fld->name);
  bool isNotNull = ((fld->flags & NOT_NULL_FLAG) > 0);
  printf("column `%s`: notnull=%d\n", name, isNotNull);

  MYSQL_ROW row = mysql_fetch_row(res);
  printf("value: %s", row[0] ? row[0] : "NULL");

  mysql_close(cnn);


>Fix:

None.

>Originator:    Matt Solnit
>Organization: Iteration Software, Inc. http://www.iteration.com
>Release:   mysql-4.0.9-gamma (Binary distribution) 
>Environment:
    
System: Windows XP Professional
Architecture: Pentium IV

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to