List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:September 1 1999 8:35pm
Subject:Re: mysql_num_fields() vs empty results from mysql_store_result().
View as plain text  
>>>>> "Scott" == Scott Hess <scott@stripped> writes:

Scott> Michael Widenius <monty@stripped> wrote:
>> >>>>> "Scott" == Scott Hess <scott@stripped> writes:
Scott> Manual section 20.4.50 Why is it that after mysql_query() returns
Scott> success,
Scott> mysql_store_result() sometimes returns NULL?' states:
Scott> <snip>
Scott> I'm unable to reconcile this with the API functions.  Since
Scott> mysql_num_fields() accepts a MYSQL_RES parameter, if
Scott> mysql_store_result()
Scott> returns a NULL MYSQL_RES, then what value would you pass to
Scott> mysql_num_fields() in order to get the zero return?
>> 
>> The mysql_num_fields(MYSQL_RES *) should be mysql_field_count(MYSQL *)
>> 
>> In MySQL 3.22 mysql_num_fields is a macro that will work both for the
>> MYSQL and MYSQL_RES structure.

Scott> So, just to verify how things work... I have a function which can accept
Scott> queries and submit them.  The queries can be select's, inserts, deletes,
Scott> etc, etc.  It contains code like:

Scott>             if( !mysql_real_query( conn, query, queryLength)) {
Scott>                 res=mysql_store_result( conn);
Scott>                 if( res || mysql_errno( conn)==0) {
Scott>                     return res;
Scott>                 }
Scott>             }

Scott> Would this work the same?:

Scott>             if( !mysql_real_query( conn, query, queryLength)) {
Scott>                 res=mysql_store_result( conn);
Scott>                 if( res || mysql_num_fields( conn)==0) {
Scott>                     return res;
Scott>                 }
Scott>             }

Scott> [Not that it makes a big difference, I'd just like to know,]
Scott> scott

Hi!

No.  The second version would not notice errors

This would probably be better:

if( !mysql_real_query( conn, query, queryLength)) {
  res=mysql_store_result( conn);
  if (res || (mysql_errno(conn) == 0 && mysql_field_count(conn) == 0))
   return res;			/* returns null pointer for commands */
}
print_error(mysql_error(conn))


The reason for this is that mysql_field_count() is 0 if you get an error.

Regards,
Monty
Thread
perl DBI syntex.Mike31 Aug
  • perl DBI syntex.Jani Tolonen31 Aug
RE: perl DBI syntex.Darren L Sweeney31 Aug
  • Re: perl DBI syntex.Mike31 Aug
    • Re: perl DBI syntex.Bill Gerrard31 Aug
      • mysql_num_fields() vs empty results from mysql_store_result().Scott Hess1 Sep
        • Re: mysql_num_fields() vs empty results from mysql_store_result().Martin Ramsch1 Sep
        • mysql_num_fields() vs empty results from mysql_store_result().sinisa1 Sep
        • mysql_num_fields() vs empty results from mysql_store_result().Michael Widenius1 Sep
      • Re: mysql_num_fields() vs empty results from mysql_store_result().Scott Hess1 Sep
        • Re: mysql_num_fields() vs empty results from mysql_store_result().Michael Widenius2 Sep
      • Re: mysql_num_fields() vs empty results from mysql_store_result().Scott Hess2 Sep
        • Re: mysql_num_fields() vs empty results from mysql_store_result().Michael Widenius2 Sep
RE: perl DBI syntex.Darren L Sweeney31 Aug