Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2003
    Posts
    1

    Unanswered: Segmentation Fault on mysql_real_query

    Here's the code I wrote using the C MySQL API:

    char * query;
    MYSQL_RES *res; /* To be used to fetch information into */
    MYSQL_ROW row;
    int datasize;
    const char* text = "SELECT * FROM number WHERE nth=(SELECT MAX(nth) FROM number)";

    if( argc != 2 ){
    printf("USEAGE: primetable [number of primes]\n");
    return 0;
    }

    if( mysql_init(&prime_db) == NULL ){
    printf( "Not enough memory\n" );
    exit(1);
    }

    if(!mysql_real_connect(&prime_db, "localhost", "lord", "farquad", "primes", 0, NULL, 0 )){
    printf(mysql_error(&prime_db));
    exit(1);
    }

    //printf("%d\n",mysql_field_count(&prime_db));

    datasize=mysql_real_escape_string(&prime_db, query, text, strlen(text));

    if(mysql_real_query(&prime_db, query, datasize)){ /* Make query */
    printf("%s",mysql_error(&prime_db));
    exit(1);
    }

    When I try to execute I get a Segmentation Fault. gdb points to mysql_real_query as the culprit.

    Thanks!

    Russell
    Last edited by hegelian; 08-27-03 at 16:03.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •