]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/db/listdb.cpp
Committing in .
[wxWidgets.git] / samples / db / listdb.cpp
index 20a753280f84a4df2001a7bf169942c55c2dc857..e00f3c8740c4523bb6f3854e279ea5c678ca1dff 100644 (file)
@@ -30,7 +30,7 @@
      data table/object for building the list.
        
     The data table record access is all handled through the routines
-    in this module, interfacing with the methods defined in wxTable.
+    in this module, interfacing with the methods defined in wxDbTable.
 
      All objects which use data table access must be initialized and
      have opened the table prior to passing them in the dialog
 
 #include <wx/dbtable.h>
 
-extern DbList WXDLLEXPORT *PtrBegDbList;    /* from db.cpp, used in getting back error results from db connections */
+extern wxDbList WXDLLEXPORT *PtrBegDbList;    /* from db.cpp, used in getting back error results from db connections */
 
 #include "listdb.h"
 
 // Global structure for holding ODBC connection information
-extern DbStuff DbConnectInf;
+extern wxDbConnectInf DbConnectInf;
 
 // Global database connection
-extern wxDB *READONLY_DB;
+extern wxDb *READONLY_DB;
 
 
 // Used for passing the selected listbox selection back to the calling
@@ -93,9 +93,10 @@ const int LISTDB_NO_SPACES_BETWEEN_COLS = 3;
  * NOTE: The value returned by this function is for temporary use only and
  *       should be copied for long term use
  */
-char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
+const char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
 {
     static wxString msg;
+    msg = "";
 
     wxString tStr;
 
@@ -105,7 +106,7 @@ char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
         msg += ErrFile;
         msg += "   Line: ";
         tStr.Printf("%d",ErrLine);
-        msg += tStr.GetData();
+        msg += tStr.c_str();
         msg += "\n";
     }
 
@@ -114,7 +115,8 @@ char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
     
     /* Scan through each database connection displaying 
      * any ODBC errors that have occured. */
-    for (DbList *pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext)
+    wxDbList *pDbList;
+    for (pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext)
     {
         // Skip over any free connections
         if (pDbList->Free)
@@ -125,20 +127,23 @@ char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
             if (pDbList->PtrDb->errorList[i])
             {
                 msg.Append(pDbList->PtrDb->errorList[i]);
-                if (strcmp(pDbList->PtrDb->errorList[i],"") != 0)
+                if (wxStrcmp(pDbList->PtrDb->errorList[i],"") != 0)
                     msg.Append("\n");
+                // Clear the errmsg buffer so the next error will not
+                // end up showing the previous error that have occurred
+                wxStrcpy(pDbList->PtrDb->errorList[i],"");
             }
         }
     }
     msg += "\n";
 
-    return (char*) (const char*) msg;
+    return /*(char*) (const char*) msg*/msg.c_str();
 }  // GetExtendedDBErrorMsg
 
 
 
 // Clookup constructor
-Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1, NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
+Clookup::Clookup(char *tblName, char *colName) : wxDbTable(READONLY_DB, tblName, 1, NULL, !wxDB_QUERY_ONLY, DbConnectInf.defaultDir)
 {
 
     SetColDefs (0, colName, DB_DATA_TYPE_VARCHAR, lookupCol, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
@@ -147,14 +152,14 @@ Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1
 
 
 // Clookup2 constructor
-Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb)
-   : wxTable(pDb, tblName, (1 + (strlen(colName2) > 0)), NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
+Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDb *pDb)
+   : wxDbTable(pDb, tblName, (1 + (wxStrlen(colName2) > 0)), NULL, !wxDB_QUERY_ONLY, DbConnectInf.defaultDir)
 {
     int i = 0;
 
     SetColDefs (i, colName1, DB_DATA_TYPE_VARCHAR, lookupCol1, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
 
-    if (strlen(colName2) > 0)
+    if (wxStrlen(colName2) > 0)
         SetColDefs (++i, colName2, DB_DATA_TYPE_VARCHAR, lookupCol2, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
 
 }  // Clookup2()
@@ -173,7 +178,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha
 {
     wxBeginBusyCursor();
     
-    strcpy(ListDB_Selection,"");
+    wxStrcpy(ListDB_Selection,"");
     widgetPtrsSet = FALSE;
     lookup  = 0;
     lookup2 = 0;
@@ -203,8 +208,8 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha
         return;
     }
 
-    lookup->orderBy = orderBy;
-    lookup->where = where;
+    lookup->SetOrderByClause(orderBy);
+    lookup->SetWhereClause(where);
     if (!lookup->Query())
     {
         wxMessageBox("ODBC error during Query()","ODBC Error...");
@@ -263,16 +268,16 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha
 //
 ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
     char *dispCol1, char *dispCol2, char *where, char *orderBy, bool distinctValues,
-    char *selectStmt, int maxLenCol1, wxDB *pDb, bool allowOk)  : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290))
+    char *selectStmt, int maxLenCol1, wxDb *pDb, bool allowOk)  : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290))
 {
     wxBeginBusyCursor();
     
-    strcpy(ListDB_Selection,"");
-    strcpy(ListDB_Selection2,"");
+    wxStrcpy(ListDB_Selection,"");
+    wxStrcpy(ListDB_Selection2,"");
     widgetPtrsSet = FALSE;
     lookup  = 0;
     lookup2 = 0;
-    noDisplayCols = (strlen(dispCol2) ? 2 : 1);
+    noDisplayCols = (wxStrlen(dispCol2) ? 2 : 1);
     col1Len = 0;
 
     wxFont fixedFont(12,wxMODERN,wxNORMAL,wxNORMAL);
@@ -313,14 +318,14 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
     else
     {
         maxColLen = LOOKUP_COL_LEN;
-        if (strlen(dispCol2))
+        if (wxStrlen(dispCol2))
         {
             wxString q = "SELECT MAX({fn LENGTH(";
             q += dispCol1;
             q += ")}), NULL";
             q += " FROM ";
             q += tableName;
-            if (strlen(where))
+            if (wxStrlen(where))
             {
                 q += " WHERE ";
                 q += where;
@@ -339,7 +344,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
     }
 
     // Query the actual record set
-    if (selectStmt && strlen(selectStmt))    // Query by sql stmt passed in
+    if (selectStmt && wxStrlen(selectStmt))    // Query by sql stmt passed in
     {
         if (!lookup2->QueryBySqlStmt(selectStmt))
         {
@@ -350,8 +355,8 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
     }
     else    // Query using where and order by clauses
     {
-        lookup2->orderBy = orderBy;
-        lookup2->where = where;
+        lookup2->SetOrderByClause(orderBy);
+        lookup2->SetWhereClause(where);
         if (!lookup2->Query(FALSE, distinctValues))
         {
             wxMessageBox("ODBC error during Query()","ODBC Error...");
@@ -365,9 +370,9 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
     while (lookup2->GetNext())
     {
         s = lookup2->lookupCol1;
-        if (strlen(dispCol2))        // Append the optional column 2
+        if (wxStrlen(dispCol2))        // Append the optional column 2
         {
-            s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - strlen(lookup2->lookupCol1)));
+            s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - wxStrlen(lookup2->lookupCol1)));
             s.Append(lookup2->lookupCol2);
         }
         pLookUpSelectList->Append(s);
@@ -406,8 +411,10 @@ void ClookUpDlg::OnClose(wxCloseEvent& event)
     if (lookup2)
         delete lookup2;
 
+     SetReturnCode(1);
+
     while (wxIsBusy()) wxEndBusyCursor();
-   event.Skip();
+    event.Skip();
 
 //    return TRUE;
 
@@ -433,25 +440,25 @@ void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
             if (pLookUpSelectList->GetSelection() != -1)
             {
                 if (noDisplayCols == 1)
-                    strcpy (ListDB_Selection, pLookUpSelectList->GetStringSelection());
+                    wxStrcpy (ListDB_Selection, pLookUpSelectList->GetStringSelection());
                 else  // 2 display columns
                 {
                     wxString s = pLookUpSelectList->GetStringSelection();
                     // Column 1
                     s = s.SubString(0, col1Len-1);
                     s = s.Strip();
-                    strcpy(ListDB_Selection, s);
+                    wxStrcpy(ListDB_Selection, s);
                     // Column 2
                     s = pLookUpSelectList->GetStringSelection();
                     s = s.Mid(col1Len + LISTDB_NO_SPACES_BETWEEN_COLS);
                     s = s.Strip();
-                    strcpy(ListDB_Selection2, s);
+                    wxStrcpy(ListDB_Selection2, s);
                 }
             }
             else
             {
-                strcpy(ListDB_Selection,"");
-                strcpy(ListDB_Selection2,"");
+                wxStrcpy(ListDB_Selection,"");
+                wxStrcpy(ListDB_Selection2,"");
             }
             Close();
         }  // OK Button
@@ -459,8 +466,8 @@ void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
         // Cancel Button
         if (widgetName == pLookUpCancelBtn->GetName())
         {
-            strcpy (ListDB_Selection,"");
-            strcpy (ListDB_Selection2,"");
+            wxStrcpy (ListDB_Selection,"");
+            wxStrcpy (ListDB_Selection2,"");
             Close();
         }  // Cancel Button
     }