]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/db/dbtest.cpp
compate charset names case-insensitively in GetEncodingFromName()
[wxWidgets.git] / samples / db / dbtest.cpp
index d4c894c2d85e36f592a0c5977ed78dd30aba1517..8b91e280cde6ab4080ad0c9b94f3d029e820f597 100644 (file)
@@ -616,6 +616,22 @@ void CheckSupportForAllDataTypes(wxDb *pDb)
         wxLogMessage(nativeDataTypeName);
     }
 #endif
+#ifdef SQL_WVARCHAR
+    if (DataTypeSupported(pDb,SQL_WVARCHAR, &nativeDataTypeName))
+    {
+        nativeDataTypeName = wxT("SQL_WVARCHAR (") + nativeDataTypeName;
+        nativeDataTypeName += wxT(")\n");
+        wxLogMessage(nativeDataTypeName);
+    }
+#endif
+#ifdef SQL_WCHAR
+    if (DataTypeSupported(pDb,SQL_WCHAR, &nativeDataTypeName))
+    {
+        nativeDataTypeName = wxT("SQL_WCHAR (") + nativeDataTypeName;
+        nativeDataTypeName += wxT(")\n");
+        wxLogMessage(nativeDataTypeName);
+    }
+#endif
 
     wxLogMessage(wxT("Done\n"));
 }  // CheckSupportForAllDataTypes()
@@ -737,7 +753,7 @@ bool DatabaseDemoApp::ReadParamFile(Cparameters &params)
     if ((paramFile = wxFopen(PARAM_FILENAME, wxT("r"))) == NULL)
     {
         wxString tStr;
-        tStr.Printf(wxT("Unable to open the parameter file '%s' for reading.\n\nYou must specify the data source, user name, and\npassword that will be used and save those settings."),PARAM_FILENAME);
+        tStr.Printf(wxT("Unable to open the parameter file '%s' for reading.\n\nYou must specify the data source, user name, and\npassword that will be used and save those settings."),PARAM_FILENAME.c_str());
         wxMessageBox(tStr,wxT("File I/O Error..."),wxOK | wxICON_EXCLAMATION);
 
         return false;
@@ -772,7 +788,7 @@ bool DatabaseDemoApp::WriteParamFile(Cparameters &WXUNUSED(params))
     if ((paramFile = wxFopen(PARAM_FILENAME, wxT("wt"))) == NULL)
     {
         wxString tStr;
-        tStr.Printf(wxT("Unable to write/overwrite '%s'."),PARAM_FILENAME);
+        tStr.Printf(wxT("Unable to write/overwrite '%s'."),PARAM_FILENAME.c_str());
         wxMessageBox(tStr,wxT("File I/O Error..."),wxOK | wxICON_EXCLAMATION);
         return false;
     }
@@ -1015,7 +1031,7 @@ void DatabaseDemoFrame::BuildParameterDialog(wxWindow *parent)
  *     will be committed or rolled back when any of the objects has this function call made.
  */
 Ccontact::Ccontact (wxDb *pwxDb) : wxDbTable(pwxDb ? pwxDb : wxDbGetConnection(wxGetApp().DbConnectInf),
-                                             CONTACT_TABLE_NAME, CONTACT_NO_COLS, wxEmptyString,
+                                             CONTACT_TABLE_NAME, CONTACT_NO_COLS, (const wxString &)wxEmptyString,
                                              !wxDB_QUERY_ONLY, wxGetApp().DbConnectInf->GetDefaultDir())
 {
     // This is used to represent whether the database connection should be released
@@ -1287,7 +1303,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& WXUNUSED(event))
         if (!Ok)
             return;
 
-        if (saveName.IsEmpty())
+        if (saveName.empty())
         {
             wxGetApp().Contact->Initialize();
             PutData();
@@ -1359,7 +1375,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& WXUNUSED(event))
         // Display the query dialog box
         wxChar qryWhere[DB_MAX_WHERE_CLAUSE_LEN+1];
         wxStrcpy(qryWhere, (const wxChar*) wxGetApp().Contact->qryWhereStr);
-        wxChar *tblName[] = {(wxChar *)CONTACT_TABLE_NAME, 0};
+        wxChar *tblName[] = {(wxChar *)CONTACT_TABLE_NAME.c_str(), 0};
         new CqueryDlg(GetParent(), wxGetApp().Contact->GetDb(), tblName, qryWhere);
 
         // Query the first record in the new record set and
@@ -1403,7 +1419,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& WXUNUSED(event))
         }
 
         // Enable/Disable the reset button
