wlbock
August 4th, 2006, 05:01 PM
Heya:
It's entirely possible one of the other subforums would be more appropriate. That said, I have an application that makes use of the C++ MySQL API to connect across a network to a server running MySQL (a recent version). My code uses functions like mysql_real_connect and so on.
If the network cable gets disconnected while I'm adding records to the MySQL database, _sometimes_ my application crashes. I put in some debugging code and I _think_ the crash occurs during calls to mysql_stmt_send_long_data, which I call repeatedly, 1024 bytes at a time, to add 200-400K chunks of data to a blob in my database.
Here's what the (relatively ugly) code looks like:
ULONG ulPos = 0;
while (ulPos < ulAudioSize)
{
ULONG ulRemainingBytes = ulAudioSize - ulPos;
if (ulRemainingBytes > 1024) ulRemainingBytes = 1024;
/* Supply data in chunks to server */
try
{
if (mysql_stmt_send_long_data(stmt, 0, chAudio+ulPos, ulRemainingBytes)) // Docs say zero is success
{
sprintf(didb_error, "send_long_data failed,\n%s", mysql_stmt_error(stmt));
//mysql_stmt_close(stmt); // wlb073106 : Example from mysql.com doesn't close stmt.
didb_add_status = 1;
return false;
}
}
catch (CException*)
{
didb_log("EXCEPTION with mysql_stmt_send_long_data");
strcpy(didb_error, "mysql_stmt_send_long_data(), exception\n");
didb_add_status = 1;
return false;
}
ulPos += ulRemainingBytes;
}
I'm kind of hoping that this question is 1) in the right place and 2) something that is easily dealt with or understood or recognized. ;) Any advice?
Thanks,
Bill
It's entirely possible one of the other subforums would be more appropriate. That said, I have an application that makes use of the C++ MySQL API to connect across a network to a server running MySQL (a recent version). My code uses functions like mysql_real_connect and so on.
If the network cable gets disconnected while I'm adding records to the MySQL database, _sometimes_ my application crashes. I put in some debugging code and I _think_ the crash occurs during calls to mysql_stmt_send_long_data, which I call repeatedly, 1024 bytes at a time, to add 200-400K chunks of data to a blob in my database.
Here's what the (relatively ugly) code looks like:
ULONG ulPos = 0;
while (ulPos < ulAudioSize)
{
ULONG ulRemainingBytes = ulAudioSize - ulPos;
if (ulRemainingBytes > 1024) ulRemainingBytes = 1024;
/* Supply data in chunks to server */
try
{
if (mysql_stmt_send_long_data(stmt, 0, chAudio+ulPos, ulRemainingBytes)) // Docs say zero is success
{
sprintf(didb_error, "send_long_data failed,\n%s", mysql_stmt_error(stmt));
//mysql_stmt_close(stmt); // wlb073106 : Example from mysql.com doesn't close stmt.
didb_add_status = 1;
return false;
}
}
catch (CException*)
{
didb_log("EXCEPTION with mysql_stmt_send_long_data");
strcpy(didb_error, "mysql_stmt_send_long_data(), exception\n");
didb_add_status = 1;
return false;
}
ulPos += ulRemainingBytes;
}
I'm kind of hoping that this question is 1) in the right place and 2) something that is easily dealt with or understood or recognized. ;) Any advice?
Thanks,
Bill