Hello, I seem to have a problem with the C API, briefly I try to select something into a temporary table and then do three selects, two of which are from the temporary table created. Program segfaults. When I comment all but temp table creation, program works, and same happens for a non-temp table select, but when both are present, the program simply refuses to run.
code details (complete queries ommitted for clarity, queries are not problematic - they were tested with the standalone mysql client): query_len = sprintf(query, "CREATE TEMPORARY TABLE temp SELECT ...."); fprintf(stderr, "QUERY: %s\nLEN: %d\n", query, query_len); if (mysql_real_query(db_read, query, query_len)) { free(query); b_abort("CREATE TABLE temp unsuccessful: %s", mysql_error(db_read)); } if (mysql_affected_rows(db_read) == 0) { /* no rows transferred to the temp table, skip entry */ fprintf(stderr, "CREATE TABLE selected no rows, skipping id %d\n", id); free(query); return 1; /* no self score found, but the query was OK */ } fprintf(stderr, "Created table with results for id %d, affected rows %lu, errcode %d\n", id, (unsigned long) mysql_affected_rows(db_read), mysql_errno(db_read)); /* get group and self-score */ query_len = sprintf(query, "SELECT a1, a2 FROM t1,t2 GROUP BY ..."); fprintf(stderr, "QUERY: %s\nLEN: %d\n", query, query_len); if (mysql_query(db_read, query)) { b_abort("SELECT from BRP, Map unsuccessful: %s", mysql_error(db_read)); } res_set = mysql_store_result(db_read); fprintf(stderr, "SELECT FROM ResultPairs, affected rows %lu, result_set %lu rows\n", (unsigned long) mysql_affected_rows(db_read), (unsigned long) mysql_num_rows(res_set)); if (res_set && mysql_num_rows(res_set)){ if ((row = mysql_fetch_row(res_set)) != NULL){ mygrp = (unsigned long) atol(row[0]); selfscore = (unsigned long) atol(row[1]); } mysql_free_result(res_set); } else { fprintf(stderr, "SELF SCORE selected no rows, skipping id %d", id); free(query); return 1; /* no self sacore found, but the query was OK */ } fprintf(stderr, "selected group (%d) & selfscore (%d) results for id %d\n", mygrp, selfscore, id); when both queries are uncommented the program segfaults in: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1024 (LWP 11049)] chunk_alloc (ar_ptr=0x401d0a00, nb=49) at malloc.c:2929 2929 malloc.c: No such file or directory. in malloc.c (gdb) where #0 chunk_alloc (ar_ptr=0x401d0a00, nb=49) at malloc.c:2929 #1 0x4011c108 in __libc_malloc (bytes=40) at malloc.c:2811 #2 0x4003c12d in my_malloc () from /usr/lib/mysql/libmysqlclient.so.10 #3 0x40037e4c in read_rows () from /usr/lib/mysql/libmysqlclient.so.10 #4 0x40039554 in mysql_read_query_result () from /usr/lib/mysql/libmysqlclient.so.10 #5 0x400395ff in mysql_real_query () from /usr/lib/mysql/libmysqlclient.so.10 #6 0x400393bb in mysql_query () from /usr/lib/mysql/libmysqlclient.so.10 #7 0x0804b285 in do_statistics (db_read=0x805c800, db_write=0x805fbf8, id=102, type=3) at Stattest.c:291 #8 0x0804b82a in main (argc=6, argv=0xbffffb24) at Stattest.c:552 #9 0x400b8627 in __libc_start_main (main=0x804b3ec <main>, argc=6, ubp_av=0xbffffb24, init=0x8049a6c <_init>, fini=0x8056d00 <_fini>, rtld_fini=0x4000dcd4 <_dl_fini>, stack_end=0xbffffb1c) at ../sysdeps/generic/libc-start.c:129 when I comment either ow the two, the program runs OK. Any ideas? Kristian -- Dr. sc. Kristian Vlahovicek Protein structure & bioinformatics Phone: +39 0403757354 ICGEB Fax: +39 040226555 Padriciano 99 E-mail: kristian(at)icgeb(dot)trieste(dot)it Trieste 34012 Italy Web: http://www.icgeb.trieste.it/dna --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php