Hi Andy,

>     state = mysql_query(connection, "SELECT * from mytable");
                               ******* ^^^^^^
>     if( state ) {
>         printf(mysql_error(connection));
>         return 1;
>     } else {
>         printf("Everything Cool with the query\n");
>     }

      // New code, retrieve resultset. --------
      result = mysql_store_result(connection);
      if (result) {
          printf( "Return set: columns=%d, rows=%d \n",
                  mysql_field_count(connection),
                  mysql_num_rows(result));
          mysql_free_result(__result);
      } else {
          printf("%s\n", mysql_error(connection));
          return 1;
      }
      // New code -----------------------------

>     mysql_close(connection);
>     printf("Done.\n");

    After doing a SELECT statement you should issue a "mysql_store_result" /
"mysql_use_result" operation to flush the resultset returned (even an empty
resultset). In fact, you should flush the resultset stream with every SQL
statement that returns data like SELECT, SHOW, DESCRIBE, and the like. See
the manual page on "mysql_store_result" for more information. Once in there,
you can follow the directions about section "21.2.3.20 mysql_field_count()"
about using "mysql_field_count" to check in you need to flush the resultset.
Do not forget to call "mysql_free_result" to free the memory allocated for
the returned resultset.

    Hope this helps, maybe mysql_close(...) got confused by pending data
from the server.

    One note though, you should NEVER use 'printf(whatever);' use
'printf("%s", whatever);' instead.
    If it happends to be some "%" inside "whatever" you will get coredumps.
For instance, see what happends when in your program,
mysql_error(connection) returns "Please use %d to display integers." (Not a
real MySQL error, obviously!! :-)

    Cheers,
    Jose Miguel.


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to