Description:
I've played with mySQL. I have many problems with it. Retrieving the records is OK but update & delete operation is so problematic. Main error was "no records affected by update or delete operation". I've searched in the internet and have done many things which people suggest. But nothing happened.
I wrap my test code here. Before this, I want to say that, there are no any other person/exe to modify the record; it is just my exe. And I am sure that, there is a record on the table to edit and delete. I mean, there is no actual reason to be come up with an 'unaffected case'.
Here is my code:
void CMySQLTestDlg::OnBnClickedTest()
{
CDatabase db;
CString dbConnStr = _T("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=Company;USER=roo
t;OPTION=3;");
if( ! db.Open( NULL, FALSE, FALSE, dbConnStr, TRUE ) )
{
AfxMessageBox( "DataBase couldn't be open" );
return;
}
CPersonRecSet personRS( &db );
personRS.m_strFilter = "ID = 2"; //there is such a record //filter line
if( ! personRS.Open() )
{
AfxMessageBox( "Person Table couldn't be open" );
return;
}
//delete
if( ! personRS.IsEOF() && ! personRS.IsBOF() )
{
personRS.Delete(); //cursor comes here in debug! but generaly fails
}
personRS.Close();
db.Close();
}//method
Another thing
Main problem is that: MySQL behaves instable.
This code somethimes runs correctly, sometimes fails.
Here is a scenario:
1-)run exe //OK! deleted.
2-)run MySQL Control Center to see update/delete//OK! it seems deleted.
3-)change filter line in the code, give another existing ID, compile and run //Fail..
4-)close MySQL Control Center, run the myTest.exe //Fail
5-)Stop and Restart all sql server services, run myTest.exe//Fail
Could you please inform me, whether this is a bug or I have a mistake ?
How to repeat: