#include #include #include #include BOOL doUpdate = TRUE; class myRS : public CRecordset { public: DECLARE_DYNAMIC(myRS); myRS(CDatabase* pdb = NULL) : CRecordset(pdb) { int cnt = 0; m_c1 = 0; cnt++; m_c2 = ""; cnt++; m_c2 = ""; cnt++; m_nFields = cnt; } virtual void DoFieldExchange(CFieldExchange* pFX) { pFX->SetFieldType(CFieldExchange::outputColumn); RFX_Long(pFX, _T("[c1]"), m_c1); RFX_Text(pFX, _T("[c2]"), m_c2); RFX_Text(pFX, _T("[c3]"), m_c3); } virtual CString GetDefaultSQL() { return _T("SELECT c1,c2,c3 FROM tab1"); } long m_c1; CString m_c2; CString m_c3; }; IMPLEMENT_DYNAMIC(myRS, CRecordset); DWORD WINAPI my_update(LPVOID param) { long id = (long)param; try{ int tid = GetCurrentThreadId(); CDatabase db; db.OpenEx("DSN=test", CDatabase::noOdbcDialog); printf("[%5d] opendb ", tid); myRS t1(&db); t1.m_strFilter.Format("c1 = %d", id); t1.Open(); printf(" open"); if(t1.IsEOF()) { printf("Record %d not found\n", id); exit(1); } t1.Edit(); printf(" edit"); srand((int)time(NULL)); t1.m_c2.Format("%d %d", tid, long(rand())); if(doUpdate){ t1.Update(); printf(" upd"); } t1.Close(); printf(" cls"); db.Close(); printf(" dbcls"); printf("\n"); }catch(CException * ee){ char buff[256]; ee->GetErrorMessage(buff, sizeof buff); printf("ERROR - %s\n", buff); ee->Delete(); exit(1); } return 0; } //---------------------------------------------------------------- int main(int argc, char ** argv) { int limit = 10000; int delay = 0; doUpdate = ! (argc > 1 && _stricmp(argv[1], "-no-update") == 0); printf("Limit=%d delay[ms]=%d doUpdate=%d\n", limit, delay, doUpdate); Sleep(1000); CDatabase db; db.OpenEx("DSN=test", CDatabase::noOdbcDialog); myRS t1(&db); t1.Open(); for(int ii=1; ii <= limit; ii++) { if(t1.IsEOF()) { t1.Close(); t1.Open(); } printf("%5d id=%8d ", ii, t1.m_c1); if(my_update((LPVOID)t1.m_c1) != 0) return 1; if(delay > 0) Sleep(delay); t1.MoveNext(); } t1.Close(); db.Close(); return 0; }