Checking the goodness of MYSQL* handle
Posted by: Giovanni Txxxxxx
Date: October 11, 2012 03:29AM

Hello everybody,

I've written a C client application with a function that tries to do some checks before performing any query to the server.

In details, it uses mysql_ping(), eventually re-inits the connection with mysql_init() and mysql_real_connect() and then calls mysql_query().

I want to add a check at the beginning of the function, about the MYSQL* handle which is used also as parameter by mysql_ping().

In fact, if the handle is somehow unusable (overwritten / subturfuged / damaged / anything) I get a segfault when using it.
I tried both this checks:

===============
MYSQL* mysql;
[...]
if (mysql!=NULL) mysql_ping(mysql);
if (mysql) mysql_ping(mysql)
===============

but they do not work (segfault if handle is already damaged).

The only mean I have to avoid the segfault is to reinitialize the handle with mysql_init(), just before the point I know the handle is already damaged.

What I want to do is then the following:

===============
if (handle is not ok) handle=mysql_init()
===============

But I don't know how to check if the handle is ok without getting a segmentation fault.

Thank you in advance for any suggestions!

Options: ReplyQuote


Subject
Views
Written By
Posted
Checking the goodness of MYSQL* handle
2109
October 11, 2012 03:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.