running a mysql query inside a loop of another without a sync error

2011-01-19 Thread Delan Azabani
Hi all,

I'm using MySQL with C in a CGI application. I hope this is the right
list to ask for help.

If I have this simplified code:

MYSQL_RES *res;
MYSQL_ROW row;
mysql_query(mysql, "some select query");
res = mysql_use_result(mysql);
while (row = mysql_fetch_row(res)) {
MYSQL_RES *res2;
MYSQL_ROW row2;
mysql_query(mysql, "some other select query using an id from the
first");
res2 = mysql_use_result(mysql);
/* ... */
mysql_free_result(res2);
}
mysql_free_result(res);

Whenever I run the second query, inside the loop, I get the nasty
'commands out of sync' error. How can I run a select query while in a
loop fetching rows from another select query? Or, do I have to fetch all
the rows completely first and store them in memory (which wouldn't be
very 'nice' to do)?

If someone could help me with this problem, it would be greatly appreciated.

-- 
Thanks and best regards,
Delan Azabani
http://azabani.com/

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



linking to mysql in C

2011-01-07 Thread Delan Azabani
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi all,

This is a novice problem I'm having with compiling a C CGI program with
MySQL on my Gentoo box.

I have a simple source so far:

* cbook-main.c: http://pastebin.com/vnT6j1z2
* cbook-main.h: http://pastebin.com/4BnyWs27
* Makefile: http://pastebin.com/m973gbjG

When compiling I receive undefined reference errors:

de...@delan2 ~/cbook $ make
make cbook-main
make[1]: Entering directory `/home/delan/cbook'
cc -g `pkg-config --cflags libconfuse glib-2.0` `mysql_config --cflags`
- -c cbook-main.c
make[1]: Leaving directory `/home/delan/cbook'
cc `pkg-config --libs libconfuse glib-2.0` `mysql_config --libs` -o
cbook.cgi cbook-main.o
cbook-main.o: In function `myerror':
/home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_error'
/home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_errno'
cbook-main.o: In function `myescape':
/home/delan/cbook/cbook-main.c:67: undefined reference to
`mysql_real_escape_string'
cbook-main.o: In function `myquery':
/home/delan/cbook/cbook-main.c:85: undefined reference to `mysql_query'
cbook-main.o: In function `createDatabase':
/home/delan/cbook/cbook-main.c:90: undefined reference to `mysql_select_db'
cbook-main.o: In function `pageHome':
/home/delan/cbook/cbook-main.c:144: undefined reference to
`mysql_store_result'
/home/delan/cbook/cbook-main.c:146: undefined reference to `mysql_fetch_row'
/home/delan/cbook/cbook-main.c:160: undefined reference to
`mysql_free_result'
cbook-main.o: In function `pageSessions':
/home/delan/cbook/cbook-main.c:181: undefined reference to
`mysql_store_result'
/home/delan/cbook/cbook-main.c:182: undefined reference to `mysql_fetch_row'
cbook-main.o: In function `main':
/home/delan/cbook/cbook-main.c:287: undefined reference to `mysql_init'
/home/delan/cbook/cbook-main.c:289: undefined reference to
`mysql_real_connect'
/home/delan/cbook/cbook-main.c:290: undefined reference to `mysql_select_db'
/home/delan/cbook/cbook-main.c:297: undefined reference to `mysql_close'
collect2: ld returned 1 exit status
make: *** [all] Error 1

I have read the following page already and unfortunately, I am still
unable to compile it:
http://dev.mysql.com/doc/refman/5.0/en/c-api-linking-problems.html

If anyone could help me with this it would be greatly appreciated.

- -- 
Thanks and best regards,
Delan Azabani
http://azabani.com/
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJNJ/DQAAoJEAVIdHYYQWqnYTQP/10GHt7lmBjynjTXfypg+EHg
+z0mW3yr0J6TIBYasYdNSPWr2y6LCu1WqM2hP350pxj3ILQwJTZWldL93uyo
minSTobxcLU7Q2NCq5yJI6nTvW8WbBUlsAuSLiFrJSRSljH7roL4i2hLqrx66GkB
OCwoykznGcWsYKrTnhcszCQ2opK2YVf3T4duImynoYfFsZWP5JYyse5kGBJhXFaR
vUGpbNu59EFRylyDpRkMvQDUv45Y+cBpmruz+OUpit5eoyOxg3aUd9Bdm+FIHnMQ
c5QTz/g8kwfQJ5eOkWZhHfvO8jBLOdPFqkd9vdayw3kZihEXKMHTco8pFQRm/F2q
4w0TPCAaedN+1gspS+1Hon5ADBuz8q0J+LWkiOWcPKj6NL4NXOiQwQd8PZdyNOmM
VhH1/kF4Y5wCKvl/tQJWOjjJO31LOX9Lmdz8cP4sI8opHbJ4K4WPWj31spkFkF7c
NYwr+S6X+BLFvrKcunyIHYe+4btnt57BtMouTyNb8mb59rQFhL7h0LiUPhrzpwxr
wk1byf7Ov0OyVE7b2bc5+bIAf4MnaPVC+TGTezPFLbpx1tE40ZWlBxAjxPFmIuvY
ZjB7Rtyc4+bW2fMiM4GFVQODsvJCB9x/tUNOw7I2jyKQI5pBczkqBxiNqswVM7yE
yc77+eyvX6IgeZ9svzvO
=y9dU
-END PGP SIGNATURE-

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org