// WARNING: Be certain that you do not free this handle
// directly with SQLFreeEnv(). Use either the
// method ::FreeHenv() or delete the DbConnectInf.
- DbConnectInf = new wxDbConnectInf(NULL, params.ODBCSource, params.UserName,
+ DbConnectInf = new wxDbConnectInf(NULL, params.ODBCSource, params.UserName,
params.Password, params.DirPath);
if (!DbConnectInf || !DbConnectInf->GetHenv())
pEditorDlg = NULL;
pParamDlg = NULL;
+#if wxUSE_LOG
delete wxLog::SetActiveTarget(new wxLogStderr);
+#endif // wxUSE_LOG
} // DatabaseDemoFrame constructor
DatabaseDemoFrame::~DatabaseDemoFrame()
{
+#if wxUSE_LOG
delete wxLog::SetActiveTarget(NULL);
+#endif // wxUSE_LOG
} // DatabaseDemoFrame destructor
wxMessageBox(wxT("Unable to initialize the editor dialog for some reason"),wxT("Error..."),wxOK | wxICON_EXCLAMATION);
Close();
}
- }
+ }
else
{
wxMessageBox(wxT("Unable to create the editor dialog for some reason"),wxT("Error..."),wxOK | wxICON_EXCLAMATION);
* Constructor note: If no wxDb object is passed in, a new connection to the database
* is created for this instance of Ccontact. This can be a slow process depending
* on the database engine being used, and some database engines have a limit on the
- * number of connections (either hard limits, or license restricted) so care should
- * be used to use as few connections as is necessary.
+ * number of connections (either hard limits, or license restricted) so care should
+ * be used to use as few connections as is necessary.
*
- * IMPORTANT: Objects which share a wxDb pointer are ALL acted upon whenever a member
- * function of pDb is called (i.e. CommitTrans() or RollbackTrans(), so if modifying
+ * IMPORTANT: Objects which share a wxDb pointer are ALL acted upon whenever a member
+ * function of pDb is called (i.e. CommitTrans() or RollbackTrans(), so if modifying
* or creating a table objects which use the same pDb, know that all the objects
* 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, wxT(""),
+ CONTACT_TABLE_NAME, CONTACT_NO_COLS, wxEmptyString,
!wxDB_QUERY_ONLY, wxGetApp().DbConnectInf->GetDefaultDir())
{
// This is used to represent whether the database connection should be released
// when this instance of the object is deleted. If using the same connection
- // for multiple instance of database objects, then the connection should only be
+ // for multiple instance of database objects, then the connection should only be
// released when the last database instance using the connection is deleted
freeDbConn = !pwxDb;
-
+
if (GetDb())
GetDb()->SetSqlLogging(sqlLogON);
/*
* Handles setting up all the connections for the interface from the wxDbTable
- * functions to interface to the data structure used to store records in
+ * 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()
bool Ccontact::CreateIndexes(bool recreate)
{
- // This index could easily be accomplished with an "orderBy" clause,
+ // This index could easily be accomplished with an "orderBy" clause,
// but is done to show how to construct a non-primary index.
wxString indexName;
wxDbIdxDef idxDef[2];
* An instance of Ccontact is created - "Contact" - which is used to hold the Ccontact
* object that is currently being worked with.
*/
-
+
BEGIN_EVENT_TABLE(CeditorDlg, wxPanel)
EVT_BUTTON(wxID_ANY, CeditorDlg::OnButton)
EVT_CLOSE(CeditorDlg::OnCloseWindow)
END_EVENT_TABLE()
-
+
CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 0, 0, 537, 480)
{
// Since the ::OnCommand() function is overridden, this prevents the widget
void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& WXUNUSED(event))
{
wxString widgetName;
-
+
widgetName = win.GetName();
if (!widgetPtrsSet)
if (Ok && wxGetApp().Contact->Delete())
{
- // NOTE: Deletions are not finalized until a CommitTrans() is performed.
- // If the commit were not performed, the program will continue to
+ // NOTE: Deletions are not finalized until a CommitTrans() is performed.
+ // If the commit were not performed, the program will continue to
// show the table contents as if they were deleted until this instance
- // of Ccontact is deleted. If the Commit wasn't performed, the
+ // of Ccontact is deleted. If the Commit wasn't performed, the
// database will automatically Rollback the changes when the database
// connection is terminated
wxGetApp().Contact->GetDb()->CommitTrans();
tStr = wxT("ODBC error during Query()\n\n");
wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
-
+
SetMode(mView);
return;
}
wxGetApp().Contact->whereStr = wxT("NAME = (SELECT MIN(NAME) FROM ");
wxGetApp().Contact->whereStr += CONTACT_TABLE_NAME;
}
-
+
// Append the query where string (if there is one)
wxGetApp().Contact->qryWhereStr = qryWhere;
if (wxStrlen(qryWhere))
bool CeditorDlg::Initialize()
{
- // Create the data structure and a new database connection.
+ // Create the data structure and a new database connection.
// (As there is not a pDb being passed in the constructor, a new database
// connection is created)
wxGetApp().Contact = new Ccontact();
return false;
}
- // Check if the table exists or not. If it doesn't, ask the user if they want to
+ // 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,
- wxGetApp().DbConnectInf->GetUserID(),
+ while (!wxGetApp().Contact->GetDb()->TableExists((wxChar *)CONTACT_TABLE_NAME,
+ wxGetApp().DbConnectInf->GetUserID(),
wxGetApp().DbConnectInf->GetDefaultDir()))
{
wxString tStr;
wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
}
- else
+ else
#endif
if (!wxGetApp().Contact->GetDb()->TableExists(CONTACT_TABLE_NAME,
wxGetApp().Contact->GetDb()->GetUsername(),
choice_strings[3] = wxT("Spanish");
choice_strings[4] = wxT("Other");
- pNativeLangChoice = new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE, wxPoint( 17, 346), wxSize(277, wxDefaultSize.y), 5, choice_strings);
+ pNativeLangChoice = new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE, wxPoint( 17, 346), wxSize(277, wxDefaultCoord), 5, choice_strings);
pNativeLangMsg = new wxStaticText(this, EDITOR_DIALOG_LANG_MSG, wxT("Native language:"), wxPoint( 17, 330), wxDefaultSize, 0, wxT("NativeLangMsg"));
wxString radio_strings[2];
pDataTypesBtn = new wxButton(this, EDITOR_DIALOG_DATATYPES, wxT("Data&types"), wxPoint(430, 337), wxSize( 70, 35), 0, wxDefaultValidator, wxT("DataTypesBtn"));
pDbDiagsBtn = new wxButton(this, EDITOR_DIALOG_DB_DIAGS, wxT("DB Dia&gs"), wxPoint(430, 387), wxSize( 70, 35), 0, wxDefaultValidator, wxT("DbDiagsBtn"));
- // 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;
- // Setup the orderBy and where clauses to return back a single record as the result set,
+ // Setup the orderBy and where clauses to return back a single record as the result set,
// as there will only be one record being shown on the dialog at a time, this optimizes
// network traffic by only returning a one row result
-
+
wxGetApp().Contact->SetOrderByClause(wxT("NAME")); // field name to sort by
// The wxString "whereStr" is not a member of the wxDbTable object, it is a member variable
// length string, and then after the string is built, the wxDbTable member variable "where" is
// assigned the pointer to the constructed string.
//
- // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
+ // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
// to achieve a single row (in this case the first name in alphabetical order).
-
+
if (wxGetApp().Contact->GetDb()->Dbms() != dbmsPOSTGRES &&
wxGetApp().Contact->GetDb()->Dbms() != dbmsMY_SQL)
{
else
wxGetApp().Contact->SetWhereClause(wxT(""));
- // Perform the Query to get the result set.
- // NOTE: If there are no rows returned, that is a valid result, so Query() would return true.
+ // Perform the Query to get the result set.
+ // NOTE: If there are no rows returned, that is a valid result, so Query() would return true.
// Only if there is a database error will Query() come back as false
if (!wxGetApp().Contact->Query())
{
// Since Query succeeded, now get the row that was returned
if (!wxGetApp().Contact->GetNext())
- // If the GetNext() failed at this point, then there are no rows to retrieve,
- // so clear the values in the members of "Contact" so that PutData() blanks the
+ // If the GetNext() failed at this point, then there are no rows to retrieve,
+ // so clear the values in the members of "Contact" so that PutData() blanks the
// widgets on the dialog
wxGetApp().Contact->Initialize();
/*
if (!invalid)
{
- wxGetApp().Contact->JoinDate.month = mm;
- wxGetApp().Contact->JoinDate.day = dd;
- wxGetApp().Contact->JoinDate.year = yyyy;
+ wxGetApp().Contact->JoinDate.month = (unsigned short) mm;
+ wxGetApp().Contact->JoinDate.day = (unsigned short) dd;
+ wxGetApp().Contact->JoinDate.year = (short) yyyy;
}
else
{
wxStrcpy(wxGetApp().Contact->Country,pCountryTxt->GetValue());
wxStrcpy(wxGetApp().Contact->PostalCode,pPostalCodeTxt->GetValue());
- wxGetApp().Contact->Contributions = wxAtoi(pContribTxt->GetValue());
+ wxGetApp().Contact->Contributions = (UCHAR)wxAtoi(pContribTxt->GetValue());
wxGetApp().Contact->LinesOfCode = wxAtol(pLinesTxt->GetValue());
wxGetApp().Contact->NativeLanguage = (enum Language) pNativeLangChoice->GetSelection();
if (mode == mCreate)
{
- RETCODE result = wxGetApp().Contact->Insert();
+ RETCODE result = (RETCODE)wxGetApp().Contact->Insert();
failed = (result != DB_SUCCESS);
if (failed)
pParamSaveBtn = new wxButton(this, PARAMETER_DIALOG_SAVE, wxT("&Save"), wxPoint(310, 21), wxSize( 70, 35), 0, wxDefaultValidator, wxT("ParamSaveBtn"));
pParamCancelBtn = new wxButton(this, PARAMETER_DIALOG_CANCEL, wxT("C&ancel"), wxPoint(310, 66), wxSize( 70, 35), 0, wxDefaultValidator, wxT("ParamCancelBtn"));
- // 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;
if (!saved)
{
bool Ok = (wxMessageBox(wxT("No changes have been saved.\n\nAre you sure you wish exit the parameter screen?"),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES);
-
+
if (!Ok)
{
event.Veto();
return;
}
-
+
wxGetApp().params = savedParamSettings;
}
void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& WXUNUSED(event))
{
wxString widgetName;
-
+
widgetName = win.GetName();
if (!widgetPtrsSet)
}
else
return false;
-
+
tStr = pParamUserNameTxt->GetValue();
if (tStr.Length() > (sizeof(wxGetApp().params.UserName)-1))
{
{
wxChar Dsn[SQL_MAX_DSN_LENGTH + 1];
wxChar DsDesc[255];
- wxStringList strList;
+ wxSortedArrayString strArr;
while (wxDbGetDataSource(wxGetApp().DbConnectInf->GetHenv(), Dsn,
SQL_MAX_DSN_LENGTH+1, DsDesc, 255))
- strList.Add(Dsn);
-
- strList.Sort();
- strList.Add(wxT(""));
+ {
+ strArr.Add(Dsn);
+ }
- wxString current;
- for (wxStringList::Node *node = strList.GetFirst(); node; node = node->GetNext() )
+ for (size_t i=0; i < strArr.GetCount(); i++ )
{
- current = node->GetData();
- if(!current.IsEmpty())
- pParamODBCSourceList->Append(current.c_str());
+ pParamODBCSourceList->Append(strArr[i].c_str());
}
} // CparameterDlg::FillDataSourceList()
EVT_CLOSE(CqueryDlg::OnCloseWindow)
END_EVENT_TABLE()
-
+
// CqueryDlg() constructor
-CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, wxChar *tblName[],
+CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, wxChar *tblName[],
const wxString &pWhereArg) :
wxDialog (parent, QUERY_DIALOG, wxT("Query"), wxDefaultPosition, wxSize(480, 360))
{
} // CqueryDlg() constructor
-CqueryDlg::~CqueryDlg()
-{
-} // CqueryDlg::~CqueryDlg() destructor
-
-
void CqueryDlg::OnButton(wxCommandEvent &event)
{
wxWindow *win = (wxWindow*) event.GetEventObject();
// Build the expression and append it to the where clause window
wxString s = pQueryCol1Choice->GetStringSelection();
-
+
if (pQueryNotCheck->GetValue() && (oper != qryOpEQ))
s += wxT(" NOT");
-
+
switch(oper)
{
case qryOpEQ:
if (!dbTable) // wxDbTable object needs to be created and opened
{
- dbTable = new wxDbTable(pDB, masterTableName, 0, wxT(""),
- !wxDB_QUERY_ONLY,
+ dbTable = new wxDbTable(pDB, masterTableName, 0, wxEmptyString,
+ !wxDB_QUERY_ONLY,
wxGetApp().DbConnectInf->GetDefaultDir());
if (!dbTable)
{
grid->RegisterDataType(wxGRID_VALUE_CHOICEINT,
new wxGridCellEnumRenderer,
new wxGridCellEnumEditor);
-
- wxString NativeLangChoice( wxString::Format(wxT("%s:%s,%s,%s,%s,%s"),wxGRID_VALUE_CHOICEINT,
+
+ wxString NativeLangChoice( wxString::Format(wxT("%s:%s,%s,%s,%s,%s"),wxGRID_VALUE_CHOICEINT,
wxT("English"),
wxT("French"),
wxT("German"),
wxT("Spanish"),
- wxT("Other") ));
+ wxT("Other") ));
#endif
// Columns must match the sequence specified in SetColDef() calls
new wxDbGridColInfo(10,wxGRID_VALUE_NUMBER,wxT("Lines Of Code"),
#ifdef CHOICEINT
new wxDbGridColInfo(11,NativeLangChoice, wxT("Native Language"),NULL))))))))))));
-#else
+#else
new wxDbGridColInfo(11,wxGRID_VALUE_NUMBER,wxT("Native Language"),NULL))))))))))));
#endif