From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050524 Fedora/1.0.4-4 Firefox/1.0.4 Description of problem: Using the following C code (test.c): #include <stdio.h> #include <stdlib.h> #include <mysql.h> int main (int argc, char *argv) { MYSQL demo_db; MYSQL *connect_status; MYSQL_RES *result; MYSQL_ROW row; MYSQL_FIELD *field; char *query = malloc(255); mysql_init(&demo_db); connect_status = mysql_real_connect( &demo_db, "localhost", "**************", // username "**************", // password "test", 3306, NULL, 0 ); if( !connect_status ) { fprintf(stderr,"Failed to connect to database: Error: %s\n", mysql_error(&demo_db)); exit(1); } else { printf("Connected to database\n");} sprintf(query,"SHOW TABLES"); if( mysql_real_query(&demo_db, query, 255) ){ printf("find_query error with query: \"%s\"\n",query); fprintf(stderr,"REPORTED ERROR : %s",mysql_error(&demo_db)); printf("\n"); exit(1); } else { printf("Find Query processed.\n"); } result = mysql_store_result(&demo_db); row = mysql_fetch_row(result); printf("Row[0] = %s\n", row[0]); return 0; } and compiling with this (gcc-4.0.0-8): gcc -lmysqlclient -I/usr/include/mysql -L/usr/lib/mysql src/test.c -o test I get this: ./test Connected to database find_query error with query: "SHOW TABLES" REPORTED ERROR : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 "SHOW TABLES" as SQL syntax error? methinks something is rotten in the state of denmark. BTW, using command line mysql, SHOW TABLES works fine. Similar code worked fine on FC3 - will confirm same code above works fine on FC3 later today. If no follow-up, assume code worked and that bug is FC4-only. Version-Release number of selected component (if applicable): mysq-devel-4.1.11-2 How reproducible: Always Steps to Reproduce: 1. Copy code 2. Compile code 3. Run code 4. Roll eyes Actual Results: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Expected Results: +-------------------+ | Tables_in_test | +-------------------+ | _fts_test | | _fts_test_data | | _fts_test_words | | _sl_test_stoplist | +-------------------+ 4 rows in set (0.00 sec) Additional info:
I think your code is faulty: you're passing string length 255 to mysql_real_query, when the string actually passed is only 12 characters counting the trailing null. The other 243 bytes contain garbage --- probably \0 characters in this test program, but in general the contents of a freshly malloc'd block are not guaranteed. Changing the "255" to "strlen(query)" makes it work for me. I don't know why it appeared to work on FC3; maybe MySQL 3.x silently ignored null characters in the supplied query string. But I see no bug here.