]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/db/dbtest.cpp
oops, forgot to fix wxHtmlTag dtor
[wxWidgets.git] / samples / db / dbtest.cpp
index 0cdf4bff857e30430ae94a15f6ee2ed03e03f725..4c8037a85de90e79bc8cb52e1d409c9c8d5e7b93 100644 (file)
 
 //extern wxDbList WXDLLEXPORT *PtrBegDbList;    /* from db.cpp, used in getting back error results from db connections */
 
+#if wxUSE_NEW_GRID
+#include <wx/grid.h>
+#include <wx/generic/gridctrl.h>
+#include <wx/dbgrid.h>
+
+#define CHOICEINT
+#endif
+
 #include "dbtest.h"                 /* Header file for this demonstration program */
 #include "listdb.h"                 /* Code to support the "Lookup" button on the editor dialog */
 
@@ -60,46 +68,6 @@ extern wxChar ListDB_Selection2[];  /* Used to return the second column value fo
 #endif
 
 
-const char *GetExtendedDBErrorMsg(wxDb *pDb, char *ErrFile, int ErrLine)
-{
-    static wxString msg;
-    msg = wxT("");
-
-    wxString tStr;
-
-    if (ErrFile || ErrLine)
-    {
-        msg += wxT("File: ");
-        msg += ErrFile;
-        msg += wxT("   Line: ");
-        tStr.Printf(wxT("%d"),ErrLine);
-        msg += tStr.c_str();
-        msg += wxT("\n");
-    }
-
-    msg.Append (wxT("\nODBC errors:\n"));
-    msg += wxT("\n");
-    
-    // Display errors for this connection
-    int i;
-    for (i = 0; i < DB_MAX_ERROR_HISTORY; i++)
-    {
-        if (pDb->errorList[i])
-        {
-            msg.Append(pDb->errorList[i]);
-            if (wxStrcmp(pDb->errorList[i],wxT("")) != 0)
-                msg.Append(wxT("\n"));
-            // Clear the errmsg buffer so the next error will not
-            // end up showing the previous error that have occurred
-            wxStrcpy(pDb->errorList[i],wxT(""));
-        }
-    }
-    msg += wxT("\n");
-
-    return msg.c_str();
-}  // GetExtendedDBErrorMsg
-
-
 bool DataTypeSupported(wxDb *pDb, SWORD datatype)
 {
     wxDbSqlTypeInfo sqlTypeInfo;
@@ -396,6 +364,9 @@ bool DatabaseDemoApp::OnInit()
     file_menu->Append(FILE_CREATE, wxT("&Create CONTACT table"));
     file_menu->Append(FILE_RECREATE_TABLE, wxT("&Recreate CONTACT table"));
     file_menu->Append(FILE_RECREATE_INDEXES, wxT("&Recreate CONTACT indexes"));
+#if wxUSE_NEW_GRID
+    file_menu->Append(FILE_DBGRID_TABLE,  wxT("&Open DB Grid example"));
+#endif
     file_menu->Append(FILE_EXIT, wxT("E&xit"));
 
     wxMenu *edit_menu = new wxMenu;
@@ -546,9 +517,10 @@ void DatabaseDemoApp::CreateDataTable(bool recreate)
     {
         wxEndBusyCursor();
         wxString tStr;
-        tStr  = wxT("Error creating CONTACTS table.\nTable was not created.\n\n");
-        tStr += GetExtendedDBErrorMsg(Contact->GetDb(),__FILE__,__LINE__);
-        wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+        tStr = wxT("Error creating CONTACTS table.\nTable was not created.\n\n");
+        wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),Contact->GetDb(),__FILE__,__LINE__),
+                     wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+
         success = FALSE;
     }
     else
@@ -557,9 +529,10 @@ void DatabaseDemoApp::CreateDataTable(bool recreate)
         {
             wxEndBusyCursor();
             wxString tStr;
-            tStr  = wxT("Error creating CONTACTS indexes.\nIndexes will be unavailable.\n\n");
-            tStr += GetExtendedDBErrorMsg(Contact->GetDb(),__FILE__,__LINE__);
-            wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+            tStr = wxT("Error creating CONTACTS indexes.\nIndexes will be unavailable.\n\n");
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+
             success = FALSE;
         }
     }
@@ -575,6 +548,9 @@ BEGIN_EVENT_TABLE(DatabaseDemoFrame, wxFrame)
     EVT_MENU(FILE_CREATE, DatabaseDemoFrame::OnCreate)
     EVT_MENU(FILE_RECREATE_TABLE, DatabaseDemoFrame::OnRecreateTable)
     EVT_MENU(FILE_RECREATE_INDEXES, DatabaseDemoFrame::OnRecreateIndexes)
+#if wxUSE_NEW_GRID
+    EVT_MENU(FILE_DBGRID_TABLE, DatabaseDemoFrame::OnDbGridTable)
+#endif
     EVT_MENU(FILE_EXIT, DatabaseDemoFrame::OnExit)
     EVT_MENU(EDIT_PARAMETERS, DatabaseDemoFrame::OnEditParameters)
     EVT_MENU(HELP_ABOUT, DatabaseDemoFrame::OnAbout)
@@ -617,14 +593,15 @@ void DatabaseDemoFrame::OnRecreateIndexes(wxCommandEvent& event)
 {
     wxGetApp().Contact->GetDb()->RollbackTrans();  // Make sure the current cursor is in a known/stable state
 
-    if (!wxGetApp().Contact->CreateIndexes(true))
+    if (!wxGetApp().Contact->CreateIndexes(TRUE))
     {
         while (wxIsBusy())
             wxEndBusyCursor();
         wxString tStr;
-        tStr  = wxT("Error creating CONTACTS indexes.\nNew indexes will be unavailable.\n\n");
-        tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-        wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+        tStr = wxT("Error creating CONTACTS indexes.\nNew indexes will be unavailable.\n\n");
+        wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                     wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+
     }
      else
         wxMessageBox(wxT("Index(es) were successfully recreated."),wxT("Notice..."),wxOK | wxICON_INFORMATION);
@@ -632,6 +609,17 @@ void DatabaseDemoFrame::OnRecreateIndexes(wxCommandEvent& event)
 }  // DatabaseDemoFrame::OnRecreateIndexes()
 
 
+#if wxUSE_NEW_GRID
+void DatabaseDemoFrame::OnDbGridTable(wxCommandEvent& )
+{
+    DbGridFrame *frame = new DbGridFrame(this);
+    if (frame->Initialize())
+    {
+        frame->Show();
+    }
+}
+#endif
+
 void DatabaseDemoFrame::OnExit(wxCommandEvent& event)
 {
     Close();
@@ -777,9 +765,10 @@ Ccontact::~Ccontact()
         if (!wxDbFreeConnection(GetDb()))
         {
             wxString tStr;
-            tStr  = wxT("Unable to Free the Ccontact data table handle\n\n");
-            tStr += GetExtendedDBErrorMsg(GetDb(),__FILE__,__LINE__);
-            wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+            tStr = wxT("Unable to Free the Ccontact data table handle\n\n");
+
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
         }
     }
 }  // Ccontract destructor
@@ -790,7 +779,7 @@ Ccontact::~Ccontact()
  * functions to interface to the data structure used to store records in 
  * memory, and for all the column definitions that define the table structure
  */
-void Ccontact::SetupColumns() 
+void Ccontact::SetupColumns()
 {
     // NOTE: Columns now are 8 character names, as that is all dBase can support.  Longer
     //       names can be used for other database engines
@@ -803,7 +792,7 @@ void Ccontact::SetupColumns()
     SetColDefs ( 6,wxT("COUNTRY"),    DB_DATA_TYPE_VARCHAR,     Country,        SQL_C_CHAR,                 sizeof(Country),        FALSE,TRUE);
     SetColDefs ( 7,wxT("JOINDATE"),   DB_DATA_TYPE_DATE,       &JoinDate,       SQL_C_TIMESTAMP,            sizeof(JoinDate),       FALSE,TRUE);
     SetColDefs ( 8,wxT("IS_DEV"),     DB_DATA_TYPE_INTEGER,    &IsDeveloper,    SQL_C_BOOLEAN(IsDeveloper), sizeof(IsDeveloper),    FALSE,TRUE);
-    SetColDefs ( 9,wxT("CONTRIBS"),   DB_DATA_TYPE_INTEGER,    &Contributions,  SQL_C_USHORT,               sizeof(Contributions),  FALSE,TRUE);
+    SetColDefs ( 9,wxT("CONTRIBS"),   DB_DATA_TYPE_INTEGER,    &Contributions,  SQL_C_UTINYINT,             sizeof(Contributions),  FALSE,TRUE);
     SetColDefs (10,wxT("LINE_CNT"),   DB_DATA_TYPE_INTEGER,    &LinesOfCode,    SQL_C_ULONG,                sizeof(LinesOfCode),    FALSE,TRUE);
     SetColDefs (11,wxT("LANGUAGE"),   DB_DATA_TYPE_INTEGER,    &NativeLanguage, SQL_C_ENUM,                 sizeof(NativeLanguage), FALSE,TRUE);
 #if wxODBC_BLOB_EXPERIMENT > 0
@@ -1033,9 +1022,10 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
         if (!wxGetApp().Contact->Query())
         {
             wxString tStr;
-            tStr  = wxT("ODBC error during Query()\n\n");
-            tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-            wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+            tStr = wxT("ODBC error during Query()\n\n");
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+            
             SetMode(mView);
             return;
         }
@@ -1102,9 +1092,10 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
             if (!wxGetApp().Contact->Query())
             {
                 wxString tStr;
-                tStr  = wxT("ODBC error during Query()\n\n");
-                tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-                wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+                tStr = wxT("ODBC error during Query()\n\n");
+                wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                             wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+
                 return;
             }
             // Display the first record from the query set
@@ -1138,9 +1129,9 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
         if (!wxGetApp().Contact->Query())
         {
             wxString tStr;
-            tStr  = wxT("ODBC error during Query()\n\n");
-            tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-            wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+            tStr = wxT("ODBC error during Query()\n\n");
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
             return;
         }
         if (!wxGetApp().Contact->GetNext())
@@ -1222,11 +1213,8 @@ bool CeditorDlg::Initialize()
                                           wxGetApp().DbConnectInf->GetDefaultDir()))
     {
         wxString tStr;
-        tStr.Printf(wxT("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n"),CONTACT_TABLE_NAME);
-        tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-        wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
-
-        bool createTable = (wxMessageBox(wxT("Do you wish to try to create/clear the CONTACTS table?"),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES);
+        tStr.Printf(wxT("Unable to open the table '%s'.  The table may\nneed to be created.\n\nDo you wish to try to create/clear the table?\n\n"),CONTACT_TABLE_NAME);
+        bool createTable = (wxMessageBox(tStr.c_str(),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES);
 
         if (!createTable)
         {
@@ -1255,8 +1243,9 @@ bool CeditorDlg::Initialize()
         {
             wxString tStr;
             tStr.Printf(wxT("Unable to open the table '%s' (likely due to\ninsufficient privileges of the logged in user).\n\n"),CONTACT_TABLE_NAME);
-            tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-            wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
         }
         else 
 #endif
@@ -1266,8 +1255,8 @@ bool CeditorDlg::Initialize()
         {
             wxString tStr;
             tStr.Printf(wxT("Unable to open the table '%s' as the table\ndoes not appear to exist in the tablespace available\nto the currently logged in user.\n\n"),CONTACT_TABLE_NAME);
-            tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-            wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
         }
 
         return FALSE;
@@ -1364,9 +1353,9 @@ bool CeditorDlg::Initialize()
     if (!wxGetApp().Contact->Query())
     {
         wxString tStr;
-        tStr  = wxT("ODBC error during Query()\n\n");
-        tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-        wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+        tStr = wxT("ODBC error during Query()\n\n");
+        wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                     wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
         return FALSE;
     }
 
@@ -1616,17 +1605,17 @@ bool CeditorDlg::Save()
                 if (result == DB_ERR_INTEGRITY_CONSTRAINT_VIOL)
                 {
                     wxString tStr;
-                    tStr  = wxT("A duplicate key value already exists in the table.\nUnable to save record\n\n");
-                    tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-                    wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+                    tStr = wxT("A duplicate key value already exists in the table.\nUnable to save record\n\n");
+                    wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                                 wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
                 }
                 else
                 {
                     // Some other unexpected error occurred
                     wxString tStr;
-                    tStr  = wxT("Database insert failed\n\n");
-                    tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-                    wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+                    tStr = wxT("Database insert failed\n\n");
+                    wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                                 wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
                 }
             }
         }
@@ -1637,9 +1626,9 @@ bool CeditorDlg::Save()
             if (!wxGetApp().Contact->UpdateWhere(wxGetApp().Contact->whereStr))
             {
                 wxString tStr;
-                tStr  = wxT("Database update failed\n\n");
-                tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-                wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+                tStr = wxT("Database update failed\n\n");
+                wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                             wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
                 failed = TRUE;
             }
         }
@@ -1744,9 +1733,9 @@ bool CeditorDlg::GetRec(const wxString &whereStr)
     if (!wxGetApp().Contact->Query())
     {
         wxString tStr;
-        tStr  = wxT("ODBC error during Query()\n\n");
-        tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__);
-        wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+        tStr = wxT("ODBC error during Query()\n\n");
+        wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                     wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
 
         return(FALSE);
     }
