Ver código fonte

changed strText to mText type memo and removed strType -- SAB

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@39 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 22 anos atrás
pai
commit
92f596d1f9
7 arquivos alterados com 46 adições e 27 exclusões
  1. 3 0
      CP_Main.cpp
  2. 37 16
      DatabaseUtilities.cpp
  3. 1 0
      DatabaseUtilities.h
  4. 2 4
      MainTable.cpp
  5. 0 1
      MainTable.h
  6. 0 1
      ProcessCopy.cpp
  7. 3 5
      QPasteWnd.cpp

+ 3 - 0
CP_Main.cpp

@@ -83,6 +83,9 @@ BOOL CCP_MainApp::InitInstance()
 
 	AfxOleInit();
 
+	if(DoCleanups() == FALSE)
+		return TRUE;
+
 	CMainFrame* pFrame = new CMainFrame;
 	m_pMainWnd = m_pMainFrame = pFrame;
 

+ 37 - 16
DatabaseUtilities.cpp

@@ -11,6 +11,41 @@
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
+BOOL DoCleanups()
+{
+	try
+	{		
+		//Try and open mText if it's not there then create it
+		CDaoRecordset recset(theApp.EnsureOpenDB());
+		recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT mText FROM Main", 0);
+		recset.Close();		
+	}
+	catch(CDaoException* e)
+	{
+		e->Delete();
+		try
+		{
+			theApp.EnsureOpenDB();
+			theApp.m_pDatabase->Execute("ALTER TABLE Main ADD COLUMN mText MEMO", dbFailOnError);
+			theApp.m_pDatabase->Execute("UPDATE Main SET mText=strText", dbFailOnError);
+			theApp.m_pDatabase->Execute("ALTER TABLE Main DROP COLUMN strText", dbFailOnError);
+			theApp.m_pDatabase->Execute("ALTER TABLE Main DROP COLUMN strType", dbFailOnError);
+		}
+		catch(CDaoException *e)
+		{
+			CString cs;
+			cs = e->m_pErrorInfo->m_strDescription;
+			cs += "\n\nError updating Database!";
+			MessageBox(NULL, cs, "Ditto", MB_OK);
+
+			e->Delete();
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
 CString GetDBName()
 {
 	return CGetSetOptions::GetDBPath();
@@ -104,25 +139,12 @@ BOOL ValidDB(CString csPath)
 		CDaoFieldInfo info;
 
 		table.Open("Main");
-		table.GetFieldInfo("lID", info);
-		table.GetFieldInfo("lDate", info);
-		table.GetFieldInfo("strType", info);
-		table.GetFieldInfo("strText", info);
-		table.GetFieldInfo("lShortCut", info);
-		table.GetFieldInfo("lDontAutoDelete", info);
-		table.GetFieldInfo("lTotalCopySize", info);
 		table.Close();
 
 		table.Open("Data");
-		table.GetFieldInfo("lID", info);
-		table.GetFieldInfo("lParentID", info);
-		table.GetFieldInfo("strClipBoardFormat", info);
-		table.GetFieldInfo("ooData", info);
 		table.Close();
 
 		table.Open("Types");
-		table.GetFieldInfo("ID", info);
-		table.GetFieldInfo("TypeText", info);
 		table.Close();
 	}
 	catch(CDaoException* e)
@@ -156,8 +178,8 @@ BOOL CreateDB(CString csPath)
 		table.CreateField("lDate", dbLong, 4, 0, "0");
 		table.CreateIndex(FALSE, "lDate");
 
-		table.CreateField("strType", dbText, 50, dbVariableField);
-		table.CreateField("strText", dbText, 255, dbVariableField);
+		table.CreateField("mText", dbMemo, 0, dbVariableField);
+//		table.CreateField("strText", dbText, 250, dbVariableField);
 
 		table.CreateField("lShortCut", dbLong, 4, 0, "0");
 		table.CreateIndex(FALSE, "lShortCut");
@@ -205,7 +227,6 @@ BOOL CreateDB(CString csPath)
 	return FALSE;
 }
 
-
 BOOL CompactDatabase()
 {
 	if(!theApp.CloseDB())

+ 1 - 0
DatabaseUtilities.h

@@ -82,6 +82,7 @@ public:
 	
 };
 
+BOOL DoCleanups();
 CString GetDBName();
 BOOL CompactDatabase();
 CString GetDefaultDBName();

+ 2 - 4
MainTable.cpp

@@ -23,13 +23,12 @@ CMainTable::CMainTable(CDaoDatabase* pdb)
 	//{{AFX_FIELD_INIT(CMainTable)
 	m_lID = 0;
 	m_lDate = 0;
-	m_strType = _T("");
 	m_strText = _T("");
 	m_lShortCut = 0;
 	m_lDontAutoDelete = 0;
 	m_lTotalCopySize = 0;
 
-	m_nFieldCount = m_nFields = 7;
+	m_nFieldCount = m_nFields = 6;
 	//}}AFX_FIELD_INIT
 	m_nDefaultType = dbOpenDynaset;
 	m_bBindFields = true;
@@ -54,8 +53,7 @@ void CMainTable::DoFieldExchange(CDaoFieldExchange* pFX)
 	pFX->SetFieldType(CDaoFieldExchange::outputColumn);
 	DFX_Long(pFX, _T("[lID]"), m_lID);
 	DFX_Long(pFX, _T("[lDate]"), m_lDate);
-	DFX_Text(pFX, _T("[strType]"), m_strType);
-	DFX_Text(pFX, _T("[strText]"), m_strText);
+	DFX_Text(pFX, _T("[mText]"), m_strText);
 	DFX_Long(pFX, _T("[lShortCut]"), m_lShortCut);
 	DFX_Long(pFX, _T("[lDontAutoDelete]"), m_lDontAutoDelete);
 	DFX_Long(pFX, _T("[lTotalCopySize]"), m_lTotalCopySize);

+ 0 - 1
MainTable.h

@@ -18,7 +18,6 @@ public:
 	//{{AFX_FIELD(CMainTable, CDaoRecordset)
 	long	m_lID;
 	long	m_lDate;
-	CString	m_strType;
 	CString	m_strText;
 	long	m_lShortCut;
 	long	m_lDontAutoDelete;

+ 0 - 1
ProcessCopy.cpp

@@ -443,7 +443,6 @@ long lDate;
 		recset.AddNew();
 
 		recset.m_lDate = lDate;
-		recset.m_strType = GetFormatName( m_Formats[0].m_cfType );
 		recset.m_strText = m_Desc;
 		recset.m_lTotalCopySize = m_lTotalCopySize;
 

+ 3 - 5
QPasteWnd.cpp

@@ -1085,8 +1085,7 @@ void CQPasteWnd::GetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)
 				cs += m_Recset.m_strText;
 				
 				lstrcpyn(pItem->pszText, cs, pItem->cchTextMax);
-				if(cs.GetLength() > pItem->cchTextMax)
-					pItem->pszText[pItem->cchTextMax-1] = 0;
+				pInfo->pszText[pItem->cchTextMax-1] = '\0';
 			}
 			catch(CDaoException *e)
 			{
@@ -1144,7 +1143,7 @@ void CQPasteWnd::OnGetToolTipText(NMHDR* pNMHDR, LRESULT* pResult)
 		cs += "\n\n";
 
 #ifdef _DEBUG
-		cs += StrF("%d (%d) ", pInfo->lItem, m_Recset.m_lID );
+		cs += StrF("Index = %d (DB ID = %d) ", pInfo->lItem, m_Recset.m_lID );
 #endif
 
 		CTime time(m_Recset.m_lDate);
@@ -1171,8 +1170,7 @@ void CQPasteWnd::OnGetToolTipText(NMHDR* pNMHDR, LRESULT* pResult)
 		}
 
 		lstrcpyn(pInfo->pszText, cs, pInfo->cchTextMax);
-		if(cs.GetLength() > pInfo->cchTextMax)
-			pInfo->pszText[pInfo->cchTextMax-1] = 0;
+		pInfo->pszText[pInfo->cchTextMax-1] = '\0';
 	}
 	catch(CDaoException *e)
 	{