У меня была такая же проблема. Я решил эту проблему, как сказал pmg в первом пункте, используя настройку STMT_ATTR_UPDATE_MAX_LENGTH, вот мой код:
MYSQL_STMT *stmt;
MYSQL_BIND bind[1];
MYSQL_BIND bind_result[1];
// _con your mysql connection
stmt = mysql_stmt_init(_con);
if (!stmt)
{
fprintf(stderr, " mysql_stmt_init(), out of memory\n");
exit(0);
}
char* aQuery = (char*) "'your query'";
if (mysql_stmt_prepare(stmt, aQuery, strlen(aQuery)))
{
fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n");
fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
exit(0);
}
// Here fill binded parameters (here a string)
memset(bind, 0, sizeof(bind));
const char* aStr = ioType.c_str();
long unsigned int aSize = ioType.size();
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (char *) aStr;
bind[0].buffer_length= 2048;
bind[0].is_null= 0;
bind[0].length= &aSize;
/* Bind the buffers */
if (mysql_stmt_bind_param(stmt, bind))
{
fprintf(stderr, " mysql_stmt_bind_param() failed\n");
fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
exit(0);
}
// Reauest meta data information
MYSQL_RES* aRes = mysql_stmt_result_metadata(stmt);
// Set STMT_ATTR_UPDATE_MAX_LENGTH attribute
my_bool aBool = 1;
mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &aBool);
/* Execute the select statement - 1*/
if (mysql_stmt_execute(stmt))
{
fprintf(stderr, " mysql_stmt_execute(), 1 failed\n");
fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
exit(0);
}
if (mysql_stmt_store_result(stmt)) {
fprintf(stderr, " mysql_stmt_execute(), 1 failed\n");
fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
exit(0);
}
// Retrieving meta data information
MYSQL_FIELD* aField = &aRes->fields[0];
fprintf(stdout, " field %s \n",aField->name);
fprintf(stdout, " field length %d \n",(int) aField->length);
fprintf(stdout, " field max length %d \n", (int) aField->max_length);
int totalrows = mysql_stmt_num_rows(stmt);
fprintf(stdout, " fetched %d description\n",totalrows);
fprintf(stdout, " field count %d \n",(int) aRes->field_count);
long unsigned int aMaxSize;
char* aBuffer = (char*) malloc(aField->max_length);
memset (bind_result, 0, sizeof (bind_result));
bind_result[0].buffer_type= MYSQL_TYPE_BLOB;
bind_result[0].is_null= 0;
bind_result[0].buffer= (char *) aBuffer;
bind_result[0].buffer_length= aField->max_length;
bind_result[0].length= &aMaxSize;
mysql_stmt_bind_result(stmt, bind_result);
std::string aStrData;
while(!mysql_stmt_fetch(stmt))
{
fprintf(stdout, " size %d\n", (int) aMaxSize);
aStrData = std::string(aBuffer,aMaxSize);
fprintf(stdout, " data %s\n", aStrData.c_str());
}
free(aBuffer);
mysql_free_result(aRes);
if (mysql_stmt_close(stmt))
{
fprintf(stderr, " failed while closing the statement\n");
fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
exit(0);
}
Надеюсь, это поможет!