-        pResetBtn->Enable(!wxGetApp().Contact->qryWhereStr.IsEmpty());
+        pResetBtn->Enable(!wxGetApp().Contact->qryWhereStr.empty());
 
         return;
     }  // Query button
@@ -1443,16 +1459,17 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& WXUNUSED(event))
 
     if (widgetName == pNameListBtn->GetName())
     {
-        new ClookUpDlg(/* wxWindow    *parent        */ this,
-                       /* wxChar      *windowTitle   */ wxT("Select contact name"),
-                       /* wxChar      *tableName     */ (wxChar *) CONTACT_TABLE_NAME,
-                       /* wxChar      *dispCol1      */ wxT("NAME"),
-                       /* wxChar      *dispCol2      */ wxT("JOINDATE"),
-                       /* wxChar      *where         */ wxT(""),
-                       /* wxChar      *orderBy       */ wxT("NAME"),
-                       /* wxDb        *pDb           */ wxGetApp().READONLY_DB,
-                       /* const wxString &defDir     */ wxGetApp().DbConnectInf->GetDefaultDir(),
-                       /* bool        distinctValues */ true);
+        new ClookUpDlg(/* wxWindow       *parent        */ this,
+                       /* const wxString &windowTitle   */ wxT("Select contact name"),
+                       /* const wxString &tableName     */ CONTACT_TABLE_NAME,
+                       /* const wxString &dispCol1      */ wxT("NAME"),
+                       /* const wxString &dispCol2      */ wxT("JOINDATE"),
+                       /* const wxString &where         */ wxT(""),
+                       /* const wxString &orderBy       */ wxT("NAME"),
+                       /* wxDb           *pDb           */ wxGetApp().READONLY_DB,
+                       /* const wxString &defDir        */ wxGetApp().DbConnectInf->GetDefaultDir(),
+                       /* bool            distinctValues*/ true,
+                       wxEmptyString, 20);
 
         if (ListDB_Selection && wxStrlen(ListDB_Selection))
         {
@@ -1484,7 +1501,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& WXUNUSED(event))
         if (wxGetApp().Contact->GetDb()->Catalog(wxEmptyString, wxT("catalog.txt")))
             wxMessageBox(wxT("The file 'catalog.txt' was created."));
         else
-            wxMessageBox(wxT("Creation of the file 'catalog.txt' was failed."));
+            wxMessageBox(wxT("Creation of the file 'catalog.txt' failed."));
         return;
     }
 
@@ -1518,12 +1535,12 @@ bool CeditorDlg::Initialize()
 
     // Check if the table exists or not.  If it doesn't, ask the user if they want to
     // create the table.  Continue trying to create the table until it exists, or user aborts
-    while (!wxGetApp().Contact->GetDb()->TableExists((wxChar *)CONTACT_TABLE_NAME,
+    while (!wxGetApp().Contact->GetDb()->TableExists(CONTACT_TABLE_NAME,
                                           wxGetApp().DbConnectInf->GetUserID(),
                                           wxGetApp().DbConnectInf->GetDefaultDir()))
     {
         wxString tStr;
-        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);
+        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.c_str());
         bool createTable = (wxMessageBox(tStr.c_str(),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES);
 
         if (!createTable)
@@ -1552,7 +1569,7 @@ bool CeditorDlg::Initialize()
                                                 wxGetApp().DbConnectInf->GetDefaultDir()))
         {
             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.Printf(wxT("Unable to open the table '%s' (likely due to\ninsufficient privileges of the logged in user).\n\n"),CONTACT_TABLE_NAME.c_str());
 
             wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
                          wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
@@ -1564,7 +1581,7 @@ bool CeditorDlg::Initialize()
                                            wxGetApp().DbConnectInf->GetDefaultDir()))
         {
             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.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.c_str());
             wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
                          wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
         }
@@ -1636,7 +1653,7 @@ bool CeditorDlg::Initialize()
     pPictSizeTxt      = new wxTextCtrl(this, EDITOR_DIALOG_PIC_SIZE_TEXT, wxEmptyString,          wxPoint(175,447), wxSize(120, 25), 0, wxDefaultValidator, wxT("PictSizeTxt"));
 #endif
 