@@ -2054,9 +2043,9 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, wxChar *tblName[],
     {
         wxEndBusyCursor();
         wxString tStr;
-        tStr  = wxT("ODBC error during GetColumns()\n\n");
-        tStr += GetExtendedDBErrorMsg(pDb,__FILE__,__LINE__);
-        wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+        tStr = wxT("ODBC error during GetColumns()\n\n");
+        wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                     wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
         return;
     }
 
@@ -2457,9 +2446,9 @@ void CqueryDlg::ProcessCountBtn()
         if (!dbTable->Open())
         {
             wxString tStr;
-            tStr  = wxT("ODBC error during Open()\n\n");
-            tStr += GetExtendedDBErrorMsg(dbTable->GetDb(),__FILE__,__LINE__);
-            wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+            tStr = wxT("ODBC error during Open()\n\n");
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
             return;
         }
     }
@@ -2849,8 +2838,124 @@ void DisplayDbDiagnostics(wxDb *pDb)
 
 }  // DisplayDbDiagnostics()
 
+#if wxUSE_NEW_GRID
+
+BEGIN_EVENT_TABLE(DbGridFrame, wxFrame)
+ //   EVT_CLOSE(DbGridFrame::OnCloseWindow)
+END_EVENT_TABLE()
 
 
+DbGridFrame::DbGridFrame(wxWindow *parent)
+    : wxFrame (parent, -1, wxT("Database Table"),
+                   wxDefaultPosition, wxSize(400, 325))
+{
+    initialized = FALSE;
+}
+
+
+void DbGridFrame::OnCloseWindow(wxCloseEvent& event)
+{
+    this->Destroy();
+}
+
+
+bool DbGridFrame::Initialize()
+{
+    wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition);
+
+    grid->RegisterDataType(wxGRID_VALUE_DATETIME,
+                             new wxGridCellDateTimeRenderer(_T("%d %b %Y")),
+                             new wxGridCellTextEditor);
+#ifdef CHOICEINT
+    grid->RegisterDataType(wxGRID_VALUE_CHOICEINT,
+                             new wxGridCellEnumRenderer,
+                             new wxGridCellEnumEditor);
+                             
+    wxString NativeLangChoice( wxString::Format("%s:%s,%s,%s,%s,%s",wxGRID_VALUE_CHOICEINT, 
+                            wxT("English"),
+                            wxT("French"),
+                            wxT("German"),
+                            wxT("Spanish"),
+                            wxT("Other") )); 
+#endif
+
+    // Columns must match the sequence specified in SetColDef() calls
+    wxDbGridColInfo* cols =
+        new wxDbGridColInfo( 0,wxGRID_VALUE_STRING,wxT("Name"),
+        new wxDbGridColInfo( 1,wxGRID_VALUE_STRING,wxT("Address 1"),
+        new wxDbGridColInfo( 2,wxGRID_VALUE_STRING,wxT("Address 2"),
+        new wxDbGridColInfo( 3,wxGRID_VALUE_STRING,wxT("City"),
+        new wxDbGridColInfo( 4,wxGRID_VALUE_STRING,wxT("State"),
+        new wxDbGridColInfo( 5,wxGRID_VALUE_STRING,wxT("PostCode"),
+        new wxDbGridColInfo( 6,wxGRID_VALUE_STRING,wxT("Country"),
+        new wxDbGridColInfo( 7,wxGRID_VALUE_DBAUTO,wxT("Join Date"),
+        new wxDbGridColInfo( 8,wxGRID_VALUE_BOOL,  wxT("Developer"),
+        new wxDbGridColInfo( 9,wxGRID_VALUE_NUMBER,wxT("Contributions"),
+        new wxDbGridColInfo(10,wxGRID_VALUE_NUMBER,wxT("Lines Of Code"),
+#ifdef CHOICEINT
+        new wxDbGridColInfo(11,NativeLangChoice,   wxT("Native Language"),NULL))))))))))));
+#else        
+        new wxDbGridColInfo(11,wxGRID_VALUE_NUMBER,wxT("Native Language"),NULL))))))))))));
+#endif
+
+    Ccontact *Contact = new Ccontact();
+    //wxGetApp().Contact
+
+    if (!Contact)
+    {
+        wxMessageBox(wxT("Unable to instantiate an instance of Ccontact"), wxT("Error..."), wxOK | wxICON_EXCLAMATION);
+        return FALSE;
+    }
+
+    if (!Contact->Open())
+    {
+        if (Contact->GetDb()->TableExists(CONTACT_TABLE_NAME, Contact->GetDb()->GetUsername(),
+                                          wxGetApp().DbConnectInf->GetDefaultDir()))
+        {
+            wxString tStr;
+            tStr.Printf(wxT("Unable to open the table '%s'.\n\n"),CONTACT_TABLE_NAME);
+            wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                         wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+        }
+
+        return FALSE;
+    }
+
+    // Execute the following query using the cursor designated
+    // for full table query
+    Contact->SetRowMode(wxDbTable::WX_ROW_MODE_QUERY);
+
+    if (!Contact->Query())
+    {
+        wxString tStr;
+        tStr = wxT("ODBC error during Query()\n\n");
+        wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__),
+                     wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+        return FALSE;
+    }
+
+    // No data has been read in from the database yet, so
+    // we need to initialize the data members to valid values
+    // so Fit() can correctly size the grid
+    Contact->Initialize();
+
+    wxDbGridTableBase* db = new wxDbGridTableBase(Contact, cols, wxUSE_QUERY, TRUE);
+
+    delete cols;
+
+    grid->SetTable(db,TRUE);
+    grid->SetMargins(0, 0);
+
+    grid->Fit();
+    wxSize size = grid->GetSize();
+    size.x += 10;
+    size.y += 10;
+    SetClientSize(size);
+    initialized = TRUE;
+    return TRUE;
+}  // DbGridFrame::Initialize()
+
+#endif // #if wxUSE_NEW_GRID
 
 /*
     TEST CODE FOR TESTING THE wxDbCreateDataSource() FUNCTION