Q:

Syntax error in mySQL prepare statement using C API

I created a mySQL database, with some stored procedures. Using mySQL Workbench the SP forks fine, and now i need to launch them using a c program.
I created the program, which connect successfully to my db, and i'm able to launch procedures wich not requires parameters.
To launch more complex procedure i need to use the prepare statement in c: in particular, i want to call the procedure esame_cancella(IN code CHAR(5)) wich delete a selected row of the table 'esame'.
    int status;
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    MYSQL_RES *rs_metadata;
    MYSQL_STMT *stmt;
    MYSQL_BIND ps_params[6];
    unsigned long length[6];
    char cod[64];

    printf("Codice: ");
    scanf ("%s",cod);
    length[0] = strlen(cod);

    stmt = mysql_stmt_init(conn);
    if (stmt == NULL) {
        printf("Could not initialize statement\n");
        exit(1);
    }

    status = mysql_stmt_prepare(stmt, "call esame_cancella(?) ", 64);
    test_stmt_error(stmt, status); //line which gives me the syntax error 

    memset(ps_params, 0, sizeof(ps_params));

    ps_params[0].buffer_type = MYSQL_TYPE_VAR_STRING;
    ps_params[0].buffer = cod;
    ps_params[0].buffer_length = 64;
    ps_params[0].length = &length[0];
    ps_params[0].is_null = 0;

    // bind parameters
    status = mysql_stmt_bind_param(stmt, ps_params); //muore qui
    test_stmt_error(stmt, status);

    // Run the stored procedure
    status = mysql_stmt_execute(stmt);
    test_stmt_error(stmt, status);

    }

i use test_stmt_error to see mySQL log calling procedures.
    static void test_stmt_error(MYSQL_STMT * stmt, int status)
    {
        if (status) {
            fprintf(stderr, "Error: %s (errno: %d)\n",
            mysql_stmt_error(stmt), mysql_stmt_errno(stmt));
            exit(1);
        }
    }

when i compile, and launch my program, i have the following log:
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 (errno: 1064)
Any help?

A:

It looks like the string length being passed to mysql_stmt_prepare is wrong - try changing the 64 to 24.
Or better yet, try something like:
const char sql_sp[] = "call esame_cancella(?) ";
...
status = mysql_stmt_prepare(stmt, sql_sp, sizeof(sql_sp));

