List:General Discussion« Previous MessageNext Message »
From:Christer Holmström \(at Home\) Date:November 4 2002 2:58pm
Subject:RE: Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)
View as plain text  
The code works in that sence that I get resultsets, the only thing that
does not work is the "ORDER BY" option for the SELECT statement. The
resultset is ordered by the exe column instead.

Should I run MyODBC instead?

Is the sourcecode for mysql.exe available?

Is there any miss-usage of mysql_query, mysql_store_result etc?

/Christer



void StatisticsToday()
{
	char	szSQL[1024];
	MYSQL_RES*		res;	// Resultset
	MYSQL_ROW		row;	// Row
	int i, j;

	// Tried both below
	strcpy(szSQL, "SELECT DISTINCT exe, sum(duration) AS s FROM data
GROUP BY exe ORDER BY s DESC");
	strcpy(szSQL, "SELECT DISTINCT exe, sum(duration) FROM data
GROUP BY exe ORDER BY 2 DESC;");

	if (!mysql_query( myData, szSQL)) {
		res = mysql_store_result( myData ) ;
		i = (int) mysql_num_rows( res ) ; 
		while ( row = mysql_fetch_row( res ) ) 
		{
			j=mysql_num_fields( res );
			sprintf(szId, "%s %s", row[0], row[1]);
		}
		mysql_free_result( res ) ;
	} else {
		printf( "Couldn't execute %s on the server !\n", szSQL )
;
	}
}





-----Original Message-----
From: gerald_clark [mailto:gerald_clark@stripped] 
Sent: den 4 november 2002 15:51
To: Christer Holmström (at Home)
Cc: 'Joseph Bueno'; mysql@stripped
Subject: Re: Problems with "ORDER BY" from C API (works from
command-line tool mysql.exe)


Then I would suggest you check your C code.
The program 'mysql' uses the C API.

Christer Holmström (at Home) wrote:

>Hi, and thanks for the response, but unfortunately the same problem 
>with both below
>
>SELECT exe, sum(duration) FROM data GROUP BY exe ORDER BY 2 DESC; 
>SELECT exe, sum(duration) AS s FROM data GROUP exe BY ORDER BY s DESC;
>
>Works from mysql.exe but not from C API.
>
>/Christer
>
>-----Original Message-----
>From: Joseph Bueno [mailto:joseph.bueno@stripped]
>Sent: den 4 november 2002 11:57
>To: Christer Holmström (at Home)
>Cc: mysql@stripped
>Subject: Re: Problems with "ORDER BY" from C API (works from
>command-line tool mysql.exe)
>
>
>Christer Holmström (at Home) wrote:
>
>  
>
>>Hi!
>>
>>This SQL works perfect when running the command line tool mysql.exe
>>
>>SELECT exe, sum(duration) FROM data GROUP BY exe ORDER BY 2
>>
>>BUT when running from the C API, the "ORDER BY" part doesn't seem
>>active, why?
>>
>>Please help.
>>
>>/Christer
>>
>>
>>    
>>
>Hi,
>
>What do expect with "ORDER BY 2" ?
>If you want to arder by "sum(duration)" you should use:
>SELECT exe, sum(duration) AS s FROM data GROUP BY exe ORDER BY s
>
>Hope this helps
>  
>



Thread
Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)at Home \ )4 Nov
  • Re: Problems with "ORDER BY" from C API (works from command-linetool mysql.exe)Joseph Bueno4 Nov
    • RE: Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)at Home \ )4 Nov
      • Re: Problems with "ORDER BY" from C API (works from command-linetool mysql.exe)gerald_clark4 Nov
        • RE: Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)at Home \ )4 Nov
          • RE: Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)at Home \ )4 Nov
    • Re: Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)Benjamin Pflugmann5 Nov
    • Re: Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)Paul DuBois5 Nov
      • RE: Problems with "ORDER BY" from C API (works from command-line tool mysql.exe)at Home \ )5 Nov