-    // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to 
+    // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
     // handle all widget processing
     widgetPtrsSet = true;
 
@@ -1707,23 +1724,22 @@ void CeditorDlg::OnSelectPict()
 
         if (file.IsOpened())
         {
-            off_t iSize = file.Length();
+            // assume not huge file in sample
+            long iSize = (long)file.Length();
 
             if ((iSize > 0) && (iSize < MAX_PICTURE_SIZE))
             {
-                off_t iReadSize = 0;
-
-                wxGetApp().Contact->BlobSize = iSize;
+                wxGetApp().Contact->BlobSize = (size_t)iSize;
 
                 memset(wxGetApp().Contact->Picture, 0, MAX_PICTURE_SIZE);
 
-                iReadSize = file.Read(wxGetApp().Contact->Picture, iSize);
+                wxFileOffset iReadSize = file.Read(wxGetApp().Contact->Picture, (size_t)iSize);
 
                 if (iReadSize < iSize)
                     wxMessageBox(wxT("Something bad happened while reading..."), wxT("BLOB Loading Error"), wxOK | wxICON_EXCLAMATION);
 
                 wxString tStr;
-                tStr.Printf(wxT("%lu"),iSize);
+                tStr.Printf(wxT("%ld"),iSize);
                 pPictSizeTxt->SetValue(tStr);
             }
             else
@@ -1804,7 +1820,7 @@ void CeditorDlg::SetMode(enum DialogModes m)
         pPrevBtn->Enable( !edit );
         pNextBtn->Enable( !edit );
         pQueryBtn->Enable( !edit );
-        pResetBtn->Enable( !edit && !wxGetApp().Contact->qryWhereStr.IsEmpty() );
+        pResetBtn->Enable( !edit && !wxGetApp().Contact->qryWhereStr.empty() );
         pNameListBtn->Enable( !edit );
     }
 
@@ -2051,7 +2067,7 @@ bool CeditorDlg::GetNextRec()
     w += wxT("'");
 
     // If a query where string is currently set, append that criteria
-    if (!wxGetApp().Contact->qryWhereStr.IsEmpty())
+    if (!wxGetApp().Contact->qryWhereStr.empty())
     {
         w += wxT(" AND (");
         w += wxGetApp().Contact->qryWhereStr;
@@ -2087,7 +2103,7 @@ bool CeditorDlg::GetPrevRec()
     w += wxT("'");
 
     // If a query where string is currently set, append that criteria
-    if (!wxGetApp().Contact->qryWhereStr.IsEmpty())
+    if (!wxGetApp().Contact->qryWhereStr.empty())
     {
         w += wxT(" AND (");
         w += wxGetApp().Contact->qryWhereStr;
@@ -2818,7 +2834,7 @@ void CqueryDlg::ProcessCountBtn()
 
     if (!dbTable)  // wxDbTable object needs to be created and opened
     {
-        dbTable = new wxDbTable(pDB, masterTableName, 0, wxEmptyString,
+        dbTable = new wxDbTable(pDB, masterTableName, 0, (const wxString &)wxEmptyString,
                                 !wxDB_QUERY_ONLY,
                                 wxGetApp().DbConnectInf->GetDefaultDir());
         if (!dbTable)
@@ -2895,9 +2911,9 @@ END_EVENT_TABLE()
 
 CimageDlg::CimageDlg(wxWindow *parent, wxChar *pImageData, off_t iSize)
 : wxDialog(parent, IMAGE_DIALOG, wxT("BLOB Image"), wxDefaultPosition, wxDefaultSize),
-m_pImage(NULL),
+m_pDisplayBmp(NULL),
 m_pBmp(NULL),
-m_pDisplayBmp(NULL)
+m_pImage(NULL)
 {
     wxMemoryInputStream inStream(pImageData, iSize);
 
@@ -3353,7 +3369,7 @@ bool DbGridFrame::Initialize()
                                           wxGetApp().DbConnectInf->GetDefaultDir()))
         {
             wxString tStr;
-            tStr.Printf(wxT("Unable to open the table '%s'.\n\n"),CONTACT_TABLE_NAME);
+            tStr.Printf(wxT("Unable to open the table '%s'.\n\n"),CONTACT_TABLE_NAME.c_str());
             wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
                          wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
         }