1998-07-28 09:43:44 +00:00
///////////////////////////////////////////////////////////////////////////////
// Name: dbtest.cpp
2004-05-25 11:20:37 +00:00
// Purpose: wxWidgets database demo app
1998-07-28 09:43:44 +00:00
// Author: George Tasker
// Modified by:
// Created: 1998
// RCS-ID: $Id$
// Copyright: (c) 1998 Remstar International, Inc.
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
/*
2000-01-25 16:18:40 +00:00
* SYNOPSIS START
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
This sample program demonstrates the cross - platform ODBC database classes
donated by the development team at Remstar International .
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
The table this sample is based on is developer contact table , and shows
2000-07-15 19:51:35 +00:00
some of the simple uses of the database classes wxDb and wxDbTable .
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
* SYNOPSIS END
1998-07-28 09:43:44 +00:00
*/
# ifdef __GNUG__
# pragma implementation "dbtest.h"
# endif
# include "wx/wxprec.h"
# ifdef __BORLANDC__
# pragma hdrstop
# endif //__BORLANDC__
# ifndef WX_PRECOMP
2002-08-31 22:36:13 +00:00
# include "wx/wx.h"
1998-07-28 09:43:44 +00:00
# endif //WX_PRECOMP
2003-06-24 20:00:40 +00:00
# if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMAC__)
1998-12-30 23:30:49 +00:00
# include "db.xpm"
# endif
1999-01-21 19:02:18 +00:00
# include <stdio.h> /* Included strictly for reading the text file with the database parameters */
1998-07-28 09:43:44 +00:00
2002-08-31 22:36:13 +00:00
//#include "wx/db.h" /* Required in the file which will get the data source connection */
//#include "wx/dbtable.h" /* Has the wxDbTable object from which all data objects will inherit their data table functionality */
1998-07-28 09:43:44 +00:00
2001-04-11 14:20:56 +00:00
//extern wxDbList WXDLLEXPORT *PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */
1998-07-28 09:43:44 +00:00
2004-05-18 02:43:53 +00:00
# if wxUSE_GRID
2002-08-31 22:36:13 +00:00
# include "wx/grid.h"
# include "wx/generic/gridctrl.h"
# include "wx/dbgrid.h"
2001-06-10 17:12:56 +00:00
# define CHOICEINT
# endif
1999-01-21 19:02:18 +00:00
# include "dbtest.h" /* Header file for this demonstration program */
# include "listdb.h" /* Code to support the "Lookup" button on the editor dialog */
1998-12-30 17:40:53 +00:00
IMPLEMENT_APP ( DatabaseDemoApp )
2001-02-03 17:52:58 +00:00
extern wxChar ListDB_Selection [ ] ; /* Used to return the first column value for the selected line from the listDB routines */
extern wxChar ListDB_Selection2 [ ] ; /* Used to return the second column value for the selected line from the listDB routines */
1998-07-28 09:43:44 +00:00
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
# include "wx/file.h"
# include "wx/mstream.h"
# include "wx/image.h"
# include "wx/bitmap.h"
# include "wx/statbmp.h"
# endif
2001-05-18 18:32:33 +00:00
# if !wxUSE_ODBC
# error Sample cannot be compiled unless setup.h has wxUSE_ODBC set to 1
# endif
2002-06-13 17:51:56 +00:00
bool DataTypeSupported ( wxDb * pDb , SWORD datatype , wxString * nativeDataTypeName )
2001-04-11 14:20:56 +00:00
{
wxDbSqlTypeInfo sqlTypeInfo ;
2004-05-25 19:57:33 +00:00
bool breakpoint = false ;
2001-04-11 14:20:56 +00:00
2002-06-13 17:51:56 +00:00
* nativeDataTypeName = wxEmptyString ;
2001-04-11 14:20:56 +00:00
if ( pDb - > GetDataTypeInfo ( datatype , sqlTypeInfo ) )
2002-06-13 17:51:56 +00:00
{
* nativeDataTypeName = sqlTypeInfo . TypeName ;
2004-05-25 19:57:33 +00:00
breakpoint = true ;
2002-06-13 17:51:56 +00:00
}
2001-04-11 14:20:56 +00:00
return breakpoint ;
} // GetDataTypesSupported();
void CheckSupportForAllDataTypes ( wxDb * pDb )
{
2002-06-13 17:51:56 +00:00
wxString nativeDataTypeName ;
2004-02-08 11:53:48 +00:00
wxLogMessage ( wxT ( " \n The following datatypes are supported by the \n database you are currently connected to: " ) ) ;
2001-04-11 14:20:56 +00:00
# ifdef SQL_C_BINARY
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_BINARY , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_BINARY ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_BIT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_BIT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_BIT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_BOOKMARK
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_BOOKMARK , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_BOOKMARK ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_CHAR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_CHAR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_CHAR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_DATE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_DATE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_DATE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_DEFAULT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_DEFAULT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_DEFAULT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_DOUBLE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_DOUBLE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_DOUBLE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_FLOAT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_FLOAT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_FLOAT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_GUID
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_GUID , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_GUID ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_DAY
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_DAY , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_DAY ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_DAY_TO_HOUR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_DAY_TO_HOUR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_DAY_TO_HOUR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_DAY_TO_MINUTE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_DAY_TO_MINUTE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_DAY_TO_MINUTE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_DAY_TO_SECOND
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_DAY_TO_SECOND , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_DAY_TO_SECOND ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_HOUR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_HOUR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_HOUR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_HOUR_TO_MINUTE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_HOUR_TO_MINUTE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_HOUR_TO_MINUTE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_HOUR_TO_SECOND
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_HOUR_TO_SECOND , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_HOUR_TO_SECOND ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_MINUTE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_MINUTE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_MINUTE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_MINUTE_TO_SECOND
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_MINUTE_TO_SECOND , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_MINUTE_TO_SECOND ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_MONTH
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_MONTH , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_MONTH ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_SECOND
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_SECOND , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_SECOND ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_YEAR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_YEAR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_YEAR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_INTERVAL_YEAR_TO_MONTH
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_INTERVAL_YEAR_TO_MONTH , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_INTERVAL_YEAR_TO_MONTH ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_LONG
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_LONG , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_LONG ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_NUMERIC
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_NUMERIC , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_NUMERIC ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_SBIGINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_SBIGINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_SBIGINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_SHORT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_SHORT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_SHORT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_SLONG
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_SLONG , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_SLONG ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_SSHORT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_SSHORT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_SSHORT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_STINYINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_STINYINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_STINYINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_TIME
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_TIME , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_TIME ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_TIMESTAMP
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_TIMESTAMP , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_TIMESTAMP ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_TINYINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_TINYINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_TINYINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_TYPE_DATE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_TYPE_DATE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_TYPE_DATE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_TYPE_TIME
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_TYPE_TIME , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_TYPE_TIME ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_TYPE_TIMESTAMP
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_TYPE_TIMESTAMP , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_TYPE_TIMESTAMP ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_UBIGINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_UBIGINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_UBIGINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_ULONG
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_ULONG , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_ULONG ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_USHORT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_USHORT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_USHORT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_UTINYINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_UTINYINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_UTINYINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_C_VARBOOKMARK
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_VARBOOKMARK , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_VARBOOKMARK ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
2004-11-04 21:35:39 +00:00
# ifdef SQL_C_WXCHAR
if ( DataTypeSupported ( pDb , SQL_C_WXCHAR , & nativeDataTypeName ) )
{
nativeDataTypeName = wxT ( " SQL_C_WXCHAR ( " ) + nativeDataTypeName ;
nativeDataTypeName + = wxT ( " ) \n " ) ;
wxLogMessage ( nativeDataTypeName ) ;
}
# endif
2001-04-11 14:20:56 +00:00
// Extended SQL types
# ifdef SQL_DATE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_DATE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_DATE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_INTERVAL
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_INTERVAL , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_INTERVAL ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_TIME
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_TIME , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_TIME ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_TIMESTAMP
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_TIMESTAMP , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_TIMESTAMP ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_LONGVARCHAR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_LONGVARCHAR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_LONGVARCHAR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_BINARY
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_BINARY , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_BINARY ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_VARBINARY
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_VARBINARY , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_VARBINARY ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_LONGVARBINARY
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_LONGVARBINARY , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_LOGVARBINARY ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_BIGINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_BIGINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_BIGINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_TINYINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_TINYINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_TINYINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_BIT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_BIT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_BIT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_GUID
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_GUID , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_GUID ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_CHAR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_CHAR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_CHAR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_INTEGER
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_INTEGER , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_INTEGER ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_SMALLINT
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_SMALLINT , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_SAMLLINT ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_REAL
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_REAL , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_REAL ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_DOUBLE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_DOUBLE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_DOUBLE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_NUMERIC
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_NUMERIC , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_NUMERIC ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_DATE
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_DATE , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_DATE ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_TIME
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_TIME , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_TIME ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_TIMESTAMP
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_TIMESTAMP , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_TIMESTAMP ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
# ifdef SQL_VARCHAR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_VARCHAR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_VARCHAR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
// UNICODE
# ifdef SQL_C_TCHAR
2002-06-13 17:51:56 +00:00
if ( DataTypeSupported ( pDb , SQL_C_TCHAR , & nativeDataTypeName ) )
{
2004-02-08 11:53:48 +00:00
nativeDataTypeName = wxT ( " SQL_C_TCHAR ( " ) + nativeDataTypeName ;
2004-05-18 02:43:53 +00:00
nativeDataTypeName + = wxT ( " ) \n " ) ;
2002-06-13 17:51:56 +00:00
wxLogMessage ( nativeDataTypeName ) ;
}
2001-04-11 14:20:56 +00:00
# endif
2001-05-15 13:12:36 +00:00
2004-05-18 02:43:53 +00:00
wxLogMessage ( wxT ( " Done \n " ) ) ;
2001-04-11 14:20:56 +00:00
} // CheckSupportForAllDataTypes()
1998-12-30 17:40:53 +00:00
bool DatabaseDemoApp : : OnInit ( )
1998-07-28 09:43:44 +00:00
{
2001-05-15 00:58:09 +00:00
DbConnectInf = NULL ;
Contact = NULL ;
2001-02-03 17:52:58 +00:00
2000-01-25 16:18:40 +00:00
// Create the main frame window
2004-11-04 21:35:39 +00:00
DemoFrame = new DatabaseDemoFrame ( NULL , wxT ( " wxWidgets Database Demo " ) , wxPoint ( 50 , 50 ) , wxSize ( 537 , 530 ) ) ;
2000-01-25 16:18:40 +00:00
// Give it an icon
DemoFrame - > SetIcon ( wxICON ( db ) ) ;
// Make a menubar
wxMenu * file_menu = new wxMenu ;
2004-02-08 11:53:48 +00:00
file_menu - > Append ( FILE_CREATE_ID , wxT ( " &Create CONTACT table " ) ) ;
2001-02-01 20:17:15 +00:00
file_menu - > Append ( FILE_RECREATE_TABLE , wxT ( " &Recreate CONTACT table " ) ) ;
file_menu - > Append ( FILE_RECREATE_INDEXES , wxT ( " &Recreate CONTACT indexes " ) ) ;
2004-05-18 02:43:53 +00:00
# if wxUSE_GRID
2001-06-10 17:12:56 +00:00
file_menu - > Append ( FILE_DBGRID_TABLE , wxT ( " &Open DB Grid example " ) ) ;
# endif
2001-02-01 20:17:15 +00:00
file_menu - > Append ( FILE_EXIT , wxT ( " E&xit " ) ) ;
2000-01-25 16:18:40 +00:00
wxMenu * edit_menu = new wxMenu ;
2001-02-01 20:17:15 +00:00
edit_menu - > Append ( EDIT_PARAMETERS , wxT ( " &Parameters... " ) ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
wxMenu * help_menu = new wxMenu ;
help_menu - > Append ( HELP_ABOUT , wxT ( " &About " ) ) ;
2000-01-25 16:18:40 +00:00
wxMenuBar * menu_bar = new wxMenuBar ;
2001-02-01 20:17:15 +00:00
menu_bar - > Append ( file_menu , wxT ( " &File " ) ) ;
menu_bar - > Append ( edit_menu , wxT ( " &Edit " ) ) ;
2001-05-15 00:58:09 +00:00
menu_bar - > Append ( help_menu , wxT ( " &Help " ) ) ;
2000-01-25 16:18:40 +00:00
DemoFrame - > SetMenuBar ( menu_bar ) ;
params . ODBCSource [ 0 ] = 0 ;
params . UserName [ 0 ] = 0 ;
params . Password [ 0 ] = 0 ;
params . DirPath [ 0 ] = 0 ;
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
wxInitAllImageHandlers ( ) ;
wxImage : : InitStandardHandlers ( ) ;
wxBitmap : : InitStandardHandlers ( ) ;
# endif
2000-08-08 06:11:51 +00:00
// Show the frame
2004-05-25 19:57:33 +00:00
DemoFrame - > Show ( true ) ;
2000-08-08 06:11:51 +00:00
2001-02-03 17:52:58 +00:00
// Passing NULL for the SQL environment handle causes
// the wxDbConnectInf constructor to obtain a handle
// for you.
//
// WARNING: Be certain that you do not free this handle
// directly with SQLFreeEnv(). Use either the
// method ::FreeHenv() or delete the DbConnectInf.
2004-10-06 20:54:57 +00:00
DbConnectInf = new wxDbConnectInf ( NULL , params . ODBCSource , params . UserName ,
2001-02-03 17:52:58 +00:00
params . Password , params . DirPath ) ;
if ( ! DbConnectInf | | ! DbConnectInf - > GetHenv ( ) )
{
wxMessageBox ( wxT ( " Unable to define data source connection info. " ) , wxT ( " DB CONNECTION ERROR... " ) , wxOK | wxICON_EXCLAMATION ) ;
2001-05-15 00:58:09 +00:00
wxDELETE ( DbConnectInf ) ;
2001-02-03 17:52:58 +00:00
}
2001-04-11 14:20:56 +00:00
if ( ! ReadParamFile ( params ) )
DemoFrame - > BuildParameterDialog ( NULL ) ;
if ( ! wxStrlen ( params . ODBCSource ) )
{
2001-05-15 00:58:09 +00:00
wxDELETE ( DbConnectInf ) ;
2004-05-25 19:57:33 +00:00
return ( false ) ;
2001-04-11 14:20:56 +00:00
}
DbConnectInf - > SetDsn ( params . ODBCSource ) ;
DbConnectInf - > SetUserID ( params . UserName ) ;
DbConnectInf - > SetPassword ( params . Password ) ;
DbConnectInf - > SetDefaultDir ( params . DirPath ) ;
2001-02-03 17:52:58 +00:00
READONLY_DB = wxDbGetConnection ( DbConnectInf ) ;
if ( READONLY_DB = = 0 )
{
wxMessageBox ( wxT ( " Unable to connect to the data source. \n \n Check the name of your data source to verify it has been correctly entered/spelled. \n \n With some databases, the user name and password must \n be created with full rights to the CONTACT table prior to making a connection \n (using tools provided by the database manufacturer) " ) , wxT ( " DB CONNECTION ERROR... " ) , wxOK | wxICON_EXCLAMATION ) ;
DemoFrame - > BuildParameterDialog ( NULL ) ;
2001-05-15 00:58:09 +00:00
wxDELETE ( DbConnectInf ) ;
2001-02-03 17:52:58 +00:00
wxMessageBox ( wxT ( " Now exiting program. \n \n Restart program to try any new settings. " ) , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2004-05-25 19:57:33 +00:00
return ( false ) ;
2001-02-03 17:52:58 +00:00
}
DemoFrame - > BuildEditorDialog ( ) ;
// Show the frame
DemoFrame - > Refresh ( ) ;
2004-05-25 19:57:33 +00:00
return true ;
2001-02-03 17:52:58 +00:00
} // DatabaseDemoApp::OnInit()
2001-11-23 00:24:32 +00:00
/*
* Remove CR or CR / LF from a character string .
*/
2004-02-08 11:53:48 +00:00
wxChar * wxRemoveLineTerminator ( wxChar * aString )
2001-11-23 00:24:32 +00:00
{
2004-02-08 11:53:48 +00:00
int len = wxStrlen ( aString ) ;
while ( len > 0 & & ( aString [ len - 1 ] = = wxT ( ' \r ' ) | | aString [ len - 1 ] = = wxT ( ' \n ' ) ) ) {
aString [ len - 1 ] = wxT ( ' \0 ' ) ;
2001-11-23 00:24:32 +00:00
len - - ;
}
return aString ;
}
2001-02-03 17:52:58 +00:00
bool DatabaseDemoApp : : ReadParamFile ( Cparameters & params )
{
2000-01-25 16:18:40 +00:00
FILE * paramFile ;
2004-02-08 11:53:48 +00:00
if ( ( paramFile = wxFopen ( PARAM_FILENAME , wxT ( " r " ) ) ) = = NULL )
2000-01-25 16:18:40 +00:00
{
wxString tStr ;
2004-11-22 17:48:33 +00:00
tStr . Printf ( wxT ( " Unable to open the parameter file '%s' for reading. \n \n You must specify the data source, user name, and \n password that will be used and save those settings. " ) , PARAM_FILENAME . c_str ( ) ) ;
2001-02-01 20:17:15 +00:00
wxMessageBox ( tStr , wxT ( " File I/O Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2001-02-01 20:17:15 +00:00
wxChar buffer [ 1000 + 1 ] ;
2004-02-08 11:53:48 +00:00
wxFgets ( buffer , sizeof ( params . ODBCSource ) , paramFile ) ;
2001-11-23 00:24:32 +00:00
wxRemoveLineTerminator ( buffer ) ;
2000-07-15 19:51:35 +00:00
wxStrcpy ( params . ODBCSource , buffer ) ;
2000-01-25 16:18:40 +00:00
2004-02-08 11:53:48 +00:00
wxFgets ( buffer , sizeof ( params . UserName ) , paramFile ) ;
2001-11-23 00:24:32 +00:00
wxRemoveLineTerminator ( buffer ) ;
2000-07-15 19:51:35 +00:00
wxStrcpy ( params . UserName , buffer ) ;
2000-01-25 16:18:40 +00:00
2004-02-08 11:53:48 +00:00
wxFgets ( buffer , sizeof ( params . Password ) , paramFile ) ;
2001-11-23 00:24:32 +00:00
wxRemoveLineTerminator ( buffer ) ;
2000-07-15 19:51:35 +00:00
wxStrcpy ( params . Password , buffer ) ;
2000-01-25 16:18:40 +00:00
2004-02-08 11:53:48 +00:00
wxFgets ( buffer , sizeof ( params . DirPath ) , paramFile ) ;
2001-11-23 00:24:32 +00:00
wxRemoveLineTerminator ( buffer ) ;
2000-07-15 19:51:35 +00:00
wxStrcpy ( params . DirPath , buffer ) ;
2000-01-25 16:18:40 +00:00
fclose ( paramFile ) ;
2004-05-25 19:57:33 +00:00
return true ;
2001-02-03 17:52:58 +00:00
} // DatabaseDemoApp::ReadParamFile()
2000-01-25 16:18:40 +00:00
2001-02-03 17:52:58 +00:00
2004-02-08 11:53:48 +00:00
bool DatabaseDemoApp : : WriteParamFile ( Cparameters & WXUNUSED ( params ) )
2001-02-03 17:52:58 +00:00
{
FILE * paramFile ;
2004-02-08 11:53:48 +00:00
if ( ( paramFile = wxFopen ( PARAM_FILENAME , wxT ( " wt " ) ) ) = = NULL )
2000-01-25 16:18:40 +00:00
{
2001-02-03 17:52:58 +00:00
wxString tStr ;
2004-11-22 17:48:33 +00:00
tStr . Printf ( wxT ( " Unable to write/overwrite '%s'. " ) , PARAM_FILENAME . c_str ( ) ) ;
2001-02-03 17:52:58 +00:00
wxMessageBox ( tStr , wxT ( " File I/O Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2004-02-08 11:53:48 +00:00
wxFputs ( wxGetApp ( ) . params . ODBCSource , paramFile ) ;
wxFputc ( wxT ( ' \n ' ) , paramFile ) ;
wxFputs ( wxGetApp ( ) . params . UserName , paramFile ) ;
wxFputc ( wxT ( ' \n ' ) , paramFile ) ;
wxFputs ( wxGetApp ( ) . params . Password , paramFile ) ;
wxFputc ( wxT ( ' \n ' ) , paramFile ) ;
wxFputs ( wxGetApp ( ) . params . DirPath , paramFile ) ;
wxFputc ( wxT ( ' \n ' ) , paramFile ) ;
2001-02-03 17:52:58 +00:00
fclose ( paramFile ) ;
1998-07-28 09:43:44 +00:00
2004-05-25 19:57:33 +00:00
return true ;
2001-02-03 17:52:58 +00:00
} // DatabaseDemoApp::WriteParamFile()
void DatabaseDemoApp : : CreateDataTable ( bool recreate )
{
2004-05-25 19:57:33 +00:00
bool Ok = true ;
2001-02-03 17:52:58 +00:00
if ( recreate )
Ok = ( wxMessageBox ( wxT ( " Any data currently residing in the table will be erased. \n \n Are you sure? " ) , wxT ( " Confirm " ) , wxYES_NO | wxICON_QUESTION ) = = wxYES ) ;
if ( ! Ok )
return ;
wxBeginBusyCursor ( ) ;
2004-05-25 19:57:33 +00:00
bool success = true ;
2001-02-03 17:52:58 +00:00
2001-05-15 00:58:09 +00:00
Contact - > GetDb ( ) - > RollbackTrans ( ) ; // Make sure the current cursor is in a known/stable state
2001-02-03 17:52:58 +00:00
if ( ! Contact - > CreateTable ( recreate ) )
{
wxEndBusyCursor ( ) ;
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " Error creating CONTACTS table. \n Table was not created. \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
success = false ;
2001-02-03 17:52:58 +00:00
}
else
{
2001-05-23 13:48:04 +00:00
if ( ! Contact - > CreateIndexes ( recreate ) )
2001-02-03 17:52:58 +00:00
{
wxEndBusyCursor ( ) ;
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " Error creating CONTACTS indexes. \n Indexes will be unavailable. \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
success = false ;
2001-02-03 17:52:58 +00:00
}
}
while ( wxIsBusy ( ) )
wxEndBusyCursor ( ) ;
if ( success )
wxMessageBox ( wxT ( " Table and index(es) were successfully created. " ) , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
} // DatabaseDemoApp::CreateDataTable()
1998-07-28 09:43:44 +00:00
2000-08-08 06:11:51 +00:00
1998-12-30 17:40:53 +00:00
BEGIN_EVENT_TABLE ( DatabaseDemoFrame , wxFrame )
2004-02-08 11:53:48 +00:00
EVT_MENU ( FILE_CREATE_ID , DatabaseDemoFrame : : OnCreate )
2000-08-08 06:11:51 +00:00
EVT_MENU ( FILE_RECREATE_TABLE , DatabaseDemoFrame : : OnRecreateTable )
EVT_MENU ( FILE_RECREATE_INDEXES , DatabaseDemoFrame : : OnRecreateIndexes )
2004-05-18 02:43:53 +00:00
# if wxUSE_GRID
2001-06-10 17:12:56 +00:00
EVT_MENU ( FILE_DBGRID_TABLE , DatabaseDemoFrame : : OnDbGridTable )
# endif
1998-12-30 17:40:53 +00:00
EVT_MENU ( FILE_EXIT , DatabaseDemoFrame : : OnExit )
EVT_MENU ( EDIT_PARAMETERS , DatabaseDemoFrame : : OnEditParameters )
2001-05-15 00:58:09 +00:00
EVT_MENU ( HELP_ABOUT , DatabaseDemoFrame : : OnAbout )
1998-12-30 17:40:53 +00:00
EVT_CLOSE ( DatabaseDemoFrame : : OnCloseWindow )
END_EVENT_TABLE ( )
1998-07-28 09:43:44 +00:00
2000-08-08 06:11:51 +00:00
1998-07-28 09:43:44 +00:00
// DatabaseDemoFrame constructor
1998-12-30 17:40:53 +00:00
DatabaseDemoFrame : : DatabaseDemoFrame ( wxFrame * frame , const wxString & title ,
2000-08-08 06:11:51 +00:00
const wxPoint & pos , const wxSize & size ) :
2004-05-25 19:57:33 +00:00
wxFrame ( frame , wxID_ANY , title , pos , size )
1998-07-28 09:43:44 +00:00
{
2000-08-08 06:11:51 +00:00
// Put any code in necessary for initializing the main frame here
pEditorDlg = NULL ;
pParamDlg = NULL ;
2001-05-15 13:12:36 +00:00
2004-07-20 19:11:34 +00:00
# if wxUSE_LOG
2001-05-15 13:12:36 +00:00
delete wxLog : : SetActiveTarget ( new wxLogStderr ) ;
2004-07-20 19:11:34 +00:00
# endif // wxUSE_LOG
2001-05-15 13:12:36 +00:00
2000-08-08 06:11:51 +00:00
} // DatabaseDemoFrame constructor
2001-05-15 13:12:36 +00:00
DatabaseDemoFrame : : ~ DatabaseDemoFrame ( )
{
2004-07-20 19:11:34 +00:00
# if wxUSE_LOG
2001-05-15 13:12:36 +00:00
delete wxLog : : SetActiveTarget ( NULL ) ;
2004-07-20 19:11:34 +00:00
# endif // wxUSE_LOG
2001-05-15 13:12:36 +00:00
} // DatabaseDemoFrame destructor
1998-07-28 09:43:44 +00:00
2004-02-08 11:53:48 +00:00
void DatabaseDemoFrame : : OnCreate ( wxCommandEvent & WXUNUSED ( event ) )
1998-12-30 17:40:53 +00:00
{
2004-05-25 19:57:33 +00:00
wxGetApp ( ) . CreateDataTable ( false ) ;
2000-08-08 06:11:51 +00:00
} // DatabaseDemoFrame::OnCreate()
2004-02-08 11:53:48 +00:00
void DatabaseDemoFrame : : OnRecreateTable ( wxCommandEvent & WXUNUSED ( event ) )
2000-08-08 06:11:51 +00:00
{
2004-05-25 19:57:33 +00:00
wxGetApp ( ) . CreateDataTable ( true ) ;
2000-08-08 06:11:51 +00:00
} // DatabaseDemoFrame::OnRecreate()
2004-02-08 11:53:48 +00:00
void DatabaseDemoFrame : : OnRecreateIndexes ( wxCommandEvent & WXUNUSED ( event ) )
2000-08-08 06:11:51 +00:00
{
2001-05-23 13:48:04 +00:00
wxGetApp ( ) . Contact - > GetDb ( ) - > RollbackTrans ( ) ; // Make sure the current cursor is in a known/stable state
2004-05-25 19:57:33 +00:00
if ( ! wxGetApp ( ) . Contact - > CreateIndexes ( true ) )
2000-08-08 06:11:51 +00:00
{
2001-05-15 00:58:09 +00:00
while ( wxIsBusy ( ) )
wxEndBusyCursor ( ) ;
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " Error creating CONTACTS indexes. \n New indexes will be unavailable. \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-08-08 06:11:51 +00:00
}
2001-05-23 13:48:04 +00:00
else
2001-05-15 00:58:09 +00:00
wxMessageBox ( wxT ( " Index(es) were successfully recreated. " ) , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2000-08-08 06:11:51 +00:00
} // DatabaseDemoFrame::OnRecreateIndexes()
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
2004-05-18 02:43:53 +00:00
# if wxUSE_GRID
2004-02-08 11:53:48 +00:00
void DatabaseDemoFrame : : OnDbGridTable ( wxCommandEvent & WXUNUSED ( event ) )
2001-06-10 17:12:56 +00:00
{
DbGridFrame * frame = new DbGridFrame ( this ) ;
if ( frame - > Initialize ( ) )
{
frame - > Show ( ) ;
}
}
# endif
2004-02-08 11:53:48 +00:00
void DatabaseDemoFrame : : OnExit ( wxCommandEvent & WXUNUSED ( event ) )
1998-07-28 09:43:44 +00:00
{
2000-03-16 19:09:42 +00:00
Close ( ) ;
2000-08-08 06:11:51 +00:00
} // DatabaseDemoFrame::OnExit()
1998-07-28 09:43:44 +00:00
2004-02-08 11:53:48 +00:00
void DatabaseDemoFrame : : OnEditParameters ( wxCommandEvent & WXUNUSED ( event ) )
1998-12-30 17:40:53 +00:00
{
2000-01-25 16:18:40 +00:00
if ( ( pEditorDlg - > mode ! = mCreate ) & & ( pEditorDlg - > mode ! = mEdit ) )
BuildParameterDialog ( this ) ;
else
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Cannot change database parameters while creating or editing a record " ) , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2000-08-08 06:11:51 +00:00
} // DatabaseDemoFrame::OnEditParameters()
1998-12-30 17:40:53 +00:00
2004-02-08 11:53:48 +00:00
void DatabaseDemoFrame : : OnAbout ( wxCommandEvent & WXUNUSED ( event ) )
1998-12-30 17:40:53 +00:00
{
2004-05-25 11:20:37 +00:00
wxMessageBox ( wxT ( " wxWidgets sample program for database classes \n \n Contributed on 27 July 1998 " ) , wxT ( " About... " ) , wxOK | wxICON_INFORMATION ) ;
2000-08-08 06:11:51 +00:00
} // DatabaseDemoFrame::OnAbout()
1998-07-28 09:43:44 +00:00
2001-02-03 17:52:58 +00:00
// Put any additional checking necessary to make certain it is alright
// to close the program here that is not done elsewhere
1998-12-30 17:40:53 +00:00
void DatabaseDemoFrame : : OnCloseWindow ( wxCloseEvent & event )
1998-07-28 09:43:44 +00:00
{
2000-03-16 19:09:42 +00:00
// Clean up time
2000-08-08 06:11:51 +00:00
if ( pEditorDlg & & pEditorDlg - > Close ( ) )
2000-03-16 19:09:42 +00:00
pEditorDlg = NULL ;
else
2000-07-15 19:51:35 +00:00
{
2000-08-08 06:11:51 +00:00
if ( pEditorDlg )
{
event . Veto ( ) ;
return ;
}
2000-07-15 19:51:35 +00:00
}
2001-05-15 00:58:09 +00:00
wxDELETE ( wxGetApp ( ) . Contact ) ;
2000-08-08 06:11:51 +00:00
// This function will close all the connections to the database that have been
// previously cached.
wxDbCloseConnections ( ) ;
2001-02-03 17:52:58 +00:00
// Deletion of the wxDbConnectInf instance must be the LAST thing done that
// has anything to do with the database. Deleting this before disconnecting,
// freeing/closing connections, etc will result in a crash!
2001-05-15 00:58:09 +00:00
wxDELETE ( wxGetApp ( ) . DbConnectInf ) ;
2000-03-16 19:09:42 +00:00
1998-12-30 17:40:53 +00:00
this - > Destroy ( ) ;
2000-03-16 19:09:42 +00:00
1999-02-05 23:55:04 +00:00
} // DatabaseDemoFrame::OnCloseWindow()
1998-07-28 09:43:44 +00:00
void DatabaseDemoFrame : : BuildEditorDialog ( )
{
2000-08-08 06:11:51 +00:00
pEditorDlg = NULL ;
2000-01-25 16:18:40 +00:00
pEditorDlg = new CeditorDlg ( this ) ;
2000-08-08 06:11:51 +00:00
if ( pEditorDlg )
{
pEditorDlg - > Initialize ( ) ;
if ( ! pEditorDlg - > initialized )
{
pEditorDlg - > Close ( ) ;
2000-11-22 00:28:35 +00:00
pEditorDlg = NULL ;
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Unable to initialize the editor dialog for some reason " ) , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2001-02-03 17:52:58 +00:00
Close ( ) ;
2000-08-08 06:11:51 +00:00
}
2004-10-06 20:54:57 +00:00
}
2000-08-08 06:11:51 +00:00
else
{
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Unable to create the editor dialog for some reason " ) , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2001-02-03 17:52:58 +00:00
Close ( ) ;
2000-08-08 06:11:51 +00:00
}
1998-07-28 09:43:44 +00:00
} // DatabaseDemoFrame::BuildEditorDialog()
void DatabaseDemoFrame : : BuildParameterDialog ( wxWindow * parent )
{
2000-01-25 16:18:40 +00:00
pParamDlg = new CparameterDlg ( parent ) ;
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
if ( ! pParamDlg )
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Unable to create the parameter dialog for some reason " ) , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
1998-07-28 09:43:44 +00:00
} // DatabaseDemoFrame::BuildParameterDialog()
/*
2000-07-15 19:51:35 +00:00
* Constructor note : If no wxDb object is passed in , a new connection to the database
1998-07-28 09:43:44 +00:00
* 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
2004-10-06 20:54:57 +00:00
* number of connections ( either hard limits , or license restricted ) so care should
* be used to use as few connections as is necessary .
2000-01-25 16:18:40 +00:00
*
2004-10-06 20:54:57 +00:00
* 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
1998-07-28 09:43:44 +00:00
* 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 .
*/
2001-02-03 17:52:58 +00:00
Ccontact : : Ccontact ( wxDb * pwxDb ) : wxDbTable ( pwxDb ? pwxDb : wxDbGetConnection ( wxGetApp ( ) . DbConnectInf ) ,
2004-11-10 12:12:37 +00:00
CONTACT_TABLE_NAME , CONTACT_NO_COLS , ( const wxString & ) wxEmptyString ,
2001-02-03 17:52:58 +00:00
! wxDB_QUERY_ONLY , wxGetApp ( ) . DbConnectInf - > GetDefaultDir ( ) )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// 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
2004-10-06 20:54:57 +00:00
// for multiple instance of database objects, then the connection should only be
2000-01-25 16:18:40 +00:00
// released when the last database instance using the connection is deleted
2000-07-15 19:51:35 +00:00
freeDbConn = ! pwxDb ;
2004-10-06 20:54:57 +00:00
2001-04-11 14:20:56 +00:00
if ( GetDb ( ) )
GetDb ( ) - > SetSqlLogging ( sqlLogON ) ;
2000-01-25 16:18:40 +00:00
SetupColumns ( ) ;
1998-07-28 09:43:44 +00:00
} // Ccontact Constructor
void Ccontact : : Initialize ( )
{
2000-01-25 16:18:40 +00:00
Name [ 0 ] = 0 ;
Addr1 [ 0 ] = 0 ;
Addr2 [ 0 ] = 0 ;
City [ 0 ] = 0 ;
State [ 0 ] = 0 ;
PostalCode [ 0 ] = 0 ;
Country [ 0 ] = 0 ;
JoinDate . year = 1980 ;
JoinDate . month = 1 ;
JoinDate . day = 1 ;
JoinDate . hour = 0 ;
JoinDate . minute = 0 ;
JoinDate . second = 0 ;
JoinDate . fraction = 0 ;
NativeLanguage = langENGLISH ;
2004-05-25 19:57:33 +00:00
IsDeveloper = false ;
2000-01-25 16:18:40 +00:00
Contributions = 0 ;
LinesOfCode = 0L ;
2004-11-04 21:35:39 +00:00
BlobSize = 0L ;
memset ( Picture , 0 , MAX_PICTURE_SIZE ) ;
1998-07-28 09:43:44 +00:00
} // Ccontact::Initialize
Ccontact : : ~ Ccontact ( )
{
2000-01-25 16:18:40 +00:00
if ( freeDbConn )
{
2000-07-15 19:51:35 +00:00
if ( ! wxDbFreeConnection ( GetDb ( ) ) )
2000-01-25 16:18:40 +00:00
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " Unable to Free the Ccontact data table handle \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
}
}
1998-07-28 09:43:44 +00:00
} // Ccontract destructor
/*
2000-07-15 19:51:35 +00:00
* Handles setting up all the connections for the interface from the wxDbTable
2004-10-06 20:54:57 +00:00
* functions to interface to the data structure used to store records in
1998-07-28 09:43:44 +00:00
* memory , and for all the column definitions that define the table structure
*/
2001-06-10 17:12:56 +00:00
void Ccontact : : SetupColumns ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// NOTE: Columns now are 8 character names, as that is all dBase can support. Longer
// names can be used for other database engines
2004-11-04 21:35:39 +00:00
SetColDefs ( 0 , wxT ( " NAME " ) , DB_DATA_TYPE_VARCHAR , Name , SQL_C_WXCHAR , sizeof ( Name ) , true , true ) ; // Primary index
SetColDefs ( 1 , wxT ( " ADDRESS1 " ) , DB_DATA_TYPE_VARCHAR , Addr1 , SQL_C_WXCHAR , sizeof ( Addr1 ) , false , true ) ;
SetColDefs ( 2 , wxT ( " ADDRESS2 " ) , DB_DATA_TYPE_VARCHAR , Addr2 , SQL_C_WXCHAR , sizeof ( Addr2 ) , false , true ) ;
SetColDefs ( 3 , wxT ( " CITY " ) , DB_DATA_TYPE_VARCHAR , City , SQL_C_WXCHAR , sizeof ( City ) , false , true ) ;
SetColDefs ( 4 , wxT ( " STATE " ) , DB_DATA_TYPE_VARCHAR , State , SQL_C_WXCHAR , sizeof ( State ) , false , true ) ;
SetColDefs ( 5 , wxT ( " POSTCODE " ) , DB_DATA_TYPE_VARCHAR , PostalCode , SQL_C_WXCHAR , sizeof ( PostalCode ) , false , true ) ;
SetColDefs ( 6 , wxT ( " COUNTRY " ) , DB_DATA_TYPE_VARCHAR , Country , SQL_C_WXCHAR , sizeof ( Country ) , false , true ) ;
2004-05-25 19:57:33 +00:00
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_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 ) ;
2004-05-12 14:03:23 +00:00
# ifdef wxODBC_BLOB_SUPPORT
2004-11-04 21:35:39 +00:00
SetColDefs ( 12 , wxT ( " PICSIZE " ) , DB_DATA_TYPE_INTEGER , & BlobSize , SQL_C_ULONG , sizeof ( BlobSize ) , false , true ) ;
SetColDefs ( 13 , wxT ( " PICTURE " ) , DB_DATA_TYPE_BLOB , Picture , SQL_C_BINARY , sizeof ( Picture ) , false , true ) ;
2001-04-11 14:20:56 +00:00
# endif
1998-07-28 09:43:44 +00:00
} // Ccontact::SetupColumns
2001-05-23 13:48:04 +00:00
bool Ccontact : : CreateIndexes ( bool recreate )
1998-07-28 09:43:44 +00:00
{
2004-10-06 20:54:57 +00:00
// This index could easily be accomplished with an "orderBy" clause,
2000-01-25 16:18:40 +00:00
// but is done to show how to construct a non-primary index.
wxString indexName ;
2000-07-15 19:51:35 +00:00
wxDbIdxDef idxDef [ 2 ] ;
1998-07-28 09:43:44 +00:00
2004-02-08 11:53:48 +00:00
wxStrcpy ( idxDef [ 0 ] . ColName , wxT ( " IS_DEV " ) ) ;
2004-05-25 19:57:33 +00:00
idxDef [ 0 ] . Ascending = true ;
1998-07-28 09:43:44 +00:00
2004-02-08 11:53:48 +00:00
wxStrcpy ( idxDef [ 1 ] . ColName , wxT ( " NAME " ) ) ;
2004-05-25 19:57:33 +00:00
idxDef [ 1 ] . Ascending = true ;
1998-07-28 09:43:44 +00:00
2000-07-15 19:51:35 +00:00
indexName = GetTableName ( ) ;
2004-02-08 11:53:48 +00:00
indexName + = wxT ( " _IDX1 " ) ;
1998-07-28 09:43:44 +00:00
2004-05-25 19:57:33 +00:00
return CreateIndex ( indexName . c_str ( ) , true , 2 , idxDef , recreate ) ;
1998-07-28 09:43:44 +00:00
} // Ccontact::CreateIndexes()
/*
* Having a function to do a query on the primary key ( and possibly others ) is
* very efficient and tighter coding so that it is available where ever the object
* is . Great for use with multiple tables when not using views or outer joins
*/
2001-02-03 17:52:58 +00:00
bool Ccontact : : FetchByName ( const wxString & name )
1998-07-28 09:43:44 +00:00
{
2001-02-05 23:26:46 +00:00
whereStr . Printf ( wxT ( " NAME = '%s' " ) , name . c_str ( ) ) ;
2000-07-15 19:51:35 +00:00
SetWhereClause ( whereStr . c_str ( ) ) ;
2004-11-04 21:35:39 +00:00
SetOrderByClause ( wxEmptyString ) ;
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
if ( ! Query ( ) )
2004-05-25 19:57:33 +00:00
return ( false ) ;
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
// Fetch the record
return ( GetNext ( ) ) ;
1998-07-28 09:43:44 +00:00
} // Ccontact::FetchByName()
/*
*
* * * * * * * * * * * * * * DIALOGS * * * * * * * * * * * * * * *
*
*/
/* CeditorDlg constructor
*
* Creates the dialog used for creating / editing / deleting / copying a Ccontact object .
* This dialog actually is drawn in the main frame of the program
*
* An instance of Ccontact is created - " Contact " - which is used to hold the Ccontact
* object that is currently being worked with .
*/
2004-10-06 20:54:57 +00:00
1999-01-12 17:53:45 +00:00
BEGIN_EVENT_TABLE ( CeditorDlg , wxPanel )
2004-05-25 19:57:33 +00:00
EVT_BUTTON ( wxID_ANY , CeditorDlg : : OnButton )
2000-03-16 19:09:42 +00:00
EVT_CLOSE ( CeditorDlg : : OnCloseWindow )
1999-01-12 17:53:45 +00:00
END_EVENT_TABLE ( )
2004-10-06 20:54:57 +00:00
2004-11-04 21:35:39 +00:00
CeditorDlg : : CeditorDlg ( wxWindow * parent ) : wxPanel ( parent , 0 , 0 , 537 , 530 )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Since the ::OnCommand() function is overridden, this prevents the widget
// detection in ::OnCommand() until all widgets have been initialized to prevent
// uninitialized pointers from crashing the program
2004-05-25 19:57:33 +00:00
widgetPtrsSet = false ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
initialized = false ;
2000-01-25 16:18:40 +00:00
2001-04-11 14:20:56 +00:00
SetMode ( mView ) ;
2004-05-25 19:57:33 +00:00
Show ( false ) ;
1998-07-28 09:43:44 +00:00
} // CeditorDlg constructor
1999-02-05 23:55:04 +00:00
void CeditorDlg : : OnCloseWindow ( wxCloseEvent & event )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Clean up time
2000-03-16 19:09:42 +00:00
if ( ( mode ! = mCreate ) & & ( mode ! = mEdit ) )
2000-01-25 16:18:40 +00:00
{
this - > Destroy ( ) ;
}
else
{
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Must finish processing the current record being created/modified before exiting " ) , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2000-01-25 16:18:40 +00:00
event . Veto ( ) ;
}
1999-02-05 23:55:04 +00:00
} // CeditorDlg::OnCloseWindow()
1998-07-28 09:43:44 +00:00
2000-08-08 06:11:51 +00:00
void CeditorDlg : : OnButton ( wxCommandEvent & event )
1999-01-12 17:53:45 +00:00
{
2000-08-08 06:11:51 +00:00
wxWindow * win = ( wxWindow * ) event . GetEventObject ( ) ;
OnCommand ( * win , event ) ;
} // CeditorDlg::OnButton()
1999-01-12 17:53:45 +00:00
1999-10-07 11:04:06 +00:00
2004-02-08 11:53:48 +00:00
void CeditorDlg : : OnCommand ( wxWindow & win , wxCommandEvent & WXUNUSED ( event ) )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxString widgetName ;
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
widgetName = win . GetName ( ) ;
if ( ! widgetPtrsSet )
return ;
if ( widgetName = = pCreateBtn - > GetName ( ) )
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > Initialize ( ) ;
2000-01-25 16:18:40 +00:00
PutData ( ) ;
SetMode ( mCreate ) ;
2004-11-04 21:35:39 +00:00
pNameTxt - > SetValue ( wxEmptyString ) ;
2000-01-25 16:18:40 +00:00
pNameTxt - > SetFocus ( ) ;
return ;
}
if ( widgetName = = pEditBtn - > GetName ( ) )
{
2001-05-15 00:58:09 +00:00
saveName = wxGetApp ( ) . Contact - > Name ;
2000-01-25 16:18:40 +00:00
SetMode ( mEdit ) ;
pNameTxt - > SetFocus ( ) ;
return ;
}
if ( widgetName = = pCopyBtn - > GetName ( ) )
{
SetMode ( mCreate ) ;
2004-11-04 21:35:39 +00:00
pNameTxt - > SetValue ( wxEmptyString ) ;
2000-01-25 16:18:40 +00:00
pNameTxt - > SetFocus ( ) ;
return ;
}
if ( widgetName = = pDeleteBtn - > GetName ( ) )
{
2001-02-01 20:17:15 +00:00
bool Ok = ( wxMessageBox ( wxT ( " Are you sure? " ) , wxT ( " Confirm " ) , wxYES_NO | wxICON_QUESTION ) = = wxYES ) ;
2000-01-25 16:18:40 +00:00
if ( ! Ok )
return ;
2001-05-15 00:58:09 +00:00
if ( Ok & & wxGetApp ( ) . Contact - > Delete ( ) )
2000-01-25 16:18:40 +00:00
{
2004-10-06 20:54:57 +00:00
// NOTE: Deletions are not finalized until a CommitTrans() is performed.
// If the commit were not performed, the program will continue to
2000-01-25 16:18:40 +00:00
// show the table contents as if they were deleted until this instance
2004-10-06 20:54:57 +00:00
// of Ccontact is deleted. If the Commit wasn't performed, the
2000-01-25 16:18:40 +00:00
// database will automatically Rollback the changes when the database
// connection is terminated
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > GetDb ( ) - > CommitTrans ( ) ;
2000-01-25 16:18:40 +00:00
// Try to get the row that followed the just deleted row in the orderBy sequence
if ( ! GetNextRec ( ) )
{
// There was now row (in sequence) after the just deleted row, so get the
// row which preceded the just deleted row
if ( ! GetPrevRec ( ) )
{
// There are now no rows remaining, so clear the dialog widgets
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > Initialize ( ) ;
2000-01-25 16:18:40 +00:00
PutData ( ) ;
}
}
SetMode ( mode ) ; // force reset of button enable/disable
}
else
// Delete failed
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > GetDb ( ) - > RollbackTrans ( ) ;
2000-01-25 16:18:40 +00:00
SetMode ( mView ) ;
return ;
}
if ( widgetName = = pSaveBtn - > GetName ( ) )
{
Save ( ) ;
return ;
}
if ( widgetName = = pCancelBtn - > GetName ( ) )
{
2001-02-01 20:17:15 +00:00
bool Ok = ( wxMessageBox ( wxT ( " Are you sure? " ) , wxT ( " Confirm " ) , wxYES_NO | wxICON_QUESTION ) = = wxYES ) ;
2000-01-25 16:18:40 +00:00
if ( ! Ok )
return ;
2004-11-22 17:48:33 +00:00
if ( saveName . empty ( ) )
2000-01-25 16:18:40 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > Initialize ( ) ;
2000-01-25 16:18:40 +00:00
PutData ( ) ;
SetMode ( mView ) ;
return ;
}
else
{
// Requery previous record
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > FetchByName ( saveName ) )
2000-01-25 16:18:40 +00:00
{
PutData ( ) ;
SetMode ( mView ) ;
return ;
}
}
// Previous record not available, retrieve first record in table
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsPOSTGRES & &
wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsMY_SQL )
2000-01-25 16:18:40 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > whereStr = wxT ( " NAME = (SELECT MIN(NAME) FROM " ) ;
wxGetApp ( ) . Contact - > whereStr + = wxGetApp ( ) . Contact - > GetTableName ( ) ;
wxGetApp ( ) . Contact - > whereStr + = wxT ( " ) " ) ;
wxGetApp ( ) . Contact - > SetWhereClause ( wxGetApp ( ) . Contact - > whereStr . c_str ( ) ) ;
2000-01-25 16:18:40 +00:00
}
else
2004-11-04 21:35:39 +00:00
wxGetApp ( ) . Contact - > SetWhereClause ( wxEmptyString ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > Query ( ) )
2000-01-25 16:18:40 +00:00
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " ODBC error during Query() \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
SetMode ( mView ) ;
return ;
}
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetNext ( ) ) // Successfully read first record
2000-01-25 16:18:40 +00:00
{
PutData ( ) ;
SetMode ( mView ) ;
return ;
}
// No contacts are available, clear dialog
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > Initialize ( ) ;
2000-01-25 16:18:40 +00:00
PutData ( ) ;
SetMode ( mView ) ;
return ;
} // Cancel Button
if ( widgetName = = pPrevBtn - > GetName ( ) )
{
if ( ! GetPrevRec ( ) )
wxBell ( ) ;
return ;
} // Prev Button
if ( widgetName = = pNextBtn - > GetName ( ) )
{
if ( ! GetNextRec ( ) )
wxBell ( ) ;
return ;
} // Next Button
if ( widgetName = = pQueryBtn - > GetName ( ) )
{
// Display the query dialog box
2001-02-01 20:17:15 +00:00
wxChar qryWhere [ DB_MAX_WHERE_CLAUSE_LEN + 1 ] ;
2001-05-15 00:58:09 +00:00
wxStrcpy ( qryWhere , ( const wxChar * ) wxGetApp ( ) . Contact - > qryWhereStr ) ;
2004-11-10 12:12:37 +00:00
wxChar * tblName [ ] = { ( wxChar * ) CONTACT_TABLE_NAME . c_str ( ) , 0 } ;
2001-05-15 00:58:09 +00:00
new CqueryDlg ( GetParent ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , tblName , qryWhere ) ;
2000-01-25 16:18:40 +00:00
// Query the first record in the new record set and
// display it, if the query string has changed.
2001-05-15 00:58:09 +00:00
if ( wxStrcmp ( qryWhere , ( const wxChar * ) wxGetApp ( ) . Contact - > qryWhereStr ) )
2000-01-25 16:18:40 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > whereStr . Empty ( ) ;
2004-02-08 11:53:48 +00:00
wxGetApp ( ) . Contact - > SetOrderByClause ( wxT ( " NAME " ) ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsPOSTGRES & &
wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsMY_SQL )
2000-01-25 16:18:40 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > whereStr = wxT ( " NAME = (SELECT MIN(NAME) FROM " ) ;
wxGetApp ( ) . Contact - > whereStr + = CONTACT_TABLE_NAME ;
2000-01-25 16:18:40 +00:00
}
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
// Append the query where string (if there is one)
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > qryWhereStr = qryWhere ;
2000-07-15 19:51:35 +00:00
if ( wxStrlen ( qryWhere ) )
2000-01-25 16:18:40 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > whereStr + = wxT ( " WHERE " ) ;
wxGetApp ( ) . Contact - > whereStr + = wxGetApp ( ) . Contact - > qryWhereStr ;
2000-01-25 16:18:40 +00:00
}
// Close the expression with a right paren
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > whereStr + = wxT ( " ) " ) ;
2000-01-25 16:18:40 +00:00
// Requery the table
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > SetWhereClause ( wxGetApp ( ) . Contact - > whereStr . c_str ( ) ) ;
if ( ! wxGetApp ( ) . Contact - > Query ( ) )
2000-01-25 16:18:40 +00:00
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " ODBC error during Query() \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
return ;
}
// Display the first record from the query set
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > GetNext ( ) )
wxGetApp ( ) . Contact - > Initialize ( ) ;
2000-01-25 16:18:40 +00:00
PutData ( ) ;
}
// Enable/Disable the reset button
2004-11-22 17:48:33 +00:00
pResetBtn - > Enable ( ! wxGetApp ( ) . Contact - > qryWhereStr . empty ( ) ) ;
2000-01-25 16:18:40 +00:00
return ;
} // Query button
if ( widgetName = = pResetBtn - > GetName ( ) )
{
// Clear the additional where criteria established by the query feature
2004-11-04 21:35:39 +00:00
wxGetApp ( ) . Contact - > qryWhereStr = wxEmptyString ;
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > SetOrderByClause ( wxT ( " NAME " ) ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsPOSTGRES & &
wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsMY_SQL )
2000-01-25 16:18:40 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > whereStr = wxT ( " NAME = (SELECT MIN(NAME) FROM " ) ;
wxGetApp ( ) . Contact - > whereStr + = CONTACT_TABLE_NAME ;
wxGetApp ( ) . Contact - > whereStr + = wxT ( " ) " ) ;
2000-01-25 16:18:40 +00:00
}
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > SetWhereClause ( wxGetApp ( ) . Contact - > whereStr . c_str ( ) ) ;
if ( ! wxGetApp ( ) . Contact - > Query ( ) )
2000-01-25 16:18:40 +00:00
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " ODBC error during Query() \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
return ;
}
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > GetNext ( ) )
wxGetApp ( ) . Contact - > Initialize ( ) ;
2000-01-25 16:18:40 +00:00
PutData ( ) ;
2004-05-25 19:57:33 +00:00
pResetBtn - > Enable ( false ) ;
2000-01-25 16:18:40 +00:00
return ;
} // Reset button
if ( widgetName = = pNameListBtn - > GetName ( ) )
{
2004-11-10 12:12:37 +00:00
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 ) ;
2000-01-25 16:18:40 +00:00
2000-07-15 19:51:35 +00:00
if ( ListDB_Selection & & wxStrlen ( ListDB_Selection ) )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
wxString w = wxT ( " NAME = ' " ) ;
2000-01-25 16:18:40 +00:00
w + = ListDB_Selection ;
2001-02-01 20:17:15 +00:00
w + = wxT ( " ' " ) ;
2001-02-03 17:52:58 +00:00
GetRec ( w ) ;
2000-01-25 16:18:40 +00:00
}
return ;
}
2001-05-15 13:12:36 +00:00
if ( widgetName = = pDataTypesBtn - > GetName ( ) )
{
CheckSupportForAllDataTypes ( wxGetApp ( ) . READONLY_DB ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxT ( " Support datatypes was dumped to stdout. " ) ) ;
2001-05-15 13:12:36 +00:00
return ;
} // Data types Button
if ( widgetName = = pDbDiagsBtn - > GetName ( ) )
{
DisplayDbDiagnostics ( wxGetApp ( ) . READONLY_DB ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxT ( " Diagnostics info was dumped to stdout. " ) ) ;
2001-05-23 13:48:04 +00:00
return ;
}
if ( widgetName = = pCatalogBtn - > GetName ( ) )
{
2004-11-04 21:35:39 +00:00
if ( wxGetApp ( ) . Contact - > GetDb ( ) - > Catalog ( wxEmptyString , wxT ( " catalog.txt " ) ) )
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxT ( " The file 'catalog.txt' was created. " ) ) ;
2001-05-23 13:48:04 +00:00
else
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxT ( " Creation of the file 'catalog.txt' was failed. " ) ) ;
2001-05-15 13:12:36 +00:00
return ;
}
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
if ( widgetName = = pChooseImageBtn - > GetName ( ) )
{
OnSelectPict ( ) ;
}
if ( widgetName = = pShowImageBtn - > GetName ( ) )
{
OnShowImage ( ) ;
}
# endif
1998-07-28 09:43:44 +00:00
} // CeditorDlg::OnCommand()
2000-08-08 06:11:51 +00:00
bool CeditorDlg : : Initialize ( )
{
2004-10-06 20:54:57 +00:00
// Create the data structure and a new database connection.
2000-08-08 06:11:51 +00:00
// (As there is not a pDb being passed in the constructor, a new database
// connection is created)
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact = new Ccontact ( ) ;
2000-08-08 06:11:51 +00:00
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact )
2000-08-08 06:11:51 +00:00
{
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Unable to instantiate an instance of Ccontact " ) , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-08-08 06:11:51 +00:00
}
2004-10-06 20:54:57 +00:00
// Check if the table exists or not. If it doesn't, ask the user if they want to
2000-08-08 06:11:51 +00:00
// create the table. Continue trying to create the table until it exists, or user aborts
2004-11-10 12:12:37 +00:00
while ( ! wxGetApp ( ) . Contact - > GetDb ( ) - > TableExists ( CONTACT_TABLE_NAME ,
2004-10-06 20:54:57 +00:00
wxGetApp ( ) . DbConnectInf - > GetUserID ( ) ,
2001-02-03 17:52:58 +00:00
wxGetApp ( ) . DbConnectInf - > GetDefaultDir ( ) ) )
2000-08-08 06:11:51 +00:00
{
wxString tStr ;
2004-11-22 17:48:33 +00:00
tStr . Printf ( wxT ( " Unable to open the table '%s'. The table may \n need to be created. \n \n Do you wish to try to create/clear the table? \n \n " ) , CONTACT_TABLE_NAME . c_str ( ) ) ;
2001-06-10 17:12:56 +00:00
bool createTable = ( wxMessageBox ( tStr . c_str ( ) , wxT ( " Confirm " ) , wxYES_NO | wxICON_QUESTION ) = = wxYES ) ;
2000-08-08 06:11:51 +00:00
if ( ! createTable )
{
// Close();
2004-05-25 19:57:33 +00:00
return false ;
2000-08-08 06:11:51 +00:00
}
else
2004-05-25 19:57:33 +00:00
wxGetApp ( ) . CreateDataTable ( false ) ;
2000-08-08 06:11:51 +00:00
}
// Tables must be "opened" before anything other than creating/deleting table can be done
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > Open ( ) )
2000-08-08 06:11:51 +00:00
{
// Table does exist, or there was some problem opening it. Currently this should
2000-11-22 00:28:35 +00:00
// never fail, except in the case of the table not exisiting or the current
2000-08-08 06:11:51 +00:00
// user has insufficent privileges to access the table
2001-04-11 14:20:56 +00:00
# if 1
2000-08-08 06:11:51 +00:00
// This code is experimenting with a new function that will hopefully be available
// in the 2.4 release. This check will determine whether the open failing was due
// to the table not existing, or the users privileges being insufficient to
// open the table.
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > GetDb ( ) - > TablePrivileges ( CONTACT_TABLE_NAME , wxT ( " SELECT " ) ,
wxGetApp ( ) . Contact - > GetDb ( ) - > GetUsername ( ) ,
2001-05-23 13:48:04 +00:00
wxGetApp ( ) . Contact - > GetDb ( ) - > GetUsername ( ) ,
wxGetApp ( ) . DbConnectInf - > GetDefaultDir ( ) ) )
2000-08-08 06:11:51 +00:00
{
wxString tStr ;
2004-11-22 17:48:33 +00:00
tStr . Printf ( wxT ( " Unable to open the table '%s' (likely due to \n insufficient privileges of the logged in user). \n \n " ) , CONTACT_TABLE_NAME . c_str ( ) ) ;
2001-06-10 17:12:56 +00:00
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-08-08 06:11:51 +00:00
}
2004-10-06 20:54:57 +00:00
else
2000-08-08 06:11:51 +00:00
# endif
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > GetDb ( ) - > TableExists ( CONTACT_TABLE_NAME ,
wxGetApp ( ) . Contact - > GetDb ( ) - > GetUsername ( ) ,
2001-04-11 14:20:56 +00:00
wxGetApp ( ) . DbConnectInf - > GetDefaultDir ( ) ) )
2000-08-08 06:11:51 +00:00
{
wxString tStr ;
2004-11-22 17:48:33 +00:00
tStr . Printf ( wxT ( " Unable to open the table '%s' as the table \n does not appear to exist in the tablespace available \n to the currently logged in user. \n \n " ) , CONTACT_TABLE_NAME . c_str ( ) ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-08-08 06:11:51 +00:00
}
2004-05-25 19:57:33 +00:00
return false ;
2000-08-08 06:11:51 +00:00
}
// Build the dialog
2004-11-04 21:35:39 +00:00
( void ) new wxStaticBox ( this , EDITOR_DIALOG_FN_GROUP , wxEmptyString , wxPoint ( 15 , 1 ) , wxSize ( 497 , 69 ) , 0 , wxT ( " FunctionGrp " ) ) ;
( void ) new wxStaticBox ( this , EDITOR_DIALOG_SEARCH_GROUP , wxEmptyString , wxPoint ( 417 , 1 ) , wxSize ( 95 , 242 ) , 0 , wxT ( " SearchGrp " ) ) ;
2001-02-01 20:17:15 +00:00
pCreateBtn = new wxButton ( this , EDITOR_DIALOG_CREATE , wxT ( " &Create " ) , wxPoint ( 25 , 21 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " CreateBtn " ) ) ;
pEditBtn = new wxButton ( this , EDITOR_DIALOG_EDIT , wxT ( " &Edit " ) , wxPoint ( 102 , 21 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " EditBtn " ) ) ;
pDeleteBtn = new wxButton ( this , EDITOR_DIALOG_DELETE , wxT ( " &Delete " ) , wxPoint ( 179 , 21 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " DeleteBtn " ) ) ;
pCopyBtn = new wxButton ( this , EDITOR_DIALOG_COPY , wxT ( " Cop&y " ) , wxPoint ( 256 , 21 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " CopyBtn " ) ) ;
pSaveBtn = new wxButton ( this , EDITOR_DIALOG_SAVE , wxT ( " &Save " ) , wxPoint ( 333 , 21 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " SaveBtn " ) ) ;
pCancelBtn = new wxButton ( this , EDITOR_DIALOG_CANCEL , wxT ( " C&ancel " ) , wxPoint ( 430 , 21 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " CancelBtn " ) ) ;
pPrevBtn = new wxButton ( this , EDITOR_DIALOG_PREV , wxT ( " << &Prev " ) , wxPoint ( 430 , 81 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " PrevBtn " ) ) ;
pNextBtn = new wxButton ( this , EDITOR_DIALOG_NEXT , wxT ( " &Next >> " ) , wxPoint ( 430 , 121 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " NextBtn " ) ) ;
pQueryBtn = new wxButton ( this , EDITOR_DIALOG_QUERY , wxT ( " &Query " ) , wxPoint ( 430 , 161 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " QueryBtn " ) ) ;
pResetBtn = new wxButton ( this , EDITOR_DIALOG_RESET , wxT ( " &Reset " ) , wxPoint ( 430 , 200 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " ResetBtn " ) ) ;
2004-05-25 19:57:33 +00:00
pNameMsg = new wxStaticText ( this , EDITOR_DIALOG_NAME_MSG , wxT ( " Name: " ) , wxPoint ( 17 , 80 ) , wxDefaultSize , 0 , wxT ( " NameMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pNameTxt = new wxTextCtrl ( this , EDITOR_DIALOG_NAME_TEXT , wxEmptyString , wxPoint ( 17 , 97 ) , wxSize ( 308 , 25 ) , 0 , wxDefaultValidator , wxT ( " NameTxt " ) ) ;
2001-02-01 20:17:15 +00:00
pNameListBtn = new wxButton ( this , EDITOR_DIALOG_LOOKUP , wxT ( " &Lookup " ) , wxPoint ( 333 , 97 ) , wxSize ( 70 , 24 ) , 0 , wxDefaultValidator , wxT ( " LookupBtn " ) ) ;
2004-05-25 19:57:33 +00:00
pAddress1Msg = new wxStaticText ( this , EDITOR_DIALOG_ADDRESS1_MSG , wxT ( " Address: " ) , wxPoint ( 17 , 130 ) , wxDefaultSize , 0 , wxT ( " Address1Msg " ) ) ;
2004-11-04 21:35:39 +00:00
pAddress1Txt = new wxTextCtrl ( this , EDITOR_DIALOG_ADDRESS2_TEXT , wxEmptyString , wxPoint ( 17 , 147 ) , wxSize ( 308 , 25 ) , 0 , wxDefaultValidator , wxT ( " Address1Txt " ) ) ;
2004-05-25 19:57:33 +00:00
pAddress2Msg = new wxStaticText ( this , EDITOR_DIALOG_ADDRESS2_MSG , wxT ( " Address: " ) , wxPoint ( 17 , 180 ) , wxDefaultSize , 0 , wxT ( " Address2Msg " ) ) ;
2004-11-04 21:35:39 +00:00
pAddress2Txt = new wxTextCtrl ( this , EDITOR_DIALOG_ADDRESS2_TEXT , wxEmptyString , wxPoint ( 17 , 197 ) , wxSize ( 308 , 25 ) , 0 , wxDefaultValidator , wxT ( " Address2Txt " ) ) ;
2004-05-25 19:57:33 +00:00
pCityMsg = new wxStaticText ( this , EDITOR_DIALOG_CITY_MSG , wxT ( " City: " ) , wxPoint ( 17 , 230 ) , wxDefaultSize , 0 , wxT ( " CityMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pCityTxt = new wxTextCtrl ( this , EDITOR_DIALOG_CITY_TEXT , wxEmptyString , wxPoint ( 17 , 247 ) , wxSize ( 225 , 25 ) , 0 , wxDefaultValidator , wxT ( " CityTxt " ) ) ;
2004-05-25 19:57:33 +00:00
pStateMsg = new wxStaticText ( this , EDITOR_DIALOG_STATE_MSG , wxT ( " State: " ) , wxPoint ( 250 , 230 ) , wxDefaultSize , 0 , wxT ( " StateMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pStateTxt = new wxTextCtrl ( this , EDITOR_DIALOG_STATE_TEXT , wxEmptyString , wxPoint ( 250 , 247 ) , wxSize ( 153 , 25 ) , 0 , wxDefaultValidator , wxT ( " StateTxt " ) ) ;
2004-05-25 19:57:33 +00:00
pCountryMsg = new wxStaticText ( this , EDITOR_DIALOG_COUNTRY_MSG , wxT ( " Country: " ) , wxPoint ( 17 , 280 ) , wxDefaultSize , 0 , wxT ( " CountryMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pCountryTxt = new wxTextCtrl ( this , EDITOR_DIALOG_COUNTRY_TEXT , wxEmptyString , wxPoint ( 17 , 297 ) , wxSize ( 225 , 25 ) , 0 , wxDefaultValidator , wxT ( " CountryTxt " ) ) ;
2004-05-25 19:57:33 +00:00
pPostalCodeMsg = new wxStaticText ( this , EDITOR_DIALOG_POSTAL_MSG , wxT ( " Postal Code: " ) , wxPoint ( 250 , 280 ) , wxDefaultSize , 0 , wxT ( " PostalCodeMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pPostalCodeTxt = new wxTextCtrl ( this , EDITOR_DIALOG_POSTAL_TEXT , wxEmptyString , wxPoint ( 250 , 297 ) , wxSize ( 153 , 25 ) , 0 , wxDefaultValidator , wxT ( " PostalCodeTxt " ) ) ;
2000-08-08 06:11:51 +00:00
wxString choice_strings [ 5 ] ;
2001-02-01 20:17:15 +00:00
choice_strings [ 0 ] = wxT ( " English " ) ;
choice_strings [ 1 ] = wxT ( " French " ) ;
choice_strings [ 2 ] = wxT ( " German " ) ;
choice_strings [ 3 ] = wxT ( " Spanish " ) ;
choice_strings [ 4 ] = wxT ( " Other " ) ;
2000-08-08 06:11:51 +00:00
2004-07-20 10:09:47 +00:00
pNativeLangChoice = new wxChoice ( this , EDITOR_DIALOG_LANG_CHOICE , wxPoint ( 17 , 346 ) , wxSize ( 277 , wxDefaultCoord ) , 5 , choice_strings ) ;
2004-05-25 19:57:33 +00:00
pNativeLangMsg = new wxStaticText ( this , EDITOR_DIALOG_LANG_MSG , wxT ( " Native language: " ) , wxPoint ( 17 , 330 ) , wxDefaultSize , 0 , wxT ( " NativeLangMsg " ) ) ;
2000-08-08 06:11:51 +00:00
wxString radio_strings [ 2 ] ;
2001-02-01 20:17:15 +00:00
radio_strings [ 0 ] = wxT ( " No " ) ;
radio_strings [ 1 ] = wxT ( " Yes " ) ;
2004-05-25 19:57:33 +00:00
pDeveloperRadio = new wxRadioBox ( this , EDITOR_DIALOG_DEVELOPER , wxT ( " Developer: " ) , wxPoint ( 303 , 330 ) , wxDefaultSize , 2 , radio_strings , 2 , wxHORIZONTAL ) ;
pJoinDateMsg = new wxStaticText ( this , EDITOR_DIALOG_JOIN_MSG , wxT ( " Date joined: " ) , wxPoint ( 17 , 380 ) , wxDefaultSize , 0 , wxT ( " JoinDateMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pJoinDateTxt = new wxTextCtrl ( this , EDITOR_DIALOG_JOIN_TEXT , wxEmptyString , wxPoint ( 17 , 397 ) , wxSize ( 150 , 25 ) , 0 , wxDefaultValidator , wxT ( " JoinDateTxt " ) ) ;
2004-05-25 19:57:33 +00:00
pContribMsg = new wxStaticText ( this , EDITOR_DIALOG_CONTRIB_MSG , wxT ( " Contributions: " ) , wxPoint ( 175 , 380 ) , wxDefaultSize , 0 , wxT ( " ContribMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pContribTxt = new wxTextCtrl ( this , EDITOR_DIALOG_CONTRIB_TEXT , wxEmptyString , wxPoint ( 175 , 397 ) , wxSize ( 120 , 25 ) , 0 , wxDefaultValidator , wxT ( " ContribTxt " ) ) ;
2004-05-25 19:57:33 +00:00
pLinesMsg = new wxStaticText ( this , EDITOR_DIALOG_LINES_MSG , wxT ( " Lines of code: " ) , wxPoint ( 303 , 380 ) , wxDefaultSize , 0 , wxT ( " LinesMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pLinesTxt = new wxTextCtrl ( this , EDITOR_DIALOG_LINES_TEXT , wxEmptyString , wxPoint ( 303 , 397 ) , wxSize ( 100 , 25 ) , 0 , wxDefaultValidator , wxT ( " LinesTxt " ) ) ;
2000-08-08 06:11:51 +00:00
2001-05-23 13:48:04 +00:00
pCatalogBtn = new wxButton ( this , EDITOR_DIALOG_CATALOG , wxT ( " Catalo&g " ) , wxPoint ( 430 , 287 ) , wxSize ( 70 , 35 ) , 0 , wxDefaultValidator , wxT ( " CatalogBtn " ) ) ;
2001-05-15 13:12:36 +00:00
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 " ) ) ;
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
pPictureMsg = new wxStaticText ( this , EDITOR_DIALOG_PIC_MSG , wxT ( " Picture: " ) , wxPoint ( 17 , 430 ) , wxDefaultSize , 0 , wxT ( " PicMsg " ) ) ;
pPictSizeMsg = new wxStaticText ( this , EDITOR_DIALOG_PICSIZE_MSG , wxT ( " Picture Bytes: " ) , wxPoint ( 175 , 430 ) , wxDefaultSize , 0 , wxT ( " PicSizeMsg " ) ) ;
pChooseImageBtn = new wxButton ( this , EDITOR_DIALOG_PIC_BROWSE , wxT ( " Select... " ) , wxPoint ( 17 , 447 ) , wxSize ( 70 , 24 ) , 0 , wxDefaultValidator , wxT ( " PicBrowseBtn " ) ) ;
pShowImageBtn = new wxButton ( this , EDITOR_DIALOG_PIC_SHOW , wxT ( " Show... " ) , wxPoint ( 97 , 447 ) , wxSize ( 70 , 24 ) , 0 , wxDefaultValidator , wxT ( " PictShowBtn " ) ) ;
pPictSizeTxt = new wxTextCtrl ( this , EDITOR_DIALOG_PIC_SIZE_TEXT , wxEmptyString , wxPoint ( 175 , 447 ) , wxSize ( 120 , 25 ) , 0 , wxDefaultValidator , wxT ( " PictSizeTxt " ) ) ;
# endif
2004-11-22 17:48:33 +00:00
// Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
2000-08-08 06:11:51 +00:00
// handle all widget processing
2004-05-25 19:57:33 +00:00
widgetPtrsSet = true ;
2000-08-08 06:11:51 +00:00
2004-10-06 20:54:57 +00:00
// Setup the orderBy and where clauses to return back a single record as the result set,
2000-08-08 06:11:51 +00:00
// 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
2004-10-06 20:54:57 +00:00
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > SetOrderByClause ( wxT ( " NAME " ) ) ; // field name to sort by
2000-08-08 06:11:51 +00:00
// The wxString "whereStr" is not a member of the wxDbTable object, it is a member variable
// specifically in the Ccontact class. It is used here for simpler construction of a varying
// length string, and then after the string is built, the wxDbTable member variable "where" is
// assigned the pointer to the constructed string.
//
2004-10-06 20:54:57 +00:00
// The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
2000-08-08 06:11:51 +00:00
// to achieve a single row (in this case the first name in alphabetical order).
2004-10-06 20:54:57 +00:00
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsPOSTGRES & &
wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsMY_SQL )
2000-08-08 06:11:51 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > whereStr . Printf ( wxT ( " NAME = (SELECT MIN(NAME) FROM %s) " ) ,
wxGetApp ( ) . Contact - > GetTableName ( ) . c_str ( ) ) ;
2001-02-01 20:17:15 +00:00
// NOTE: (const wxChar*) returns a pointer which may not be valid later, so this is short term use only
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > SetWhereClause ( wxGetApp ( ) . Contact - > whereStr ) ;
2000-08-08 06:11:51 +00:00
}
else
2004-11-04 21:35:39 +00:00
wxGetApp ( ) . Contact - > SetWhereClause ( wxEmptyString ) ;
2000-08-08 06:11:51 +00:00
2004-10-06 20:54:57 +00:00
// 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.
2004-05-25 19:57:33 +00:00
// Only if there is a database error will Query() come back as false
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > Query ( ) )
2000-08-08 06:11:51 +00:00
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " ODBC error during Query() \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-08-08 06:11:51 +00:00
}
// Since Query succeeded, now get the row that was returned
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > GetNext ( ) )
2004-10-06 20:54:57 +00:00
// 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
2000-08-08 06:11:51 +00:00
// widgets on the dialog
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > Initialize ( ) ;
/*
wxGetApp ( ) . Contact - > GetDb ( ) - > RollbackTrans ( ) ;
*/
2000-08-08 06:11:51 +00:00
SetMode ( mView ) ;
PutData ( ) ;
2004-05-25 19:57:33 +00:00
Show ( true ) ;
2000-08-08 06:11:51 +00:00
2004-05-25 19:57:33 +00:00
initialized = true ;
return true ;
2000-08-08 06:11:51 +00:00
} // CeditorDlg::Initialize()
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
void CeditorDlg : : OnSelectPict ( )
{
wxFileDialog dlg ( this , wxT ( " Choose an image file less than 60K " ) , wxEmptyString , wxEmptyString , wxT ( " JPEG files (*.jpg)|*.jpg|GIF files (*.gif)|*.gif|BMP files (*.bmp)|*.bmp|All Files (*.*)|*.* " ) , wxOPEN ) ;
if ( dlg . ShowModal ( ) = = wxID_OK )
{
wxFile file ( dlg . GetPath ( ) ) ;
if ( file . IsOpened ( ) )
{
2004-11-22 19:32:37 +00:00
// assume not huge file in sample
long iSize = ( long ) file . Length ( ) ;
2004-11-04 21:35:39 +00:00
if ( ( iSize > 0 ) & & ( iSize < MAX_PICTURE_SIZE ) )
{
2004-11-12 14:15:30 +00:00
wxGetApp ( ) . Contact - > BlobSize = ( size_t ) iSize ;
2004-11-04 21:35:39 +00:00
memset ( wxGetApp ( ) . Contact - > Picture , 0 , MAX_PICTURE_SIZE ) ;
2004-11-12 14:15:30 +00:00
wxFileOffset iReadSize = file . Read ( wxGetApp ( ) . Contact - > Picture , ( size_t ) iSize ) ;
2004-11-04 21:35:39 +00:00
if ( iReadSize < iSize )
wxMessageBox ( wxT ( " Something bad happened while reading... " ) , wxT ( " BLOB Loading Error " ) , wxOK | wxICON_EXCLAMATION ) ;
wxString tStr ;
2004-11-22 19:32:37 +00:00
tStr . Printf ( wxT ( " %ld " ) , iSize ) ;
2004-11-04 21:35:39 +00:00
pPictSizeTxt - > SetValue ( tStr ) ;
}
else
wxMessageBox ( wxT ( " Selected File is TOO BIG. 60k is the max image size " ) , wxT ( " BLOB Loading Error " ) , wxOK | wxICON_EXCLAMATION ) ;
}
else
wxMessageBox ( wxT ( " Unable to open the requested image file " ) , wxT ( " File Access Error " ) , wxOK | wxICON_EXCLAMATION ) ;
}
}
void CeditorDlg : : OnShowImage ( )
{
if ( wxGetApp ( ) . Contact - > BlobSize > 0 )
{
CimageDlg dlg ( this , wxGetApp ( ) . Contact - > Picture , wxGetApp ( ) . Contact - > BlobSize ) ;
dlg . ShowModal ( ) ;
}
}
# endif
2000-08-08 06:11:51 +00:00
1998-07-28 09:43:44 +00:00
void CeditorDlg : : FieldsEditable ( )
{
2001-04-11 14:20:56 +00:00
if ( ! widgetPtrsSet )
return ;
2000-01-25 16:18:40 +00:00
pNameTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pAddress1Txt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pAddress2Txt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pCityTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pStateTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pPostalCodeTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pCountryTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pJoinDateTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pContribTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pLinesTxt - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pNativeLangChoice - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pDeveloperRadio - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
1998-07-28 09:43:44 +00:00
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
pPictSizeTxt - > Enable ( false ) ;
pChooseImageBtn - > Enable ( ( mode = = mCreate ) | | ( mode = = mEdit ) ) ;
pShowImageBtn - > Enable ( wxGetApp ( ) . Contact & & wxGetApp ( ) . Contact - > BlobSize > 0 ) ; //((mode == mCreate) || (mode == mEdit));
# endif
1998-07-28 09:43:44 +00:00
} // CeditorDlg::FieldsEditable()
void CeditorDlg : : SetMode ( enum DialogModes m )
{
2004-05-25 19:57:33 +00:00
bool edit = false ;
2000-01-25 16:18:40 +00:00
mode = m ;
switch ( mode )
{
case mCreate :
case mEdit :
2004-05-25 19:57:33 +00:00
edit = true ;
2000-01-25 16:18:40 +00:00
break ;
case mView :
case mSearch :
2004-05-25 19:57:33 +00:00
edit = false ;
2000-01-25 16:18:40 +00:00
break ;
default :
break ;
} ;
if ( widgetPtrsSet )
{
pCreateBtn - > Enable ( ! edit ) ;
2004-11-04 21:35:39 +00:00
pEditBtn - > Enable ( ! edit & & ( wxStrcmp ( wxGetApp ( ) . Contact - > Name , wxEmptyString ) ! = 0 ) ) ;
pDeleteBtn - > Enable ( ! edit & & ( wxStrcmp ( wxGetApp ( ) . Contact - > Name , wxEmptyString ) ! = 0 ) ) ;
pCopyBtn - > Enable ( ! edit & & ( wxStrcmp ( wxGetApp ( ) . Contact - > Name , wxEmptyString ) ! = 0 ) ) ;
2000-01-25 16:18:40 +00:00
pSaveBtn - > Enable ( edit ) ;
pCancelBtn - > Enable ( edit ) ;
pPrevBtn - > Enable ( ! edit ) ;
pNextBtn - > Enable ( ! edit ) ;
pQueryBtn - > Enable ( ! edit ) ;
2004-11-22 17:48:33 +00:00
pResetBtn - > Enable ( ! edit & & ! wxGetApp ( ) . Contact - > qryWhereStr . empty ( ) ) ;
2000-01-25 16:18:40 +00:00
pNameListBtn - > Enable ( ! edit ) ;
}
FieldsEditable ( ) ;
1998-07-28 09:43:44 +00:00
} // CeditorDlg::SetMode()
1998-12-30 17:40:53 +00:00
bool CeditorDlg : : PutData ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxString tStr ;
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
pNameTxt - > SetValue ( wxGetApp ( ) . Contact - > Name ) ;
pAddress1Txt - > SetValue ( wxGetApp ( ) . Contact - > Addr1 ) ;
pAddress2Txt - > SetValue ( wxGetApp ( ) . Contact - > Addr2 ) ;
pCityTxt - > SetValue ( wxGetApp ( ) . Contact - > City ) ;
pStateTxt - > SetValue ( wxGetApp ( ) . Contact - > State ) ;
pCountryTxt - > SetValue ( wxGetApp ( ) . Contact - > Country ) ;
pPostalCodeTxt - > SetValue ( wxGetApp ( ) . Contact - > PostalCode ) ;
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
tStr . Printf ( wxT ( " %d/%d/%d " ) , wxGetApp ( ) . Contact - > JoinDate . month , wxGetApp ( ) . Contact - > JoinDate . day , wxGetApp ( ) . Contact - > JoinDate . year ) ;
2000-01-25 16:18:40 +00:00
pJoinDateTxt - > SetValue ( tStr ) ;
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
tStr . Printf ( wxT ( " %d " ) , wxGetApp ( ) . Contact - > Contributions ) ;
2000-01-25 16:18:40 +00:00
pContribTxt - > SetValue ( tStr ) ;
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
tStr . Printf ( wxT ( " %lu " ) , wxGetApp ( ) . Contact - > LinesOfCode ) ;
2000-01-25 16:18:40 +00:00
pLinesTxt - > SetValue ( tStr ) ;
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
pNativeLangChoice - > SetSelection ( wxGetApp ( ) . Contact - > NativeLanguage ) ;
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
pDeveloperRadio - > SetSelection ( wxGetApp ( ) . Contact - > IsDeveloper ) ;
1998-07-28 09:43:44 +00:00
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
tStr . Printf ( wxT ( " %lu " ) , wxGetApp ( ) . Contact - > BlobSize ) ;
pPictSizeTxt - > SetValue ( tStr ) ;
pShowImageBtn - > Enable ( wxGetApp ( ) . Contact - > BlobSize > 0 ) ;
# endif
2004-05-25 19:57:33 +00:00
return true ;
1998-07-28 09:43:44 +00:00
} // Ceditor::PutData()
/*
* Reads the data out of all the widgets on the dialog . Some data evaluation is done
* to ensure that there is a name entered and that the date field is valid .
*
2004-05-25 19:57:33 +00:00
* A return value of true means that valid data was retrieved from the dialog , otherwise
1998-07-28 09:43:44 +00:00
* invalid data was found ( and a message was displayed telling the user what to fix ) , and
* the data was not placed into the appropraite fields of Ccontact
*/
1998-12-30 17:40:53 +00:00
bool CeditorDlg : : GetData ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Validate that the data currently entered into the widgets is valid data
wxString tStr ;
tStr = pNameTxt - > GetValue ( ) ;
2004-11-04 21:35:39 +00:00
if ( ! wxStrcmp ( ( const wxChar * ) tStr , wxEmptyString ) )
2000-01-25 16:18:40 +00:00
{
2004-11-04 21:35:39 +00:00
wxMessageBox ( wxT ( " A name is required for entry into the contact table " ) , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2004-05-25 19:57:33 +00:00
bool invalid = false ;
2001-11-23 00:24:32 +00:00
int mm = 1 , dd = 1 , yyyy = 2001 ;
2000-01-25 16:18:40 +00:00
int first , second ;
tStr = pJoinDateTxt - > GetValue ( ) ;
2001-02-01 20:17:15 +00:00
if ( tStr . Freq ( wxT ( ' / ' ) ) ! = 2 )
2004-05-25 19:57:33 +00:00
invalid = true ;
2000-01-25 16:18:40 +00:00
// Find the month, day, and year tokens
if ( ! invalid )
{
2001-02-01 20:17:15 +00:00
first = tStr . First ( wxT ( ' / ' ) ) ;
second = tStr . Last ( wxT ( ' / ' ) ) ;
2000-01-25 16:18:40 +00:00
2004-02-08 11:53:48 +00:00
mm = wxAtoi ( tStr . SubString ( 0 , first ) ) ;
dd = wxAtoi ( tStr . SubString ( first + 1 , second ) ) ;
yyyy = wxAtoi ( tStr . SubString ( second + 1 , tStr . Length ( ) - 1 ) ) ;
2000-01-25 16:18:40 +00:00
invalid = ! ( mm & & dd & & yyyy ) ;
}
// Force Year 2000 compliance
if ( ! invalid & & ( yyyy < 1000 ) )
2004-05-25 19:57:33 +00:00
invalid = true ;
2000-01-25 16:18:40 +00:00
// Check the token ranges for validity
if ( ! invalid )
{
if ( yyyy > 9999 )
2004-05-25 19:57:33 +00:00
invalid = true ;
2000-01-25 16:18:40 +00:00
else if ( ( mm < 1 ) | | ( mm > 12 ) )
2004-05-25 19:57:33 +00:00
invalid = true ;
2000-01-25 16:18:40 +00:00
else
{
if ( dd < 1 )
2004-05-25 19:57:33 +00:00
invalid = true ;
2000-01-25 16:18:40 +00:00
else
{
int days [ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 ,
31 , 31 , 30 , 31 , 30 , 31 } ;
if ( dd > days [ mm - 1 ] )
{
2004-05-25 19:57:33 +00:00
invalid = true ;
2000-01-25 16:18:40 +00:00
if ( ( dd = = 29 ) & & ( mm = = 2 ) )
{
if ( ( ( yyyy % 4 ) = = 0 ) & & ( ( ( yyyy % 100 ) ! = 0 ) | | ( ( yyyy % 400 ) = = 0 ) ) )
2004-05-25 19:57:33 +00:00
invalid = false ;
2000-01-25 16:18:40 +00:00
}
}
}
}
}
if ( ! invalid )
{
2004-10-10 10:10:27 +00:00
wxGetApp ( ) . Contact - > JoinDate . month = ( unsigned short ) mm ;
wxGetApp ( ) . Contact - > JoinDate . day = ( unsigned short ) dd ;
wxGetApp ( ) . Contact - > JoinDate . year = ( short ) yyyy ;
2000-01-25 16:18:40 +00:00
}
else
{
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Improper date format. Please check the date \n specified and try again. \n \n NOTE: Dates are in american format (MM/DD/YYYY) " ) , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
tStr = pNameTxt - > GetValue ( ) ;
2001-05-15 00:58:09 +00:00
wxStrcpy ( wxGetApp ( ) . Contact - > Name , ( const wxChar * ) tStr ) ;
wxStrcpy ( wxGetApp ( ) . Contact - > Addr1 , pAddress1Txt - > GetValue ( ) ) ;
wxStrcpy ( wxGetApp ( ) . Contact - > Addr2 , pAddress2Txt - > GetValue ( ) ) ;
wxStrcpy ( wxGetApp ( ) . Contact - > City , pCityTxt - > GetValue ( ) ) ;
wxStrcpy ( wxGetApp ( ) . Contact - > State , pStateTxt - > GetValue ( ) ) ;
wxStrcpy ( wxGetApp ( ) . Contact - > Country , pCountryTxt - > GetValue ( ) ) ;
wxStrcpy ( wxGetApp ( ) . Contact - > PostalCode , pPostalCodeTxt - > GetValue ( ) ) ;
2000-01-25 16:18:40 +00:00
2004-10-06 20:54:57 +00:00
wxGetApp ( ) . Contact - > Contributions = ( UCHAR ) wxAtoi ( pContribTxt - > GetValue ( ) ) ;
2004-02-08 11:53:48 +00:00
wxGetApp ( ) . Contact - > LinesOfCode = wxAtol ( pLinesTxt - > GetValue ( ) ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > NativeLanguage = ( enum Language ) pNativeLangChoice - > GetSelection ( ) ;
wxGetApp ( ) . Contact - > IsDeveloper = pDeveloperRadio - > GetSelection ( ) > 0 ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
return true ;
1998-07-28 09:43:44 +00:00
} // CeditorDlg::GetData()
/*
* Retrieve data from the dialog , verify the validity of the data , and if it is valid ,
* try to insert / update the data to the table based on the current ' mode ' the dialog
* is set to .
*
2004-05-25 19:57:33 +00:00
* A return value of true means the insert / update was completed successfully , a return
* value of false means that Save ( ) failed . If returning false , then this function
1998-07-28 09:43:44 +00:00
* has displayed a detailed error message for the user .
*/
1998-12-30 17:40:53 +00:00
bool CeditorDlg : : Save ( )
1998-07-28 09:43:44 +00:00
{
2004-05-25 19:57:33 +00:00
bool failed = false ;
2000-01-25 16:18:40 +00:00
// Read the data in the widgets of the dialog to get the user's data
if ( ! GetData ( ) )
2004-05-25 19:57:33 +00:00
failed = true ;
2000-01-25 16:18:40 +00:00
// Perform any other required validations necessary before saving
if ( ! failed )
{
wxBeginBusyCursor ( ) ;
if ( mode = = mCreate )
{
2004-10-06 20:54:57 +00:00
RETCODE result = ( RETCODE ) wxGetApp ( ) . Contact - > Insert ( ) ;
2000-01-25 16:18:40 +00:00
failed = ( result ! = DB_SUCCESS ) ;
if ( failed )
{
// Some errors may be expected, like a duplicate key, so handle those instances with
// specific error messages.
if ( result = = DB_ERR_INTEGRITY_CONSTRAINT_VIOL )
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " A duplicate key value already exists in the table. \n Unable to save record \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
}
else
{
2001-05-18 18:32:33 +00:00
// Some other unexpected error occurred
2000-01-25 16:18:40 +00:00
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " Database insert failed \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
}
}
}
else // mode == mEdit
{
2001-05-18 18:32:33 +00:00
wxGetApp ( ) . Contact - > GetDb ( ) - > RollbackTrans ( ) ;
2004-02-08 11:53:48 +00:00
wxGetApp ( ) . Contact - > whereStr . Printf ( wxT ( " NAME = '%s' " ) , saveName . c_str ( ) ) ;
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > UpdateWhere ( wxGetApp ( ) . Contact - > whereStr ) )
2000-01-25 16:18:40 +00:00
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " Database update failed \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
failed = true ;
2000-01-25 16:18:40 +00:00
}
}
if ( ! failed )
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > GetDb ( ) - > CommitTrans ( ) ;
2000-01-25 16:18:40 +00:00
SetMode ( mView ) ; // Sets the dialog mode back to viewing after save is successful
}
else
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > GetDb ( ) - > RollbackTrans ( ) ;
2000-01-25 16:18:40 +00:00
wxEndBusyCursor ( ) ;
}
return ! failed ;
1998-07-28 09:43:44 +00:00
} // CeditorDlg::Save()
/*
* Where this program is only showing a single row at a time in the dialog ,
* a special where clause must be built to find just the single row which ,
* in sequence , would follow the currently displayed row .
*/
1998-12-30 17:40:53 +00:00
bool CeditorDlg : : GetNextRec ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxString w ;
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsPOSTGRES & &
wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsMY_SQL )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
w = wxT ( " NAME = (SELECT MIN(NAME) FROM " ) ;
2001-05-15 00:58:09 +00:00
w + = wxGetApp ( ) . Contact - > GetTableName ( ) ;
2001-02-01 20:17:15 +00:00
w + = wxT ( " WHERE NAME > ' " ) ;
2000-01-25 16:18:40 +00:00
}
else
2001-02-01 20:17:15 +00:00
w = wxT ( " (NAME > ' " ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
w + = wxGetApp ( ) . Contact - > Name ;
2001-02-01 20:17:15 +00:00
w + = wxT ( " ' " ) ;
2000-01-25 16:18:40 +00:00
// If a query where string is currently set, append that criteria
2004-11-22 17:48:33 +00:00
if ( ! wxGetApp ( ) . Contact - > qryWhereStr . empty ( ) )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
w + = wxT ( " AND ( " ) ;
2001-05-15 00:58:09 +00:00
w + = wxGetApp ( ) . Contact - > qryWhereStr ;
2001-02-01 20:17:15 +00:00
w + = wxT ( " ) " ) ;
2000-01-25 16:18:40 +00:00
}
2001-02-01 20:17:15 +00:00
w + = wxT ( " ) " ) ;
2001-02-03 17:52:58 +00:00
return ( GetRec ( w ) ) ;
1998-07-28 09:43:44 +00:00
} // CeditorDlg::GetNextRec()
/*
* Where this program is only showing a single row at a time in the dialog ,
* a special where clause must be built to find just the single row which ,
* in sequence , would precede the currently displayed row .
*/
1998-12-30 17:40:53 +00:00
bool CeditorDlg : : GetPrevRec ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxString w ;
1998-07-28 09:43:44 +00:00
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsPOSTGRES & &
wxGetApp ( ) . Contact - > GetDb ( ) - > Dbms ( ) ! = dbmsMY_SQL )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
w = wxT ( " NAME = (SELECT MAX(NAME) FROM " ) ;
2001-05-15 00:58:09 +00:00
w + = wxGetApp ( ) . Contact - > GetTableName ( ) ;
2001-02-01 20:17:15 +00:00
w + = wxT ( " WHERE NAME < ' " ) ;
2000-01-25 16:18:40 +00:00
}
else
2001-02-01 20:17:15 +00:00
w = wxT ( " (NAME < ' " ) ;
1999-10-07 11:04:06 +00:00
2001-05-15 00:58:09 +00:00
w + = wxGetApp ( ) . Contact - > Name ;
2001-02-01 20:17:15 +00:00
w + = wxT ( " ' " ) ;
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
// If a query where string is currently set, append that criteria
2004-11-22 17:48:33 +00:00
if ( ! wxGetApp ( ) . Contact - > qryWhereStr . empty ( ) )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
w + = wxT ( " AND ( " ) ;
2001-05-15 00:58:09 +00:00
w + = wxGetApp ( ) . Contact - > qryWhereStr ;
2001-02-01 20:17:15 +00:00
w + = wxT ( " ) " ) ;
2000-01-25 16:18:40 +00:00
}
1998-07-28 09:43:44 +00:00
2001-02-01 20:17:15 +00:00
w + = wxT ( " ) " ) ;
1998-07-28 09:43:44 +00:00
2001-02-03 17:52:58 +00:00
return ( GetRec ( w ) ) ;
1998-07-28 09:43:44 +00:00
} // CeditorDlg::GetPrevRec()
/*
* This function is here to avoid duplicating this same code in both the
* GetPrevRec ( ) and GetNextRec ( ) functions
*/
2001-02-03 17:52:58 +00:00
bool CeditorDlg : : GetRec ( const wxString & whereStr )
1998-07-28 09:43:44 +00:00
{
2001-05-15 00:58:09 +00:00
wxGetApp ( ) . Contact - > SetWhereClause ( whereStr ) ;
wxGetApp ( ) . Contact - > SetOrderByClause ( wxT ( " NAME " ) ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
if ( ! wxGetApp ( ) . Contact - > Query ( ) )
2000-01-25 16:18:40 +00:00
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " ODBC error during Query() \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
return ( false ) ;
2000-01-25 16:18:40 +00:00
}
2001-05-15 00:58:09 +00:00
if ( wxGetApp ( ) . Contact - > GetNext ( ) )
2000-01-25 16:18:40 +00:00
{
PutData ( ) ;
2004-05-25 19:57:33 +00:00
return ( true ) ;
2000-01-25 16:18:40 +00:00
}
else
2004-05-25 19:57:33 +00:00
return ( false ) ;
1998-07-28 09:43:44 +00:00
} // CeditorDlg::GetRec()
/*
* CparameterDlg constructor
*/
1999-02-05 23:55:04 +00:00
BEGIN_EVENT_TABLE ( CparameterDlg , wxDialog )
1999-10-07 11:04:06 +00:00
EVT_BUTTON ( PARAMETER_DIALOG_SAVE , CparameterDlg : : OnButton )
EVT_BUTTON ( PARAMETER_DIALOG_CANCEL , CparameterDlg : : OnButton )
1999-02-05 23:55:04 +00:00
EVT_CLOSE ( CparameterDlg : : OnCloseWindow )
END_EVENT_TABLE ( )
2004-05-25 19:57:33 +00:00
CparameterDlg : : CparameterDlg ( wxWindow * parent ) : wxDialog ( parent , PARAMETER_DIALOG , wxT ( " ODBC parameter settings " ) , wxDefaultPosition , wxSize ( 400 , 325 ) )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Since the ::OnCommand() function is overridden, this prevents the widget
// detection in ::OnCommand() until all widgets have been initialized to prevent
// uninitialized pointers from crashing the program
2004-05-25 19:57:33 +00:00
widgetPtrsSet = false ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
pParamODBCSourceMsg = new wxStaticText ( this , PARAMETER_DIALOG_SOURCE_MSG , wxT ( " ODBC data sources: " ) , wxPoint ( 10 , 10 ) , wxDefaultSize , 0 , wxT ( " ParamODBCSourceMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pParamODBCSourceList = new wxListBox ( this , PARAMETER_DIALOG_SOURCE_LISTBOX , wxPoint ( 10 , 29 ) , wxSize ( 285 , 150 ) , 0 , 0 , wxLB_SINGLE | wxLB_ALWAYS_SB , wxDefaultValidator , wxT ( " ParamODBCSourceList " ) ) ;
2004-05-25 19:57:33 +00:00
pParamUserNameMsg = new wxStaticText ( this , PARAMETER_DIALOG_NAME_MSG , wxT ( " Database user name: " ) , wxPoint ( 10 , 193 ) , wxDefaultSize , 0 , wxT ( " ParamUserNameMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pParamUserNameTxt = new wxTextCtrl ( this , PARAMETER_DIALOG_NAME_TEXT , wxEmptyString , wxPoint ( 10 , 209 ) , wxSize ( 140 , 25 ) , 0 , wxDefaultValidator , wxT ( " ParamUserNameTxt " ) ) ;
2004-05-25 19:57:33 +00:00
pParamPasswordMsg = new wxStaticText ( this , PARAMETER_DIALOG_PASSWORD_MSG , wxT ( " Password: " ) , wxPoint ( 156 , 193 ) , wxDefaultSize , 0 , wxT ( " ParamPasswordMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pParamPasswordTxt = new wxTextCtrl ( this , PARAMETER_DIALOG_PASSWORD_TEXT , wxEmptyString , wxPoint ( 156 , 209 ) , wxSize ( 140 , 25 ) , 0 , wxDefaultValidator , wxT ( " ParamPasswordTxt " ) ) ;
2004-05-25 19:57:33 +00:00
pParamDirPathMsg = new wxStaticText ( this , PARAMETER_DIALOG_DIRPATH_MSG , wxT ( " Directory: " ) , wxPoint ( 10 , 243 ) , wxDefaultSize , 0 , wxT ( " ParamDirPathMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pParamDirPathTxt = new wxTextCtrl ( this , PARAMETER_DIALOG_DIRPATH_TEXT , wxEmptyString , wxPoint ( 10 , 259 ) , wxSize ( 140 , 25 ) , 0 , wxDefaultValidator , wxT ( " ParamDirPathTxt " ) ) ;
2001-02-01 20:17:15 +00:00
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 " ) ) ;
2000-01-25 16:18:40 +00:00
2004-10-06 20:54:57 +00:00
// Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
2000-01-25 16:18:40 +00:00
// handle all widget processing
2004-05-25 19:57:33 +00:00
widgetPtrsSet = true ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
saved = false ;
2000-01-25 16:18:40 +00:00
savedParamSettings = wxGetApp ( ) . params ;
Centre ( wxBOTH ) ;
PutData ( ) ;
ShowModal ( ) ;
1998-07-28 09:43:44 +00:00
} // CparameterDlg constructor
1999-02-05 23:55:04 +00:00
void CparameterDlg : : OnCloseWindow ( wxCloseEvent & event )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Put any additional checking necessary to make certain it is alright
// to close the program here that is not done elsewhere
if ( ! saved )
{
2001-02-01 20:17:15 +00:00
bool Ok = ( wxMessageBox ( wxT ( " No changes have been saved. \n \n Are you sure you wish exit the parameter screen? " ) , wxT ( " Confirm " ) , wxYES_NO | wxICON_QUESTION ) = = wxYES ) ;
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
if ( ! Ok )
1999-02-05 23:55:04 +00:00
{
event . Veto ( ) ;
2000-01-25 16:18:40 +00:00
return ;
1999-02-05 23:55:04 +00:00
}
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
wxGetApp ( ) . params = savedParamSettings ;
}
1998-07-28 09:43:44 +00:00
2000-01-25 16:18:40 +00:00
if ( GetParent ( ) ! = NULL )
GetParent ( ) - > SetFocus ( ) ;
1999-02-05 23:55:04 +00:00
2000-08-08 06:11:51 +00:00
while ( wxIsBusy ( ) )
wxEndBusyCursor ( ) ;
2004-05-25 19:57:33 +00:00
Show ( false ) ;
2000-08-08 06:11:51 +00:00
SetReturnCode ( 0 ) ; // added so BoundsChecker would not report use of uninitialized variable
this - > Destroy ( ) ;
} // CparameterDlg::OnCloseWindow()
1998-07-28 09:43:44 +00:00
1999-10-07 11:04:06 +00:00
void CparameterDlg : : OnButton ( wxCommandEvent & event )
{
2000-01-25 16:18:40 +00:00
wxWindow * win = ( wxWindow * ) event . GetEventObject ( ) ;
OnCommand ( * win , event ) ;
1999-10-07 11:04:06 +00:00
}
2000-08-08 06:11:51 +00:00
2004-02-08 11:53:48 +00:00
void CparameterDlg : : OnCommand ( wxWindow & win , wxCommandEvent & WXUNUSED ( event ) )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxString widgetName ;
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
widgetName = win . GetName ( ) ;
if ( ! widgetPtrsSet )
return ;
if ( widgetName = = pParamSaveBtn - > GetName ( ) )
{
if ( Save ( ) )
{
wxString tStr ;
2001-02-01 20:17:15 +00:00
tStr = wxT ( " Database parameters have been saved. " ) ;
2000-01-25 16:18:40 +00:00
if ( GetParent ( ) ! = NULL ) // The parameter dialog was not called during startup due to a missing cfg file
2001-02-01 20:17:15 +00:00
tStr + = wxT ( " \n New parameters will take effect the next time the program is started. " ) ;
wxMessageBox ( tStr , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2004-05-25 19:57:33 +00:00
saved = true ;
2000-01-25 16:18:40 +00:00
Close ( ) ;
}
return ;
}
if ( widgetName = = pParamCancelBtn - > GetName ( ) )
{
Close ( ) ;
return ;
}
1998-07-28 09:43:44 +00:00
} // CparameterDlg::OnCommand()
1998-12-30 17:40:53 +00:00
bool CparameterDlg : : PutData ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Fill the data source list box
FillDataSourceList ( ) ;
// Fill in the fields from the params object
if ( wxGetApp ( ) . params . ODBCSource & & wxStrlen ( wxGetApp ( ) . params . ODBCSource ) )
2001-11-23 00:24:32 +00:00
{
int index = pParamODBCSourceList - > FindString ( wxGetApp ( ) . params . ODBCSource ) ;
2004-05-25 19:57:33 +00:00
if ( index ! = wxNOT_FOUND )
2001-11-23 00:24:32 +00:00
pParamODBCSourceList - > SetSelection ( index ) ;
}
2000-01-25 16:18:40 +00:00
pParamUserNameTxt - > SetValue ( wxGetApp ( ) . params . UserName ) ;
pParamPasswordTxt - > SetValue ( wxGetApp ( ) . params . Password ) ;
pParamDirPathTxt - > SetValue ( wxGetApp ( ) . params . DirPath ) ;
2004-05-25 19:57:33 +00:00
return true ;
1998-07-28 09:43:44 +00:00
} // CparameterDlg::PutData()
1998-12-30 17:40:53 +00:00
bool CparameterDlg : : GetData ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxString tStr ;
2004-11-04 21:35:39 +00:00
if ( pParamODBCSourceList - > GetStringSelection ( ) ! = wxEmptyString )
2000-01-25 16:18:40 +00:00
{
tStr = pParamODBCSourceList - > GetStringSelection ( ) ;
2004-11-04 21:35:39 +00:00
if ( tStr . Length ( ) > ( ( int ) ( sizeof ( wxGetApp ( ) . params . ODBCSource ) / sizeof ( wxChar ) ) - 1 ) )
2000-01-25 16:18:40 +00:00
{
wxString errmsg ;
2004-11-04 21:35:39 +00:00
errmsg . Printf ( wxT ( " ODBC Data source name is longer than the data structure to hold it. \n 'Cparameter.ODBCSource' must have a larger character array \n to handle a data source with this long of a name \n \n The data source currently selected is %d characters long. " ) , tStr . Length ( ) ) ;
wxMessageBox ( errmsg , wxT ( " Internal program error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2000-07-15 19:51:35 +00:00
wxStrcpy ( wxGetApp ( ) . params . ODBCSource , tStr ) ;
2000-01-25 16:18:40 +00:00
}
else
2004-05-25 19:57:33 +00:00
return false ;
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
tStr = pParamUserNameTxt - > GetValue ( ) ;
2004-11-04 21:35:39 +00:00
if ( tStr . Length ( ) > ( ( int ) ( sizeof ( wxGetApp ( ) . params . UserName ) / sizeof ( wxChar ) ) - 1 ) )
2000-01-25 16:18:40 +00:00
{
wxString errmsg ;
2004-11-04 21:35:39 +00:00
errmsg . Printf ( wxT ( " User name is longer than the data structure to hold it. \n 'Cparameter.UserName' must have a larger character array \n to handle a data source with this long of a name \n \n The user name currently specified is %d characters long. " ) , tStr . Length ( ) ) ;
wxMessageBox ( errmsg , wxT ( " Internal program error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2000-07-15 19:51:35 +00:00
wxStrcpy ( wxGetApp ( ) . params . UserName , tStr ) ;
2000-01-25 16:18:40 +00:00
tStr = pParamPasswordTxt - > GetValue ( ) ;
2004-11-04 21:35:39 +00:00
if ( tStr . Length ( ) > ( ( int ) ( sizeof ( wxGetApp ( ) . params . Password ) / sizeof ( wxChar ) ) - 1 ) )
2000-01-25 16:18:40 +00:00
{
wxString errmsg ;
2004-11-04 21:35:39 +00:00
errmsg . Printf ( wxT ( " Password is longer than the data structure to hold it. \n 'Cparameter.Password' must have a larger character array \n to handle a data source with this long of a name \n \n The password currently specified is %d characters long. " ) , tStr . Length ( ) ) ;
wxMessageBox ( errmsg , wxT ( " Internal program error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2000-07-15 19:51:35 +00:00
wxStrcpy ( wxGetApp ( ) . params . Password , tStr ) ;
2000-01-25 16:18:40 +00:00
tStr = pParamDirPathTxt - > GetValue ( ) ;
2001-02-01 20:17:15 +00:00
tStr . Replace ( wxT ( " \\ " ) , wxT ( " / " ) ) ;
2004-11-04 21:35:39 +00:00
if ( tStr . Length ( ) > ( ( int ) ( sizeof ( wxGetApp ( ) . params . DirPath ) / sizeof ( wxChar ) ) - 1 ) )
2000-01-25 16:18:40 +00:00
{
wxString errmsg ;
2004-11-04 21:35:39 +00:00
errmsg . Printf ( wxT ( " DirPath is longer than the data structure to hold it. \n 'Cparameter.DirPath' must have a larger character array \n to handle a data source with this long of a name \n \n The password currently specified is %d characters long. " ) , tStr . Length ( ) ) ;
wxMessageBox ( errmsg , wxT ( " Internal program error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2000-07-15 19:51:35 +00:00
wxStrcpy ( wxGetApp ( ) . params . DirPath , tStr ) ;
2004-05-25 19:57:33 +00:00
return true ;
1998-07-28 09:43:44 +00:00
} // CparameterDlg::GetData()
1998-12-30 17:40:53 +00:00
bool CparameterDlg : : Save ( )
1998-07-28 09:43:44 +00:00
{
2001-02-03 17:52:58 +00:00
// Copy the current params in case user cancels changing
// the params, so that we can reset them.
2000-01-25 16:18:40 +00:00
if ( ! GetData ( ) )
{
2001-02-03 17:52:58 +00:00
wxGetApp ( ) . params = savedParamSettings ;
2004-05-25 19:57:33 +00:00
return false ;
2000-01-25 16:18:40 +00:00
}
2001-02-03 17:52:58 +00:00
wxGetApp ( ) . WriteParamFile ( wxGetApp ( ) . params ) ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
return true ;
1998-07-28 09:43:44 +00:00
} // CparameterDlg::Save()
void CparameterDlg : : FillDataSourceList ( )
{
2004-11-04 21:35:39 +00:00
wxChar Dsn [ SQL_MAX_DSN_LENGTH + 1 ] ;
wxChar DsDesc [ 254 + 1 ] ;
2004-08-02 17:52:12 +00:00
wxSortedArrayString strArr ;
1998-07-28 09:43:44 +00:00
2001-02-03 17:52:58 +00:00
while ( wxDbGetDataSource ( wxGetApp ( ) . DbConnectInf - > GetHenv ( ) , Dsn ,
2004-11-04 21:35:39 +00:00
SQL_MAX_DSN_LENGTH , DsDesc , 254 ) )
2004-08-02 17:52:12 +00:00
{
strArr . Add ( Dsn ) ;
}
1998-07-28 09:43:44 +00:00
2004-11-04 21:35:39 +00:00
for ( size_t i = 0 ; i < strArr . GetCount ( ) ; i + + )
2004-05-25 19:57:33 +00:00
{
2004-08-02 17:52:12 +00:00
pParamODBCSourceList - > Append ( strArr [ i ] . c_str ( ) ) ;
2004-05-25 19:57:33 +00:00
}
2000-08-08 06:11:51 +00:00
2001-04-11 14:20:56 +00:00
} // CparameterDlg::FillDataSourceList()
1998-07-28 09:43:44 +00:00
1999-01-12 17:53:45 +00:00
BEGIN_EVENT_TABLE ( CqueryDlg , wxDialog )
2004-05-25 19:57:33 +00:00
EVT_BUTTON ( wxID_ANY , CqueryDlg : : OnButton )
1999-02-05 23:55:04 +00:00
EVT_CLOSE ( CqueryDlg : : OnCloseWindow )
1999-01-12 17:53:45 +00:00
END_EVENT_TABLE ( )
2000-08-08 06:11:51 +00:00
2004-10-06 20:54:57 +00:00
1998-07-28 09:43:44 +00:00
// CqueryDlg() constructor
2004-10-06 20:54:57 +00:00
CqueryDlg : : CqueryDlg ( wxWindow * parent , wxDb * pDb , wxChar * tblName [ ] ,
2001-02-04 16:01:33 +00:00
const wxString & pWhereArg ) :
2004-05-25 19:57:33 +00:00
wxDialog ( parent , QUERY_DIALOG , wxT ( " Query " ) , wxDefaultPosition , wxSize ( 480 , 360 ) )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxBeginBusyCursor ( ) ;
colInf = 0 ;
dbTable = 0 ;
masterTableName = tblName [ 0 ] ;
2004-05-25 19:57:33 +00:00
widgetPtrsSet = false ;
2000-01-25 16:18:40 +00:00
pDB = pDb ;
// Initialize the WHERE clause from the string passed in
2001-02-04 16:01:33 +00:00
pWhere = pWhereArg ; // Save a pointer to the output buffer
if ( pWhere . Length ( ) > ( unsigned int ) DB_MAX_WHERE_CLAUSE_LEN ) // Check the length of the buffer passed in
2000-01-25 16:18:40 +00:00
{
wxString s ;
2001-02-01 20:17:15 +00:00
s . Printf ( wxT ( " Maximum where clause length exceeded. \n Length must be less than %d " ) , DB_MAX_WHERE_CLAUSE_LEN + 1 ) ;
wxMessageBox ( s , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
Close ( ) ;
return ;
}
2004-11-04 21:35:39 +00:00
pQueryCol1Msg = new wxStaticText ( this , QUERY_DIALOG_COL_MSG , wxT ( " Column 1: " ) , wxPoint ( 10 , 10 ) , wxSize ( 69 , 16 ) , 0 , wxT ( " QueryCol1Msg " ) ) ;
pQueryCol1Choice = new wxChoice ( this , QUERY_DIALOG_COL_CHOICE , wxPoint ( 10 , 27 ) , wxSize ( 250 , 27 ) , 0 , 0 , 0 , wxDefaultValidator , wxT ( " QueryCol1Choice " ) ) ;
pQueryNotMsg = new wxStaticText ( this , QUERY_DIALOG_NOT_MSG , wxT ( " NOT " ) , wxPoint ( 268 , 10 ) , wxDefaultSize , 0 , wxT ( " QueryNotMsg " ) ) ;
pQueryNotCheck = new wxCheckBox ( this , QUERY_DIALOG_NOT_CHECKBOX , wxEmptyString , wxPoint ( 275 , 37 ) , wxSize ( 20 , 20 ) , 0 , wxDefaultValidator , wxT ( " QueryNotCheck " ) ) ;
2000-01-25 16:18:40 +00:00
wxString choice_strings [ 9 ] ;
2001-02-01 20:17:15 +00:00
choice_strings [ 0 ] = wxT ( " = " ) ;
choice_strings [ 1 ] = wxT ( " < " ) ;
choice_strings [ 2 ] = wxT ( " > " ) ;
choice_strings [ 3 ] = wxT ( " <= " ) ;
choice_strings [ 4 ] = wxT ( " >= " ) ;
choice_strings [ 5 ] = wxT ( " Begins " ) ;
choice_strings [ 6 ] = wxT ( " Contains " ) ;
choice_strings [ 7 ] = wxT ( " Like " ) ;
choice_strings [ 8 ] = wxT ( " Between " ) ;
2004-05-25 19:57:33 +00:00
pQueryOperatorMsg = new wxStaticText ( this , QUERY_DIALOG_OP_MSG , wxT ( " Operator: " ) , wxPoint ( 305 , 10 ) , wxDefaultSize , 0 , wxT ( " QueryOperatorMsg " ) ) ;
2001-02-01 20:17:15 +00:00
pQueryOperatorChoice = new wxChoice ( this , QUERY_DIALOG_OP_CHOICE , wxPoint ( 305 , 27 ) , wxSize ( 80 , 27 ) , 9 , choice_strings , 0 , wxDefaultValidator , wxT ( " QueryOperatorChoice " ) ) ;
pQueryCol2Msg = new wxStaticText ( this , QUERY_DIALOG_COL2_MSG , wxT ( " Column 2: " ) , wxPoint ( 10 , 65 ) , wxSize ( 69 , 16 ) , 0 , wxT ( " QueryCol2Msg " ) ) ;
pQueryCol2Choice = new wxChoice ( this , QUERY_DIALOG_COL2_CHOICE , wxPoint ( 10 , 82 ) , wxSize ( 250 , 27 ) , 0 , 0 , 0 , wxDefaultValidator , wxT ( " QueryCol2Choice " ) ) ;
2004-05-25 19:57:33 +00:00
pQuerySqlWhereMsg = new wxStaticText ( this , QUERY_DIALOG_WHERE_MSG , wxT ( " SQL where clause: " ) , wxPoint ( 10 , 141 ) , wxDefaultSize , 0 , wxT ( " QuerySqlWhereMsg " ) ) ;
2004-11-04 21:35:39 +00:00
pQuerySqlWhereMtxt = new wxTextCtrl ( this , QUERY_DIALOG_WHERE_TEXT , wxEmptyString , wxPoint ( 10 , 159 ) , wxSize ( 377 , 134 ) , wxTE_MULTILINE , wxDefaultValidator , wxT ( " QuerySqlWhereMtxt " ) ) ;
2001-02-01 20:17:15 +00:00
pQueryAddBtn = new wxButton ( this , QUERY_DIALOG_ADD , wxT ( " &Add " ) , wxPoint ( 406 , 24 ) , wxSize ( 56 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryAddBtn " ) ) ;
pQueryAndBtn = new wxButton ( this , QUERY_DIALOG_AND , wxT ( " A&nd " ) , wxPoint ( 406 , 58 ) , wxSize ( 56 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryAndBtn " ) ) ;
pQueryOrBtn = new wxButton ( this , QUERY_DIALOG_OR , wxT ( " &Or " ) , wxPoint ( 406 , 92 ) , wxSize ( 56 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryOrBtn " ) ) ;
pQueryLParenBtn = new wxButton ( this , QUERY_DIALOG_LPAREN , wxT ( " ( " ) , wxPoint ( 406 , 126 ) , wxSize ( 26 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryLParenBtn " ) ) ;
pQueryRParenBtn = new wxButton ( this , QUERY_DIALOG_RPAREN , wxT ( " ) " ) , wxPoint ( 436 , 126 ) , wxSize ( 26 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryRParenBtn " ) ) ;
pQueryDoneBtn = new wxButton ( this , QUERY_DIALOG_DONE , wxT ( " &Done " ) , wxPoint ( 406 , 185 ) , wxSize ( 56 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryDoneBtn " ) ) ;
pQueryClearBtn = new wxButton ( this , QUERY_DIALOG_CLEAR , wxT ( " C&lear " ) , wxPoint ( 406 , 218 ) , wxSize ( 56 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryClearBtn " ) ) ;
pQueryCountBtn = new wxButton ( this , QUERY_DIALOG_COUNT , wxT ( " &Count " ) , wxPoint ( 406 , 252 ) , wxSize ( 56 , 26 ) , 0 , wxDefaultValidator , wxT ( " QueryCountBtn " ) ) ;
2004-05-25 19:57:33 +00:00
pQueryValue1Msg = new wxStaticText ( this , QUERY_DIALOG_VALUE1_MSG , wxT ( " Value: " ) , wxPoint ( 277 , 66 ) , wxDefaultSize , 0 , wxT ( " QueryValue1Msg " ) ) ;
2004-11-04 21:35:39 +00:00
pQueryValue1Txt = new wxTextCtrl ( this , QUERY_DIALOG_VALUE1_TEXT , wxEmptyString , wxPoint ( 277 , 83 ) , wxSize ( 108 , 25 ) , 0 , wxDefaultValidator , wxT ( " QueryValue1Txt " ) ) ;
2004-05-25 19:57:33 +00:00
pQueryValue2Msg = new wxStaticText ( this , QUERY_DIALOG_VALUE2_MSG , wxT ( " AND " ) , wxPoint ( 238 , 126 ) , wxDefaultSize , 0 , wxT ( " QueryValue2Msg " ) ) ;
2004-11-04 21:35:39 +00:00
pQueryValue2Txt = new wxTextCtrl ( this , QUERY_DIALOG_VALUE2_TEXT , wxEmptyString , wxPoint ( 277 , 120 ) , wxSize ( 108 , 25 ) , 0 , wxDefaultValidator , wxT ( " QueryValue2Txt " ) ) ;
pQueryHintGrp = new wxStaticBox ( this , QUERY_DIALOG_HINT_GROUP , wxEmptyString , wxPoint ( 10 , 291 ) , wxSize ( 377 , 40 ) , 0 , wxT ( " QueryHintGrp " ) ) ;
pQueryHintMsg = new wxStaticText ( this , QUERY_DIALOG_HINT_MSG , wxEmptyString , wxPoint ( 16 , 306 ) , wxDefaultSize , 0 , wxT ( " QueryHintMsg " ) ) ;
2000-01-25 16:18:40 +00:00
2004-05-25 19:57:33 +00:00
widgetPtrsSet = true ;
2000-01-25 16:18:40 +00:00
// Initialize the dialog
wxString qualName ;
2001-02-01 20:17:15 +00:00
pQueryCol2Choice - > Append ( wxT ( " VALUE --> " ) ) ;
2000-01-25 16:18:40 +00:00
colInf = pDB - > GetColumns ( tblName ) ;
if ( ! colInf )
{
wxEndBusyCursor ( ) ;
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " ODBC error during GetColumns() \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
return ;
}
int i ;
2000-07-15 19:51:35 +00:00
for ( i = 0 ; colInf [ i ] . colName & & wxStrlen ( colInf [ i ] . colName ) ; i + + )
2000-01-25 16:18:40 +00:00
{
// If there is more than one table being queried, qualify
// the column names with the table name prefix.
2000-07-15 19:51:35 +00:00
if ( tblName [ 1 ] & & wxStrlen ( tblName [ 1 ] ) )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
qualName . Printf ( wxT ( " %s.%s " ) , colInf [ i ] . tableName , colInf [ i ] . colName ) ;
2000-01-25 16:18:40 +00:00
pQueryCol1Choice - > Append ( qualName ) ;
pQueryCol2Choice - > Append ( qualName ) ;
}
else // Single table query, append just the column names
{
pQueryCol1Choice - > Append ( colInf [ i ] . colName ) ;
pQueryCol2Choice - > Append ( colInf [ i ] . colName ) ;
}
}
pQueryCol1Choice - > SetSelection ( 0 ) ;
pQueryCol2Choice - > SetSelection ( 0 ) ;
pQueryOperatorChoice - > SetSelection ( 0 ) ;
2004-05-25 19:57:33 +00:00
pQueryValue2Msg - > Show ( false ) ;
pQueryValue2Txt - > Show ( false ) ;
2000-01-25 16:18:40 +00:00
pQueryHintMsg - > SetLabel ( langQRY_EQ ) ;
2001-02-04 16:01:33 +00:00
pQuerySqlWhereMtxt - > SetValue ( pWhere . c_str ( ) ) ;
2000-01-25 16:18:40 +00:00
wxEndBusyCursor ( ) ;
// Display the dialog window
Centre ( wxBOTH ) ;
ShowModal ( ) ;
1998-07-28 09:43:44 +00:00
} // CqueryDlg() constructor
2004-11-04 21:35:39 +00:00
CqueryDlg : : ~ CqueryDlg ( )
{
} // CqueryDlg::~CqueryDlg() destructor
2000-08-08 06:11:51 +00:00
void CqueryDlg : : OnButton ( wxCommandEvent & event )
1999-01-12 17:53:45 +00:00
{
wxWindow * win = ( wxWindow * ) event . GetEventObject ( ) ;
OnCommand ( * win , event ) ;
2000-08-08 06:11:51 +00:00
} // CqueryDlg::OnButton()
1999-01-12 17:53:45 +00:00
2004-02-08 11:53:48 +00:00
void CqueryDlg : : OnCommand ( wxWindow & win , wxCommandEvent & WXUNUSED ( event ) )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Widget pointers won't be set when the dialog is constructed.
// Control is passed through this function once for each widget on
// a dialog as the dialog is constructed.
if ( ! widgetPtrsSet )
return ;
wxString widgetName = win . GetName ( ) ;
// Operator choice box
if ( widgetName = = pQueryOperatorChoice - > GetName ( ) )
{
// Set the help text
switch ( ( qryOp ) pQueryOperatorChoice - > GetSelection ( ) )
{
2000-08-08 06:11:51 +00:00
case qryOpEQ :
pQueryHintMsg - > SetLabel ( langQRY_EQ ) ;
break ;
case qryOpLT :
pQueryHintMsg - > SetLabel ( langQRY_LT ) ;
break ;
case qryOpGT :
pQueryHintMsg - > SetLabel ( langQRY_GT ) ;
break ;
case qryOpLE :
pQueryHintMsg - > SetLabel ( langQRY_LE ) ;
break ;
case qryOpGE :
pQueryHintMsg - > SetLabel ( langQRY_GE ) ;
break ;
case qryOpBEGINS :
pQueryHintMsg - > SetLabel ( langQRY_BEGINS ) ;
break ;
case qryOpCONTAINS :
pQueryHintMsg - > SetLabel ( langQRY_CONTAINS ) ;
break ;
case qryOpLIKE :
pQueryHintMsg - > SetLabel ( langQRY_LIKE ) ;
break ;
case qryOpBETWEEN :
pQueryHintMsg - > SetLabel ( langQRY_BETWEEN ) ;
break ;
2000-01-25 16:18:40 +00:00
}
// Hide the value2 widget
2004-05-25 19:57:33 +00:00
pQueryValue2Msg - > Show ( false ) ; // BETWEEN will show this widget
pQueryValue2Txt - > Show ( false ) ; // BETWEEN will show this widget
2000-01-25 16:18:40 +00:00
// Disable the NOT operator for <, <=, >, >=
switch ( ( qryOp ) pQueryOperatorChoice - > GetSelection ( ) )
{
2000-08-08 06:11:51 +00:00
case qryOpLT :
case qryOpGT :
case qryOpLE :
case qryOpGE :
pQueryNotCheck - > SetValue ( 0 ) ;
2004-05-25 19:57:33 +00:00
pQueryNotCheck - > Enable ( false ) ;
2000-08-08 06:11:51 +00:00
break ;
default :
2004-05-25 19:57:33 +00:00
pQueryNotCheck - > Enable ( true ) ;
2000-08-08 06:11:51 +00:00
break ;
2000-01-25 16:18:40 +00:00
}
// Manipulate the dialog to handle the selected operator
switch ( ( qryOp ) pQueryOperatorChoice - > GetSelection ( ) )
{
2000-08-08 06:11:51 +00:00
case qryOpEQ :
case qryOpLT :
case qryOpGT :
case qryOpLE :
case qryOpGE :
2004-05-25 19:57:33 +00:00
pQueryCol2Choice - > Enable ( true ) ;
2000-08-08 06:11:51 +00:00
if ( pQueryCol2Choice - > GetSelection ( ) ) // Column name is highlighted
{
2004-05-25 19:57:33 +00:00
pQueryValue1Msg - > Show ( false ) ;
pQueryValue1Txt - > Show ( false ) ;
2000-08-08 06:11:51 +00:00
}
else // "Value" is highlighted
{
2004-05-25 19:57:33 +00:00
pQueryValue1Msg - > Show ( true ) ;
pQueryValue1Txt - > Show ( true ) ;
2000-08-08 06:11:51 +00:00
pQueryValue1Txt - > SetFocus ( ) ;
}
break ;
case qryOpBEGINS :
case qryOpCONTAINS :
case qryOpLIKE :
pQueryCol2Choice - > SetSelection ( 0 ) ;
2004-05-25 19:57:33 +00:00
pQueryCol2Choice - > Enable ( false ) ;
pQueryValue1Msg - > Show ( true ) ;
pQueryValue1Txt - > Show ( true ) ;
2000-01-25 16:18:40 +00:00
pQueryValue1Txt - > SetFocus ( ) ;
2000-08-08 06:11:51 +00:00
break ;
case qryOpBETWEEN :
pQueryCol2Choice - > SetSelection ( 0 ) ;
2004-05-25 19:57:33 +00:00
pQueryCol2Choice - > Enable ( false ) ;
pQueryValue2Msg - > Show ( true ) ;
pQueryValue2Txt - > Show ( true ) ;
pQueryValue1Msg - > Show ( true ) ;
pQueryValue1Txt - > Show ( true ) ;
2000-08-08 06:11:51 +00:00
pQueryValue1Txt - > SetFocus ( ) ;
break ;
2000-01-25 16:18:40 +00:00
}
return ;
} // Operator choice box
// Column 2 choice
if ( widgetName = = pQueryCol2Choice - > GetName ( ) )
{
if ( pQueryCol2Choice - > GetSelection ( ) ) // Column name is highlighted
{
2004-05-25 19:57:33 +00:00
pQueryValue1Msg - > Show ( false ) ;
pQueryValue1Txt - > Show ( false ) ;
2000-01-25 16:18:40 +00:00
}
else // "Value" is highlighted
{
2004-05-25 19:57:33 +00:00
pQueryValue1Msg - > Show ( true ) ;
pQueryValue1Txt - > Show ( true ) ;
2000-01-25 16:18:40 +00:00
pQueryValue1Txt - > SetFocus ( ) ;
}
return ;
} // Column 2 choice
// Add button
if ( widgetName = = pQueryAddBtn - > GetName ( ) )
{
ProcessAddBtn ( ) ;
return ;
} // Add button
// And button
if ( widgetName = = pQueryAndBtn - > GetName ( ) )
{
2001-02-01 20:17:15 +00:00
AppendToWhere ( wxT ( " AND \n " ) ) ;
2000-01-25 16:18:40 +00:00
return ;
} // And button
// Or button
if ( widgetName = = pQueryOrBtn - > GetName ( ) )
{
2001-02-01 20:17:15 +00:00
AppendToWhere ( wxT ( " OR \n " ) ) ;
2000-01-25 16:18:40 +00:00
return ;
} // Or button
// Left Paren button
if ( widgetName = = pQueryLParenBtn - > GetName ( ) )
{
2001-02-01 20:17:15 +00:00
AppendToWhere ( wxT ( " ( " ) ) ;
2000-01-25 16:18:40 +00:00
return ;
} // Left Paren button
// Right paren button
if ( widgetName = = pQueryRParenBtn - > GetName ( ) )
{
2001-02-01 20:17:15 +00:00
AppendToWhere ( wxT ( " ) " ) ) ;
2000-01-25 16:18:40 +00:00
return ;
} // Right Paren button
// Done button
if ( widgetName = = pQueryDoneBtn - > GetName ( ) )
{
// Be sure the where clause will not overflow the output buffer
2000-08-08 06:11:51 +00:00
if ( wxStrlen ( pQuerySqlWhereMtxt - > GetValue ( ) ) > ( unsigned int ) DB_MAX_WHERE_CLAUSE_LEN )
2000-01-25 16:18:40 +00:00
{
wxString s ;
2001-02-01 20:17:15 +00:00
s . Printf ( wxT ( " Maximum where clause length exceeded. \n Length must be less than %d " ) , DB_MAX_WHERE_CLAUSE_LEN + 1 ) ;
wxMessageBox ( s , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
return ;
}
// Validate the where clause for things such as matching parens
if ( ! ValidateWhereClause ( ) )
return ;
// Copy the where clause to the output buffer and exit
2001-02-04 16:01:33 +00:00
pWhere = pQuerySqlWhereMtxt - > GetValue ( ) ;
2000-01-25 16:18:40 +00:00
Close ( ) ;
return ;
} // Done button
// Clear button
if ( widgetName = = pQueryClearBtn - > GetName ( ) )
{
2004-11-04 21:35:39 +00:00
bool Ok = ( wxMessageBox ( wxT ( " Are you sure you wish to clear the Query? " ) , wxT ( " Confirm " ) , wxYES_NO | wxICON_QUESTION ) = = wxYES ) ;
2000-01-25 16:18:40 +00:00
if ( Ok )
2004-11-04 21:35:39 +00:00
pQuerySqlWhereMtxt - > SetValue ( wxEmptyString ) ;
2000-01-25 16:18:40 +00:00
return ;
} // Clear button
// Count button
if ( widgetName = = pQueryCountBtn - > GetName ( ) )
{
wxBeginBusyCursor ( ) ;
ProcessCountBtn ( ) ;
wxEndBusyCursor ( ) ;
return ;
} // Count button
1998-07-28 09:43:44 +00:00
} // CqueryDlg::OnCommand
2004-02-08 11:53:48 +00:00
void CqueryDlg : : OnCloseWindow ( wxCloseEvent & WXUNUSED ( event ) )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
// Clean up
2001-05-15 00:58:09 +00:00
wxDELETEA ( colInf ) ;
2000-01-25 16:18:40 +00:00
2001-05-15 00:58:09 +00:00
wxDELETE ( dbTable ) ;
2000-01-25 16:18:40 +00:00
GetParent ( ) - > SetFocus ( ) ;
while ( wxIsBusy ( ) )
wxEndBusyCursor ( ) ;
1998-07-28 09:43:44 +00:00
2004-05-25 19:57:33 +00:00
Show ( false ) ;
2000-08-08 06:11:51 +00:00
SetReturnCode ( 1 ) ; // added so BoundsChecker would not report use of uninitialized variable
1999-02-05 23:55:04 +00:00
2000-08-08 06:11:51 +00:00
this - > Destroy ( ) ;
1999-02-05 23:55:04 +00:00
} // CqueryDlg::OnCloseWindow()
1998-07-28 09:43:44 +00:00
2001-02-01 20:17:15 +00:00
void CqueryDlg : : AppendToWhere ( wxChar * s )
1998-07-28 09:43:44 +00:00
{
2000-08-08 06:11:51 +00:00
wxString whereStr = pQuerySqlWhereMtxt - > GetValue ( ) ;
whereStr + = s ;
pQuerySqlWhereMtxt - > SetValue ( whereStr ) ;
1998-07-28 09:43:44 +00:00
} // CqueryDlg::AppendToWhere()
void CqueryDlg : : ProcessAddBtn ( )
{
2000-01-25 16:18:40 +00:00
qryOp oper = ( qryOp ) pQueryOperatorChoice - > GetSelection ( ) ;
// Verify that eveything is filled in correctly
if ( pQueryCol2Choice - > GetSelection ( ) = = 0 ) // "Value" is selected
{
// Verify that value 1 is filled in
2000-07-15 19:51:35 +00:00
if ( wxStrlen ( pQueryValue1Txt - > GetValue ( ) ) = = 0 )
2000-01-25 16:18:40 +00:00
{
wxBell ( ) ;
pQueryValue1Txt - > SetFocus ( ) ;
return ;
}
// For the BETWEEN operator, value 2 must be filled in as well
if ( oper = = qryOpBETWEEN & &
2000-07-15 19:51:35 +00:00
wxStrlen ( pQueryValue2Txt - > GetValue ( ) ) = = 0 )
2000-01-25 16:18:40 +00:00
{
wxBell ( ) ;
pQueryValue2Txt - > SetFocus ( ) ;
return ;
}
}
// Build the expression and append it to the where clause window
wxString s = pQueryCol1Choice - > GetStringSelection ( ) ;
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
if ( pQueryNotCheck - > GetValue ( ) & & ( oper ! = qryOpEQ ) )
2001-02-01 20:17:15 +00:00
s + = wxT ( " NOT " ) ;
2004-10-06 20:54:57 +00:00
2000-01-25 16:18:40 +00:00
switch ( oper )
{
case qryOpEQ :
if ( pQueryNotCheck - > GetValue ( ) ) // NOT box is checked
2001-02-01 20:17:15 +00:00
s + = wxT ( " <> " ) ;
2000-01-25 16:18:40 +00:00
else
2001-02-01 20:17:15 +00:00
s + = wxT ( " = " ) ;
2000-01-25 16:18:40 +00:00
break ;
case qryOpLT :
2001-02-01 20:17:15 +00:00
s + = wxT ( " < " ) ;
2000-01-25 16:18:40 +00:00
break ;
case qryOpGT :
2001-02-01 20:17:15 +00:00
s + = wxT ( " > " ) ;
2000-01-25 16:18:40 +00:00
break ;
case qryOpLE :
2001-02-01 20:17:15 +00:00
s + = wxT ( " <= " ) ;
2000-01-25 16:18:40 +00:00
break ;
case qryOpGE :
2001-02-01 20:17:15 +00:00
s + = wxT ( " >= " ) ;
2000-01-25 16:18:40 +00:00
break ;
case qryOpBEGINS :
case qryOpCONTAINS :
case qryOpLIKE :
2001-02-01 20:17:15 +00:00
s + = wxT ( " LIKE " ) ;
2000-01-25 16:18:40 +00:00
break ;
case qryOpBETWEEN :
2001-02-01 20:17:15 +00:00
s + = wxT ( " BETWEEN " ) ;
2000-01-25 16:18:40 +00:00
break ;
}
2001-02-01 20:17:15 +00:00
s + = wxT ( " " ) ;
2000-01-25 16:18:40 +00:00
int col1Idx = pQueryCol1Choice - > GetSelection ( ) ;
2004-05-25 19:57:33 +00:00
bool quote = false ;
2000-01-25 16:18:40 +00:00
if ( colInf [ col1Idx ] . sqlDataType = = SQL_VARCHAR | |
oper = = qryOpBEGINS | |
oper = = qryOpCONTAINS | |
oper = = qryOpLIKE )
2004-05-25 19:57:33 +00:00
quote = true ;
2000-01-25 16:18:40 +00:00
if ( pQueryCol2Choice - > GetSelection ( ) ) // Column name
s + = pQueryCol2Choice - > GetStringSelection ( ) ;
else // Column 2 is a "value"
{
if ( quote )
2001-02-01 20:17:15 +00:00
s + = wxT ( " ' " ) ;
2000-01-25 16:18:40 +00:00
if ( oper = = qryOpCONTAINS )
2001-02-01 20:17:15 +00:00
s + = wxT ( " % " ) ;
2000-01-25 16:18:40 +00:00
s + = pQueryValue1Txt - > GetValue ( ) ;
if ( oper = = qryOpCONTAINS | | oper = = qryOpBEGINS )
2001-02-01 20:17:15 +00:00
s + = wxT ( " % " ) ;
2000-01-25 16:18:40 +00:00
if ( quote )
2001-02-01 20:17:15 +00:00
s + = wxT ( " ' " ) ;
2000-01-25 16:18:40 +00:00
}
if ( oper = = qryOpBETWEEN )
{
2001-02-01 20:17:15 +00:00
s + = wxT ( " AND " ) ;
2000-01-25 16:18:40 +00:00
if ( quote )
2001-02-01 20:17:15 +00:00
s + = wxT ( " ' " ) ;
2000-01-25 16:18:40 +00:00
s + = pQueryValue2Txt - > GetValue ( ) ;
if ( quote )
2001-02-01 20:17:15 +00:00
s + = wxT ( " ' " ) ;
2000-01-25 16:18:40 +00:00
}
2001-02-01 20:17:15 +00:00
AppendToWhere ( ( wxChar * ) ( const wxChar * ) s ) ;
1998-07-28 09:43:44 +00:00
} // CqueryDlg::ProcessAddBtn()
void CqueryDlg : : ProcessCountBtn ( )
{
2000-01-25 16:18:40 +00:00
if ( ! ValidateWhereClause ( ) )
return ;
2001-04-11 14:20:56 +00:00
if ( ! dbTable ) // wxDbTable object needs to be created and opened
2000-01-25 16:18:40 +00:00
{
2004-11-10 12:12:37 +00:00
dbTable = new wxDbTable ( pDB , masterTableName , 0 , ( const wxString & ) wxEmptyString ,
2004-10-06 20:54:57 +00:00
! wxDB_QUERY_ONLY ,
2001-04-11 14:20:56 +00:00
wxGetApp ( ) . DbConnectInf - > GetDefaultDir ( ) ) ;
if ( ! dbTable )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " Memory allocation failed creating a wxDbTable object. " ) , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
return ;
}
if ( ! dbTable - > Open ( ) )
{
wxString tStr ;
2001-06-10 17:12:56 +00:00
tStr = wxT ( " ODBC error during Open() \n \n " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2000-01-25 16:18:40 +00:00
return ;
}
}
// Count() with WHERE clause
2000-07-15 19:51:35 +00:00
wxString whereStr ;
2000-03-01 01:01:01 +00:00
whereStr = pQuerySqlWhereMtxt - > GetValue ( ) ;
2000-07-15 19:51:35 +00:00
dbTable - > SetWhereClause ( whereStr . c_str ( ) ) ;
2001-02-01 20:17:15 +00:00
2000-01-25 16:18:40 +00:00
ULONG whereCnt = dbTable - > Count ( ) ;
// Count() of all records in the table
2004-11-04 21:35:39 +00:00
dbTable - > SetWhereClause ( wxEmptyString ) ;
2000-01-25 16:18:40 +00:00
ULONG totalCnt = dbTable - > Count ( ) ;
if ( whereCnt > 0 | | totalCnt = = 0 )
{
wxString tStr ;
2001-02-01 20:17:15 +00:00
tStr . Printf ( wxT ( " %lu of %lu records match the query criteria. " ) , whereCnt , totalCnt ) ;
wxMessageBox ( tStr , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2000-01-25 16:18:40 +00:00
}
else
{
wxString tStr ;
2001-02-01 20:17:15 +00:00
tStr . Printf ( wxT ( " %lu of %lu records match the query criteria. \n \n Either the criteria entered produced a result set \n with no records, or there was a syntactical error \n in the clause you entered. \n \n Press the details button to see if any database errors were reported. " ) , whereCnt , totalCnt ) ;
wxMessageBox ( tStr , wxT ( " Notice... " ) , wxOK | wxICON_INFORMATION ) ;
2000-01-25 16:18:40 +00:00
}
// After a wxMessageBox, the focus does not necessarily return to the
// window which was the focus when the message box popped up, so return
// focus to the Query dialog for certain
SetFocus ( ) ;
1998-07-28 09:43:44 +00:00
} // CqueryDlg::ProcessCountBtn()
1998-12-30 17:40:53 +00:00
bool CqueryDlg : : ValidateWhereClause ( )
1998-07-28 09:43:44 +00:00
{
2000-01-25 16:18:40 +00:00
wxString where = pQuerySqlWhereMtxt - > GetValue ( ) ;
2001-02-01 20:17:15 +00:00
if ( where . Freq ( wxT ( ' ( ' ) ) ! = where . Freq ( wxT ( ' ) ' ) ) )
2000-01-25 16:18:40 +00:00
{
2001-02-01 20:17:15 +00:00
wxMessageBox ( wxT ( " There are mismatched parenthesis in the constructed where clause " ) , wxT ( " Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return ( false ) ;
2000-01-25 16:18:40 +00:00
}
// After a wxMessageBox, the focus does not necessarily return to the
// window which was the focus when the message box popped up, so return
// focus to the Query dialog for certain
SetFocus ( ) ;
2004-05-25 19:57:33 +00:00
return ( true ) ;
1998-07-28 09:43:44 +00:00
} // CqueryDlg::ValidateWhereClause()
2000-03-16 19:09:42 +00:00
2004-11-04 21:35:39 +00:00
# ifdef wxODBC_BLOB_SUPPORT
BEGIN_EVENT_TABLE ( CimageDlg , wxDialog )
EVT_CLOSE ( CimageDlg : : OnCloseWindow )
END_EVENT_TABLE ( )
CimageDlg : : CimageDlg ( wxWindow * parent , wxChar * pImageData , off_t iSize )
: wxDialog ( parent , IMAGE_DIALOG , wxT ( " BLOB Image " ) , wxDefaultPosition , wxDefaultSize ) ,
2004-11-22 17:48:33 +00:00
m_pDisplayBmp ( NULL ) ,
2004-11-04 21:35:39 +00:00
m_pBmp ( NULL ) ,
2004-11-22 17:48:33 +00:00
m_pImage ( NULL )
2004-11-04 21:35:39 +00:00
{
wxMemoryInputStream inStream ( pImageData , iSize ) ;
if ( inStream . IsOk ( ) )
{
m_pImage = new wxImage ( inStream , wxBITMAP_TYPE_ANY ) ;
if ( m_pImage - > Ok ( ) )
{
m_pBmp = new wxBitmap ( m_pImage ) ;
m_pDisplayBmp = new wxStaticBitmap ( this , IMAGE_DIALOG_STATIC_BMP , * m_pBmp , wxPoint ( 5 , 5 ) , wxDefaultSize ) ;
SetSize ( m_pBmp - > GetWidth ( ) + 10 , m_pBmp - > GetHeight ( ) + 30 ) ;
}
}
}
CimageDlg : : ~ CimageDlg ( )
{
if ( m_pImage )
delete m_pImage ;
if ( m_pBmp )
delete m_pBmp ;
2000-03-16 19:09:42 +00:00
2004-11-04 21:35:39 +00:00
if ( m_pDisplayBmp )
delete m_pDisplayBmp ;
}
void CimageDlg : : OnCloseWindow ( wxCloseEvent & WXUNUSED ( event ) )
{
GetParent ( ) - > SetFocus ( ) ;
Show ( false ) ;
this - > Destroy ( ) ;
}
# endif
2000-03-16 19:09:42 +00:00
2001-05-15 13:12:36 +00:00
void DisplayDbDiagnostics ( wxDb * pDb )
{
2001-05-23 13:48:04 +00:00
wxString s , t ;
2004-05-25 19:57:33 +00:00
bool comma ;
2001-05-23 13:48:04 +00:00
2004-05-18 02:43:53 +00:00
s = wxT ( " Diagnostics Output \n " ) ;
s + = langDBINF_DB_NAME ;
2001-05-23 13:48:04 +00:00
s + = pDb - > dbInf . dbmsName ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_DB_VER ;
s + = pDb - > dbInf . dbmsVer ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_DRIVER_NAME ;
s + = pDb - > dbInf . driverName ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_DRIVER_ODBC_VER ;
s + = pDb - > dbInf . odbcVer ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_DRIVER_MGR_ODBC_VER ;
s + = pDb - > dbInf . drvMgrOdbcVer ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_DRIVER_VER ;
s + = pDb - > dbInf . driverVer ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_SERVER_NAME ;
s + = pDb - > dbInf . serverName ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_FILENAME ;
s + = pDb - > dbInf . databaseName ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_OUTER_JOINS ;
s + = pDb - > dbInf . outerJoins ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_STORED_PROC ;
s + = pDb - > dbInf . procedureSupport ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . maxConnections )
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s%d \n " ) , langDBINF_MAX_HDBC , pDb - > dbInf . maxConnections ) ;
2001-05-23 13:48:04 +00:00
else
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s%s \n " ) , langDBINF_MAX_HDBC , langDBINF_UNLIMITED ) ;
2001-05-23 13:48:04 +00:00
s + = t ;
if ( pDb - > dbInf . maxStmts )
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s%d \n " ) , langDBINF_MAX_HSTMT , pDb - > dbInf . maxStmts ) ;
2001-05-23 13:48:04 +00:00
else
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s%s \n " ) , langDBINF_MAX_HSTMT , langDBINF_UNLIMITED ) ;
2001-05-23 13:48:04 +00:00
s + = t ;
s + = langDBINF_API_LVL ;
switch ( pDb - > dbInf . apiConfLvl )
{
case SQL_OAC_NONE : s + = langDBINF_NONE ; break ;
case SQL_OAC_LEVEL1 : s + = langDBINF_LEVEL1 ; break ;
case SQL_OAC_LEVEL2 : s + = langDBINF_LEVEL2 ; break ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_CLI_LVL ;
switch ( pDb - > dbInf . cliConfLvl )
{
case SQL_OSCC_NOT_COMPLIANT : s + = langDBINF_NOT_COMPLIANT ; break ;
case SQL_OSCC_COMPLIANT : s + = langDBINF_COMPLIANT ; break ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_SQL_LVL ;
switch ( pDb - > dbInf . sqlConfLvl )
{
case SQL_OSC_MINIMUM : s + = langDBINF_MIN_GRAMMAR ; break ;
case SQL_OSC_CORE : s + = langDBINF_CORE_GRAMMAR ; break ;
case SQL_OSC_EXTENDED : s + = langDBINF_EXT_GRAMMAR ; break ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_COMMIT_BEHAVIOR ;
switch ( pDb - > dbInf . cursorCommitBehavior )
{
case SQL_CB_DELETE : s + = langDBINF_DELETE_CURSORS ; break ;
case SQL_CB_CLOSE : s + = langDBINF_CLOSE_CURSORS ; break ;
case SQL_CB_PRESERVE : s + = langDBINF_PRESERVE_CURSORS ; break ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_ROLLBACK_BEHAVIOR ;
switch ( pDb - > dbInf . cursorRollbackBehavior )
{
case SQL_CB_DELETE : s + = langDBINF_DELETE_CURSORS ; break ;
case SQL_CB_CLOSE : s + = langDBINF_CLOSE_CURSORS ; break ;
case SQL_CB_PRESERVE : s + = langDBINF_PRESERVE_CURSORS ; break ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_SUPP_NOT_NULL ;
switch ( pDb - > dbInf . supportNotNullClause )
{
case SQL_NNC_NULL : s + = langNO ; break ;
case SQL_NNC_NON_NULL : s + = langYES ; break ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_SUPP_IEF ;
s + = pDb - > dbInf . supportIEF ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
// DEFAULT setting for "Transaction Isolation Level"
s + = langDBINF_TXN_ISOLATION ;
switch ( pDb - > dbInf . txnIsolation )
{
case SQL_TXN_READ_UNCOMMITTED : s + = langDBINF_READ_UNCOMMITTED ; break ;
case SQL_TXN_READ_COMMITTED : s + = langDBINF_READ_COMMITTED ; break ;
case SQL_TXN_REPEATABLE_READ : s + = langDBINF_REPEATABLE_READ ; break ;
case SQL_TXN_SERIALIZABLE : s + = langDBINF_SERIALIZABLE ; break ;
2001-05-15 13:12:36 +00:00
# ifdef ODBC_V20
2001-05-23 13:48:04 +00:00
case SQL_TXN_VERSIONING : s + = langDBINF_VERSIONING ; break ;
# endif
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
// CURRENT setting for "Transaction Isolation Level"
long txnIsoLvl ;
s + = langDBINF_TXN_ISOLATION_CURR ;
if ( SQLGetConnectOption ( pDb - > GetHDBC ( ) , SQL_TXN_ISOLATION , & txnIsoLvl ) = = SQL_SUCCESS )
{
switch ( txnIsoLvl )
{
case SQL_TXN_READ_UNCOMMITTED : s + = langDBINF_READ_UNCOMMITTED ; break ;
case SQL_TXN_READ_COMMITTED : s + = langDBINF_READ_COMMITTED ; break ;
case SQL_TXN_REPEATABLE_READ : s + = langDBINF_REPEATABLE_READ ; break ;
case SQL_TXN_SERIALIZABLE : s + = langDBINF_SERIALIZABLE ; break ;
2001-05-15 13:12:36 +00:00
# ifdef ODBC_V20
2001-05-23 13:48:04 +00:00
case SQL_TXN_VERSIONING : s + = langDBINF_VERSIONING ; break ;
# endif
}
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2001-11-07 09:26:33 +00:00
# ifdef __VMS__
# pragma message disable incboodep
# endif
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_TXN_ISOLATION_OPTS ;
if ( pDb - > dbInf . txnIsolationOptions & SQL_TXN_READ_UNCOMMITTED )
{ s + = langDBINF_READ_UNCOMMITTED ; comma + + ; }
if ( pDb - > dbInf . txnIsolationOptions & SQL_TXN_READ_COMMITTED )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_READ_COMMITTED ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . txnIsolationOptions & SQL_TXN_REPEATABLE_READ )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_REPEATABLE_READ ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . txnIsolationOptions & SQL_TXN_SERIALIZABLE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_SERIALIZABLE ; }
2001-05-15 13:12:36 +00:00
# ifdef ODBC_V20
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . txnIsolationOptions & SQL_TXN_VERSIONING )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_VERSIONING ; }
2001-05-23 13:48:04 +00:00
# endif
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_FETCH_DIRS ;
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_NEXT )
{ s + = langDBINF_NEXT ; comma + + ; }
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_PRIOR )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_PREV ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_FIRST )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_FIRST ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_LAST )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_LAST ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_ABSOLUTE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_ABSOLUTE ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_RELATIVE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_RELATIVE ; }
2001-05-15 13:12:36 +00:00
# ifdef ODBC_V20
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_RESUME )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_RESUME ; }
2001-05-23 13:48:04 +00:00
# endif
if ( pDb - > dbInf . fetchDirections & SQL_FD_FETCH_BOOKMARK )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_BOOKMARK ; }
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_LOCK_TYPES ;
if ( pDb - > dbInf . lockTypes & SQL_LCK_NO_CHANGE )
{ s + = langDBINF_NO_CHANGE ; comma + + ; }
if ( pDb - > dbInf . lockTypes & SQL_LCK_EXCLUSIVE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_EXCLUSIVE ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . lockTypes & SQL_LCK_UNLOCK )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_UNLOCK ; }
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_POS_OPERS ;
if ( pDb - > dbInf . posOperations & SQL_POS_POSITION )
{ s + = langDBINF_POSITION ; comma + + ; }
if ( pDb - > dbInf . posOperations & SQL_POS_REFRESH )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_REFRESH ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . posOperations & SQL_POS_UPDATE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_UPD ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . posOperations & SQL_POS_DELETE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_DEL ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . posOperations & SQL_POS_ADD )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_ADD ; }
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_POS_STMTS ;
if ( pDb - > dbInf . posStmts & SQL_PS_POSITIONED_DELETE )
{ s + = langDBINF_POS_DEL ; comma + + ; }
if ( pDb - > dbInf . posStmts & SQL_PS_POSITIONED_UPDATE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_POS_UPD ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . posStmts & SQL_PS_SELECT_FOR_UPDATE )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_SELECT_FOR_UPD ; }
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_SCROLL_CONCURR ;
if ( pDb - > dbInf . scrollConcurrency & SQL_SCCO_READ_ONLY )
{ s + = langDBINF_READ_ONLY ; comma + + ; }
if ( pDb - > dbInf . scrollConcurrency & SQL_SCCO_LOCK )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_LOCK ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . scrollConcurrency & SQL_SCCO_OPT_ROWVER )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_OPT_ROWVER ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . scrollConcurrency & SQL_SCCO_OPT_VALUES )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_OPT_VALUES ; }
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_SCROLL_OPTS ;
if ( pDb - > dbInf . scrollOptions & SQL_SO_FORWARD_ONLY )
{ s + = langDBINF_FWD_ONLY ; comma + + ; }
if ( pDb - > dbInf . scrollOptions & SQL_SO_STATIC )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_STATIC ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . scrollOptions & SQL_SO_KEYSET_DRIVEN )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_KEYSET_DRIVEN ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . scrollOptions & SQL_SO_DYNAMIC )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_DYNAMIC ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . scrollOptions & SQL_SO_MIXED )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_MIXED ; }
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-05-25 19:57:33 +00:00
comma = false ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_STATIC_SENS ;
if ( pDb - > dbInf . staticSensitivity & SQL_SS_ADDITIONS )
{ s + = langDBINF_ADDITIONS ; comma + + ; }
if ( pDb - > dbInf . staticSensitivity & SQL_SS_DELETIONS )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_DELETIONS ; }
2001-05-23 13:48:04 +00:00
if ( pDb - > dbInf . staticSensitivity & SQL_SS_UPDATES )
2004-02-08 11:53:48 +00:00
{ if ( comma + + ) s + = wxT ( " , " ) ; s + = langDBINF_UPDATES ; }
s + = wxT ( " \n " ) ;
2001-11-07 09:26:33 +00:00
# ifdef __VMS__
# pragma message enable incboodep
# endif
2001-05-23 13:48:04 +00:00
s + = langDBINF_TXN_CAPABLE ;
switch ( pDb - > dbInf . txnCapable )
{
case SQL_TC_NONE : s + = langNO ; break ;
case SQL_TC_DML : s + = langDBINF_DML_ONLY ; break ;
2004-11-04 21:35:39 +00:00
case SQL_TC_DDL_COMMIT : s + = langDBINF_DDL_COMMIT ; break ;
case SQL_TC_DDL_IGNORE : s + = langDBINF_DDL_IGNORE ; break ;
2001-05-23 13:48:04 +00:00
case SQL_TC_ALL : s + = langDBINF_DDL_AND_DML ; break ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s%lu \n " ) , langDBINF_LOGIN_TIMEOUT , pDb - > dbInf . loginTimeout ) ;
2001-05-23 13:48:04 +00:00
s + = t ;
// Oracle specific information
if ( pDb - > Dbms ( ) = = dbmsORACLE )
{
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_ORACLE_BANNER ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
// Oracle cache hit ratio
SDWORD cb ;
ULONG dbBlockGets ;
2004-02-08 11:53:48 +00:00
pDb - > ExecSql ( wxT ( " SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'db block gets' " ) ) ;
2001-05-23 13:48:04 +00:00
pDb - > GetNext ( ) ;
if ( pDb - > GetData ( 1 , SQL_C_ULONG , & dbBlockGets , 0 , & cb ) )
{
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s: %lu \n " ) , langDBINF_DB_BLOCK_GETS , dbBlockGets ) ;
2001-05-23 13:48:04 +00:00
s + = t ;
}
ULONG consistentGets ;
2004-02-08 11:53:48 +00:00
pDb - > ExecSql ( wxT ( " SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'consistent gets' " ) ) ;
2001-05-23 13:48:04 +00:00
pDb - > GetNext ( ) ;
if ( pDb - > GetData ( 1 , SQL_C_ULONG , & consistentGets , 0 , & cb ) )
{
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s: %lu \n " ) , langDBINF_CONSISTENT_GETS , consistentGets ) ;
2001-05-23 13:48:04 +00:00
s + = t ;
}
ULONG physReads ;
2004-02-08 11:53:48 +00:00
pDb - > ExecSql ( wxT ( " SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'physical reads' " ) ) ;
2001-05-23 13:48:04 +00:00
pDb - > GetNext ( ) ;
if ( pDb - > GetData ( 1 , SQL_C_ULONG , & physReads , 0 , & cb ) )
{
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s: %lu \n " ) , langDBINF_PHYSICAL_READS , physReads ) ;
2001-05-23 13:48:04 +00:00
s + = t ;
}
ULONG hitRatio = ( ULONG ) ( ( 1.00 - ( ( float ) physReads / ( float ) ( dbBlockGets + consistentGets ) ) ) * 100.00 ) ;
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " *** %s: %lu%% \n " ) , langDBINF_CACHE_HIT_RATIO , hitRatio ) ;
2001-05-23 13:48:04 +00:00
s + = t ;
// Tablespace information
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
s + = langDBINF_TABLESPACE_IO ;
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
ULONG physWrites ;
2004-11-04 21:35:39 +00:00
char tablespaceName [ 256 + 1 ] ;
2004-02-08 11:53:48 +00:00
pDb - > ExecSql ( wxT ( " SELECT NAME,PHYRDS,PHYWRTS FROM V$DATAFILE, V$FILESTAT WHERE V$DATAFILE.FILE# = V$FILESTAT.FILE# " ) ) ;
2001-05-23 13:48:04 +00:00
while ( pDb - > GetNext ( ) )
{
2004-11-04 21:35:39 +00:00
pDb - > GetData ( 1 , SQL_C_WXCHAR , tablespaceName , 256 , & cb ) ;
pDb - > GetData ( 2 , SQL_C_ULONG , & physReads , 0 , & cb ) ;
pDb - > GetData ( 3 , SQL_C_ULONG , & physWrites , 0 , & cb ) ;
2004-02-08 11:53:48 +00:00
t . sprintf ( wxT ( " %s \n \t %s: %lu \t %s: %lu \n " ) , tablespaceName ,
2001-05-23 13:48:04 +00:00
langDBINF_PHYSICAL_READS , physReads , langDBINF_PHYSICAL_WRITES , physWrites ) ;
s + = t ;
}
2004-02-08 11:53:48 +00:00
s + = wxT ( " \n " ) ;
2001-05-23 13:48:04 +00:00
}
2001-05-15 13:12:36 +00:00
2004-05-18 02:43:53 +00:00
s + = wxT ( " End of Diagnostics \n " ) ;
2001-05-15 13:12:36 +00:00
wxLogMessage ( s ) ;
} // DisplayDbDiagnostics()
2004-05-18 02:43:53 +00:00
# if wxUSE_GRID
2001-06-10 17:12:56 +00:00
BEGIN_EVENT_TABLE ( DbGridFrame , wxFrame )
// EVT_CLOSE(DbGridFrame::OnCloseWindow)
END_EVENT_TABLE ( )
DbGridFrame : : DbGridFrame ( wxWindow * parent )
2004-05-25 19:57:33 +00:00
: wxFrame ( parent , wxID_ANY , wxT ( " Database Table " ) ,
2002-03-17 14:16:03 +00:00
wxDefaultPosition , wxSize ( 400 , 325 ) )
2001-06-10 17:12:56 +00:00
{
2004-05-25 19:57:33 +00:00
initialized = false ;
2001-06-10 17:12:56 +00:00
}
2004-05-18 02:43:53 +00:00
void DbGridFrame : : OnCloseWindow ( wxCloseEvent & WXUNUSED ( event ) )
2001-06-10 17:12:56 +00:00
{
this - > Destroy ( ) ;
}
bool DbGridFrame : : Initialize ( )
{
2004-05-25 19:57:33 +00:00
wxGrid * grid = new wxGrid ( this , wxID_ANY , wxDefaultPosition ) ;
2001-06-10 17:12:56 +00:00
grid - > RegisterDataType ( wxGRID_VALUE_DATETIME ,
2004-02-08 11:53:48 +00:00
new wxGridCellDateTimeRenderer ( wxT ( " %d %b %Y " ) ) ,
2001-06-10 17:12:56 +00:00
new wxGridCellTextEditor ) ;
# ifdef CHOICEINT
grid - > RegisterDataType ( wxGRID_VALUE_CHOICEINT ,
new wxGridCellEnumRenderer ,
new wxGridCellEnumEditor ) ;
2004-10-06 20:54:57 +00:00
wxString NativeLangChoice ( wxString : : Format ( wxT ( " %s:%s,%s,%s,%s,%s " ) , wxGRID_VALUE_CHOICEINT ,
2001-06-10 17:12:56 +00:00
wxT ( " English " ) ,
wxT ( " French " ) ,
wxT ( " German " ) ,
wxT ( " Spanish " ) ,
2004-10-06 20:54:57 +00:00
wxT ( " Other " ) ) ) ;
2001-06-10 17:12:56 +00:00
# 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 ) ) ) ) ) ) ) ) ) ) ) ) ;
2004-10-06 20:54:57 +00:00
# else
2001-06-10 17:12:56 +00:00
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 ) ;
2004-05-25 19:57:33 +00:00
return false ;
2001-06-10 17:12:56 +00:00
}
if ( ! Contact - > Open ( ) )
{
if ( Contact - > GetDb ( ) - > TableExists ( CONTACT_TABLE_NAME , Contact - > GetDb ( ) - > GetUsername ( ) ,
wxGetApp ( ) . DbConnectInf - > GetDefaultDir ( ) ) )
{
wxString tStr ;
2004-11-22 17:48:33 +00:00
tStr . Printf ( wxT ( " Unable to open the table '%s'. \n \n " ) , CONTACT_TABLE_NAME . c_str ( ) ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
}
2004-05-25 19:57:33 +00:00
return false ;
2001-06-10 17:12:56 +00:00
}
// 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 " ) ;
2004-02-08 11:53:48 +00:00
wxMessageBox ( wxDbLogExtendedErrorMsg ( tStr . c_str ( ) , wxGetApp ( ) . Contact - > GetDb ( ) , __TFILE__ , __LINE__ ) ,
2001-06-10 17:12:56 +00:00
wxT ( " ODBC Error... " ) , wxOK | wxICON_EXCLAMATION ) ;
2004-05-25 19:57:33 +00:00
return false ;
2001-06-10 17:12:56 +00:00
}
// 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 ( ) ;
2004-05-25 19:57:33 +00:00
wxDbGridTableBase * db = new wxDbGridTableBase ( Contact , cols , wxUSE_QUERY , true ) ;
2001-06-10 17:12:56 +00:00
delete cols ;
2004-05-25 19:57:33 +00:00
grid - > SetTable ( db , true ) ;
2001-06-10 17:12:56 +00:00
grid - > SetMargins ( 0 , 0 ) ;
2001-05-15 13:12:36 +00:00
2001-06-10 17:12:56 +00:00
grid - > Fit ( ) ;
wxSize size = grid - > GetSize ( ) ;
size . x + = 10 ;
size . y + = 10 ;
SetClientSize ( size ) ;
2004-05-25 19:57:33 +00:00
initialized = true ;
return true ;
2001-06-10 17:12:56 +00:00
} // DbGridFrame::Initialize()
2001-05-15 13:12:36 +00:00
2004-05-18 02:43:53 +00:00
# endif // #if wxUSE_GRID
2000-03-16 19:09:42 +00:00
/*
TEST CODE FOR TESTING THE wxDbCreateDataSource ( ) FUNCTION
int result = 0 ;
2004-11-04 21:35:39 +00:00
result = wxDbCreateDataSource ( wxT ( " Microsoft Access Driver (*.mdb) " ) , wxT ( " GLT-TEST2 " ) , wxT ( " GLT-Descrip " ) , false , wxEmptyString , this ) ;
2000-03-16 19:09:42 +00:00
if ( ! result )
{
// check for errors caused by ConfigDSN based functions
DWORD retcode = 0 ;
WORD cb ;
wxChar errMsg [ 500 + 1 ] ;
2001-02-01 20:17:15 +00:00
errMsg [ 0 ] = wxT ( ' \0 ' ) ;
2000-03-16 19:09:42 +00:00
2004-11-04 21:35:39 +00:00
SQLInstallerError ( 1 , & retcode , errMsg , 500 , & cb ) ;
2000-03-16 19:09:42 +00:00
2004-11-04 21:35:39 +00:00
wxMessageBox ( wxT ( " FAILED creating data source " ) , wxT ( " FAILED " ) ) ;
2000-03-16 19:09:42 +00:00
}
else
2004-11-04 21:35:39 +00:00
wxMessageBox ( wxT ( " SUCCEEDED creating data source " ) , wxT ( " SUCCESS " ) ) ;
2000-03-16 19:09:42 +00:00
*/