segmentation fault

C

Chris Grossbe

Hi!

this problem has been a headache for about 2 hours now and i just cant
figure it out.

ive got a c program that connects to a DB via mysql.
currently ive got 2 querys. the first worked just fine but when it comes
to the 2nd ive got an error: segmentation fault.

my query is fine tried it out directly.

i init the db with
dbHandle = mysql_init(0)
dbHandle = mysql_realconnect(dbHandle, host, pass.... blahbla)

as soon as the program comes to

mysql_query(dbHandle, str_query1);

it throws the seg fault

as i said the first q works without probs.
could it be that the dbHandle has been changed during the first q?

any help would be appricated

thx and greez
 
G

Gordon Burditt

this problem has been a headache for about 2 hours now and i just cant
figure it out.

ive got a c program that connects to a DB via mysql.
currently ive got 2 querys. the first worked just fine but when it comes
to the 2nd ive got an error: segmentation fault.

MySQL libraries are not part of standard C. However the issue
of checking for errors from function calls is still relevant to
standard C.
my query is fine tried it out directly.

i init the db with
dbHandle = mysql_init(0)
dbHandle = mysql_realconnect(dbHandle, host, pass.... blahbla)

Did you check to see whether dbHandle is NULL? If not, why not?
If it's NULL, your call didn't work, and you need to find out why.
Perhaps a call to mysql_error, feeding it the original value of
dbHandle from mysql_init() would give some useful information.
as soon as the program comes to

mysql_query(dbHandle, str_query1);

Did you initialize the value of str_query1? To what? (NULL?)
it throws the seg fault

Passing NULL where it's not expected tends to do that.
as i said the first q works without probs.

Returning NULL is not "working without probs".
could it be that the dbHandle has been changed during the first q?

What's a "q"? Oh, yeah, the letter after "p".

Gordon L. Burditt
 
C

Chris Grossbe

Gordon said:
MySQL libraries are not part of standard C. However the issue
of checking for errors from function calls is still relevant to
standard C.




Did you check to see whether dbHandle is NULL? If not, why not?
If it's NULL, your call didn't work, and you need to find out why.
Perhaps a call to mysql_error, feeding it the original value of
dbHandle from mysql_init() would give some useful information.




Did you initialize the value of str_query1? To what? (NULL?)




Passing NULL where it's not expected tends to do that.




Returning NULL is not "working without probs".




What's a "q"? Oh, yeah, the letter after "p".

Gordon L. Burditt
thx for the answer


1.i tried that already. the handler is not null, and init it with the
original values i tried too. same error
2. the str_querey1 and 2 are initialized.
3. by writing "working without probs" i mean it throws no seg fault.
instead the select gives a result that i expected.
4. by q i mean obviously query. sorry if i was too shortcutted ^^

how would u guys write a few-liner with 2 select calls, perhaps that
would help me out fast and painless *g*

any help appriciated
 

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

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top