10 messages in com.mysql.lists.mysqlRe: c program Bus Error (core dumped)| From | Sent On | Attachments |
|---|---|---|
| Andy Ford | 11 Jan 2005 05:05 | |
| Andy Ford | 11 Jan 2005 05:13 | |
| Jose Miguel Pérez | 11 Jan 2005 05:57 | |
| Andy Ford | 11 Jan 2005 06:18 | |
| Andy Ford | 11 Jan 2005 07:29 | |
| Jose Miguel Pérez | 11 Jan 2005 07:52 | |
| Andy Ford | 11 Jan 2005 08:10 | |
| Andy Ford | 11 Jan 2005 08:25 | |
| Jose Miguel Pérez | 11 Jan 2005 08:46 | |
| Andy Ford | 11 Jan 2005 09:32 |
| Subject: | Re: c program Bus Error (core dumped)![]() |
|---|---|
| From: | Andy Ford (andy...@telindus.co.uk) |
| Date: | 01/11/2005 06:18:54 AM |
| List: | com.mysql.lists.mysql |
Thanks Jose ...
but I still get the Bus Error message with the following code...
int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; int PORTNUM = 3306;
mysql_init(&mysql); connection = mysql_real_connect(&mysql, "localhost", "root", "0sg0sb4Ig", "oui", PORTNUM, NULL, 0);
if( connection == NULL ) { printf("%s\n",mysql_error(&mysql)); return 1; } else { printf("%s\n","Everything Cool with the connection"); } state = mysql_query(connection, "SELECT sysName from inv_device"); 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; } mysql_close(connection); printf("%s\n","Done."); }
Regards
Andy
On Tue, 2005-01-11 at 14:57 +0100, Jose Miguel Pérez wrote:
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.
-- perl -e "print qq^bIG VeRN ! ^^qq^#'#Yv#=<D+ ^"
This e-mail is private and may be confidential and is for the intended recipient
only. If misdirected, please notify us by telephone and confirm that it has
been deleted from your system and any copies destroyed. If you are not the
intended recipient you are strictly prohibited from using, printing, copying,
distributing or disseminating this e-mail or any information contained in it.
We use reasonable endeavours to virus scan all e-mails leaving the Company but
no warranty is given that this e-mail and any attachments are virus free. You
should undertake your own virus checking. The right to monitor e-mail
communications through our network is reserved by us.




