|
@@ -524,46 +524,75 @@ long lDate;
|
|
|
CATCHDAO
|
|
CATCHDAO
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// STATICS
|
|
|
|
|
|
|
+#define DELETE_CHUNCK_SIZE 100
|
|
|
|
|
|
|
|
-// deletes from both Main and Data Tables
|
|
|
|
|
-BOOL CClip::Delete( int id )
|
|
|
|
|
|
|
+// STATICS
|
|
|
|
|
+BOOL CClip::Delete( ARRAY& IDs )
|
|
|
{
|
|
{
|
|
|
-CString csMainSQL;
|
|
|
|
|
-CString csDataSQL;
|
|
|
|
|
-BOOL bRet = FALSE;
|
|
|
|
|
|
|
+ #ifdef _DEBUG
|
|
|
|
|
+ DWORD dTick = GetTickCount();
|
|
|
|
|
+ #endif
|
|
|
|
|
|
|
|
- csMainSQL.Format( "DELETE FROM Main WHERE lID = %d", id );
|
|
|
|
|
- csDataSQL.Format( "DELETE FROM Data WHERE lParentID = %d", id );
|
|
|
|
|
|
|
+ if(IDs.GetSize() <= 0)
|
|
|
|
|
+ return FALSE;
|
|
|
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- theApp.EnsureOpenDB();
|
|
|
|
|
- theApp.m_pDatabase->Execute(csMainSQL, dbFailOnError);
|
|
|
|
|
- theApp.m_pDatabase->Execute(csDataSQL, dbFailOnError);
|
|
|
|
|
- bRet = TRUE;
|
|
|
|
|
- }
|
|
|
|
|
- catch(CDaoException* e)
|
|
|
|
|
|
|
+ int nStart = 0;
|
|
|
|
|
+ int nEnd = DELETE_CHUNCK_SIZE;
|
|
|
|
|
+ int nLoops = (IDs.GetSize() / DELETE_CHUNCK_SIZE) + 1;
|
|
|
|
|
+ BOOL bRet = TRUE;
|
|
|
|
|
+ CString csMainSQL;
|
|
|
|
|
+ CString csDataSQL;
|
|
|
|
|
+ CString csMainFormat;
|
|
|
|
|
+
|
|
|
|
|
+ for(int n = 0; n < nLoops; n++)
|
|
|
{
|
|
{
|
|
|
- AfxMessageBox(e->m_pErrorInfo->m_strDescription);
|
|
|
|
|
- e->Delete();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ csMainSQL = "DELETE FROM Main WHERE";
|
|
|
|
|
+ csDataSQL = "DELETE FROM Data WHERE";
|
|
|
|
|
+ csMainFormat.Empty();
|
|
|
|
|
|
|
|
- return bRet;
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ csMainFormat.Format(" lID = %d", IDs[nStart]);
|
|
|
|
|
+ csMainSQL += csMainFormat;
|
|
|
|
|
|
|
|
-BOOL CClip::Delete( ARRAY& IDs )
|
|
|
|
|
-{
|
|
|
|
|
-int count = IDs.GetSize();
|
|
|
|
|
|
|
+ csMainFormat.Format(" lParentID = %d", IDs[nStart]);
|
|
|
|
|
+ csDataSQL += csMainFormat;
|
|
|
|
|
|
|
|
- if(count <= 0)
|
|
|
|
|
- return FALSE;
|
|
|
|
|
|
|
+ nEnd = min(nEnd, IDs.GetSize());
|
|
|
|
|
+
|
|
|
|
|
+ for(int i = nStart+1; i < nEnd; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ csMainFormat.Format(" Or lID = %d", IDs[i]);
|
|
|
|
|
+ csMainSQL += csMainFormat;
|
|
|
|
|
+
|
|
|
|
|
+ csMainFormat.Format(" Or lParentID = %d", IDs[i]);
|
|
|
|
|
+ csDataSQL += csMainFormat;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ nStart = nEnd;
|
|
|
|
|
+ nEnd += DELETE_CHUNCK_SIZE;
|
|
|
|
|
+
|
|
|
|
|
+ bRet = TRUE;
|
|
|
|
|
|
|
|
-BOOL bRet = TRUE;
|
|
|
|
|
- // delete one at a time rather than all in one query
|
|
|
|
|
- // in order to avoid the "query too large" error for large deletes
|
|
|
|
|
- for( int i=0; i < count && bRet; i++ )
|
|
|
|
|
- bRet = bRet && Delete( IDs[i] );
|
|
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ theApp.EnsureOpenDB();
|
|
|
|
|
+ theApp.m_pDatabase->Execute(csMainSQL, dbFailOnError);
|
|
|
|
|
+ theApp.m_pDatabase->Execute(csDataSQL, dbFailOnError);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch(CDaoException* e)
|
|
|
|
|
+ {
|
|
|
|
|
+ AfxMessageBox(e->m_pErrorInfo->m_strDescription);
|
|
|
|
|
+ e->Delete();
|
|
|
|
|
+ bRet = FALSE;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #ifdef _DEBUG
|
|
|
|
|
+ {
|
|
|
|
|
+ CString cs;
|
|
|
|
|
+ cs.Format("Delete Time = %d\n", GetTickCount() - dTick);
|
|
|
|
|
+ TRACE(cs);
|
|
|
|
|
+ }
|
|
|
|
|
+ #endif
|
|
|
|
|
|
|
|
return bRet;
|
|
return bRet;
|
|
|
}
|
|
}
|