mysql error handling

C

crowl

I have written a program which logs to mysql database. Error routines
should handle the worst case if something goes wrong. In my tests I get
a segmentation fault if I stop the mysql database (stopping after the
mysql connection was successfully). It breaks at this line:
iErr=mysql_errno(&f->f_hmysql);


Here the mysql_query call and the code of the error handling:

/* query */
dprintf("try to call mysql_query ...\n");
if(mysql_query(&f->f_hmysql, psz)) {
int iErr=0;
dprintf("in error handler\n");
iErr=mysql_errno(&f->f_hmysql);
dprintf("mysql insert failed. ErrNo: %n\n", iErr);
}
else {
dprintf("db insert sucessfully\n");
}
dprintf("...after mysql_query.\n");

Any idea how to avoid the segmentation fault? I'm using gcc on a debian
machine.

Thanks for help.
 
L

Lawrence Kirby

I have written a program which logs to mysql database. Error routines
should handle the worst case if something goes wrong. In my tests I get
a segmentation fault if I stop the mysql database (stopping after the
mysql connection was successfully). It breaks at this line:
iErr=mysql_errno(&f->f_hmysql);

Discussion of MySQL specific issues is off topic for comp.lang.c, however
you may have a simple C problem. Unfortunately it is not possible to tell
given the information you have posted. Perhaps f or what it points to
haven't been initialised correctly.

Lawrence
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top