Browse Source

delete 100 items at a time and show selection/total count in status -- SAB

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@41 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 22 years ago
parent
commit
b838262140
7 changed files with 87 additions and 34 deletions
  1. 5 1
      CP_Main.cpp
  2. 60 31
      ProcessCopy.cpp
  3. 0 1
      ProcessCopy.h
  4. 6 0
      QListCtrl.cpp
  5. 1 0
      QListCtrl.h
  6. 14 1
      QPasteWnd.cpp
  7. 1 0
      QPasteWnd.h

+ 5 - 1
CP_Main.cpp

@@ -326,7 +326,11 @@ void CCP_MainApp::OnCopyCompleted(long lLastID, int count)
 
 void CCP_MainApp::SetStatus( const char* status, bool bRepaintImmediately )
 {
-	m_Status = status;
+	if(status != NULL)
+	{
+		m_Status = status;
+	}
+
 	if( QPasteWnd() )
 		QPasteWnd()->UpdateStatus( bRepaintImmediately );
 }

+ 60 - 31
ProcessCopy.cpp

@@ -524,46 +524,75 @@ long lDate;
 	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;
 }

+ 0 - 1
ProcessCopy.h

@@ -98,7 +98,6 @@ public:
 
 // STATICS
 	// deletes from both Main and Data Tables
-	static BOOL Delete( int id );
 	static BOOL Delete( ARRAY& IDs );
 	static BOOL DeleteAll();
 

+ 6 - 0
QListCtrl.cpp

@@ -775,3 +775,9 @@ void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
 	CListCtrl::OnKillFocus(pNewWnd);
 	m_Popup.Hide();
 }
+
+BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = LVSICF_NOINVALIDATEALL */)
+{
+	theApp.SetStatus(NULL, TRUE);
+	return CListCtrl::SetItemCountEx(iCount, dwFlags);
+}

+ 1 - 0
QListCtrl.h

@@ -85,6 +85,7 @@ public:
 	void DestroyAndCreateAccelerator(BOOL bCreate);
 
 	void ShowFullDescription();
+	BOOL SetItemCountEx(int iCount, DWORD dwFlags = LVSICF_NOINVALIDATEALL);
 
 protected:
 	void SendSelection(int nItem);;

+ 14 - 1
QPasteWnd.cpp

@@ -71,6 +71,7 @@ BEGIN_MESSAGE_MAP(CQPasteWnd, CWndEx)
 	ON_COMMAND(ID_MENU_PROPERTIES, OnMenuProperties)
 	ON_WM_CLOSE()
 	ON_NOTIFY(LVN_BEGINDRAG, ID_LIST_HEADER, OnBegindrag)
+	ON_NOTIFY(LVN_ITEMCHANGED, ID_LIST_HEADER, OnSelectionChange)
 	ON_WM_SYSKEYDOWN()
 	ON_NOTIFY(LVN_GETDISPINFO, ID_LIST_HEADER, GetDispInfo)
 	ON_NOTIFY(LVN_ODFINDITEM, ID_LIST_HEADER, OnFindItem)
@@ -390,6 +391,13 @@ CString prev;
 
 	GetWindowText(prev);
 
+	if(m_Recset.IsOpen())
+	{
+		CString cs;
+		cs.Format(" - %d/%d", m_lstHeader.GetSelectedCount(), m_Recset.GetRecordCount());
+		title += cs;
+	}
+
 	if( theApp.m_Status != "" )
 	{
 		title += " [ ";
@@ -1143,7 +1151,7 @@ void CQPasteWnd::OnGetToolTipText(NMHDR* pNMHDR, LRESULT* pResult)
 		cs += "\n\n";
 
 #ifdef _DEBUG
-		cs += StrF("Index = %d (DB ID = %d) ", pInfo->lItem, m_Recset.m_lID );
+		cs += StrF("(Index = %d) (DB ID = %d) (Size = %d)\n", pInfo->lItem, m_Recset.m_lID, m_Recset.m_strText.GetLength() );
 #endif
 
 		CTime time(m_Recset.m_lDate);
@@ -1270,3 +1278,8 @@ void CQPasteWnd::OnWindowPosChanging(WINDOWPOS* lpwndpos)
 		lpwndpos->y = rcScreen.bottom - lpwndpos->cy;
 	}
 }
+
+void CQPasteWnd::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
+{
+	theApp.SetStatus(NULL, TRUE);
+}

+ 1 - 0
QPasteWnd.h

@@ -113,6 +113,7 @@ protected:
 	afx_msg void OnMenuProperties();
 	afx_msg void OnClose();
 	afx_msg void OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult);
+	afx_msg void OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult);
 	afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
 	afx_msg void GetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
 	afx_msg void OnFindItem(NMHDR* pNMHDR, LRESULT* pResult);