2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2004-04-06 13:19:42 +00:00
// Name: BrowserDB.h,cpp
// Purpose: a wxDB class
// Author: Mark Johnson
2000-01-28 15:25:32 +00:00
// Modified by:
2004-04-06 13:19:42 +00:00
// Created: 19991127.mj10777
// Copyright: (c) Mark Johnson
// Licence: wxWindows license
// RCS-ID: $Id$
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
//-- 1)
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
//-- all #ifdefs that the whole Project needs. -------------------------------------------
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
# ifdef __GNUG__
2000-01-31 10:43:24 +00:00
# pragma implementation
# pragma interface
2000-01-28 15:25:32 +00:00
# endif
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
// For compilers that support precompilation, includes "wx/wx.h".
# include "wx/wxprec.h"
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
# ifdef __BORLANDC__
2000-01-31 10:43:24 +00:00
# pragma hdrstop
2000-01-28 15:25:32 +00:00
# endif
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
# ifndef WX_PRECOMP
2000-01-31 10:43:24 +00:00
# include "wx/wx.h"
2000-01-28 15:25:32 +00:00
# endif
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
# include "std.h"
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
// Global structure for holding ODBC connection information
2004-01-11 22:08:25 +00:00
wxDbConnectInf DbConnectInf ;
2001-02-01 20:24:44 +00:00
2001-05-18 18:43:30 +00:00
# if !wxUSE_ODBC
2001-05-18 18:32:33 +00:00
# error Demo cannot be compiled unless setup.h has wxUSE_ODBC set to 1
# endif
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2004-04-06 13:19:42 +00:00
extern WXDLLEXPORT_DATA ( wxDbList * ) PtrBegDbList ; /* from db.cpp, used in getting back error results from db connections */
2001-02-01 20:24:44 +00:00
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2004-01-11 22:08:25 +00:00
wxChar * GetExtendedDBErrorMsg ( wxChar * ErrFile , int ErrLine )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
static wxString msg ;
wxString tStr ;
if ( ErrFile | | ErrLine )
{
2004-01-11 22:08:25 +00:00
msg + = _T ( " File: " ) ;
2001-02-01 20:24:44 +00:00
msg + = ErrFile ;
2004-01-11 22:08:25 +00:00
msg + = _T ( " Line: " ) ;
tStr . Printf ( _T ( " %d " ) , ErrLine ) ;
2001-02-01 20:24:44 +00:00
msg + = tStr . GetData ( ) ;
2004-01-11 22:08:25 +00:00
// msg += _T("\n");
2001-02-01 20:24:44 +00:00
}
2004-01-11 22:08:25 +00:00
msg . Append ( _T ( " \n ODBC errors: \n " ) ) ;
// msg += _T("\n");
2001-02-01 20:24:44 +00:00
/* Scan through each database connection displaying
* any ODBC errors that have occured . */
wxDbList * pDbList ;
for ( pDbList = PtrBegDbList ; pDbList ; pDbList = pDbList - > PtrNext )
{
// Skip over any free connections
if ( pDbList - > Free )
continue ;
// Display errors for this connection
for ( int i = 0 ; i < DB_MAX_ERROR_HISTORY ; i + + )
{
if ( pDbList - > PtrDb - > errorList [ i ] )
{
msg . Append ( pDbList - > PtrDb - > errorList [ i ] ) ;
2004-01-11 22:08:25 +00:00
if ( wxStrcmp ( pDbList - > PtrDb - > errorList [ i ] , _T ( " " ) ) ! = 0 )
msg . Append ( _T ( " \n " ) ) ;
2001-02-01 20:24:44 +00:00
}
}
}
2004-01-11 22:08:25 +00:00
msg + = _T ( " \n " ) ;
return ( wxChar * ) ( const wxChar * ) msg ;
2000-01-28 15:25:32 +00:00
} // GetExtendedDBErrorMsg
2000-01-31 14:36:36 +00:00
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
BrowserDB : : BrowserDB ( )
{
2001-02-03 17:55:00 +00:00
PointerToNULL ( 0 ) ;
2004-01-11 22:08:25 +00:00
ODBCSource = _T ( " " ) ; // ODBC data source name (created with ODBC Administrator under Win95/NT)
UserName = _T ( " " ) ; // database username - must already exist in the data source
Password = _T ( " " ) ; // password database username
2001-02-01 20:24:44 +00:00
OnFillSqlTyp ( ) ;
OnFilldbTyp ( ) ;
2000-01-28 15:25:32 +00:00
} // BrowserDB Constructor
2001-02-01 20:24:44 +00:00
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-01-28 15:25:32 +00:00
BrowserDB : : ~ BrowserDB ( )
{
2001-02-03 17:55:00 +00:00
PointerToNULL ( 1 ) ; // Clean up Tables and Databases (Commit, Close and delete)
2000-01-28 15:25:32 +00:00
} // BrowserDB destructor
2001-02-01 20:24:44 +00:00
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-07-15 19:51:35 +00:00
bool BrowserDB : : Initialize ( int Quiet )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
if ( ! OnStartDB ( Quiet ) )
{
wxLogMessage ( _ ( " \n \n -E-> BrowserDB::OnStartDB(%s) : Failed ! " ) , ODBCSource . c_str ( ) ) ;
2004-06-01 18:27:09 +00:00
return false ;
2001-02-01 20:24:44 +00:00
}
2004-06-01 18:27:09 +00:00
return true ;
2000-01-28 15:25:32 +00:00
} // BrowserDB:Initialize
2001-02-01 20:24:44 +00:00
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-07-15 19:51:35 +00:00
bool BrowserDB : : OnStartDB ( int Quiet )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
wxStopWatch sw ;
if ( ! Quiet )
wxLogMessage ( _ ( " \n -I-> BrowserDB::OnStartDB(%s) : Begin " ) , ODBCSource . c_str ( ) ) ;
if ( db_BrowserDB ! = NULL )
{
if ( ! Quiet )
2001-02-03 17:55:00 +00:00
wxLogMessage ( _ ( " \n -I-> BrowserDB::OnStartDB() : DB is already open. " ) ) ;
2004-06-01 18:27:09 +00:00
return true ;
2001-02-01 20:24:44 +00:00
}
2001-02-03 17:55:00 +00:00
DbConnectInf . AllocHenv ( ) ;
2001-02-01 20:24:44 +00:00
//---------------------------------------------------------------------------------------
// Connect to datasource
//---------------------------------------------------------------------------------------
DlgUser * p_Dlg ;
2004-01-11 22:08:25 +00:00
p_Dlg = new DlgUser ( pDoc - > p_MainFrame , pDoc , _T ( " " ) ) ;
2004-04-06 13:19:42 +00:00
p_Dlg - > s_DSN = ODBCSource ;
p_Dlg - > s_User = UserName ;
2001-02-01 20:24:44 +00:00
p_Dlg - > s_Password = Password ;
p_Dlg - > OnInit ( ) ;
p_Dlg - > Fit ( ) ;
2004-10-05 15:38:40 +00:00
2004-06-01 18:27:09 +00:00
bool OK = false ;
2001-02-01 20:24:44 +00:00
if ( p_Dlg - > ShowModal ( ) = = wxID_OK )
{
( pDoc - > p_DSN + i_Which ) - > Usr = p_Dlg - > s_User ;
( pDoc - > p_DSN + i_Which ) - > Pas = p_Dlg - > s_Password ;
UserName = p_Dlg - > s_User ;
Password = p_Dlg - > s_Password ;
2004-06-01 18:27:09 +00:00
OK = true ;
2001-02-01 20:24:44 +00:00
}
delete p_Dlg ;
if ( OK )
{
//--------------------------------------------------------------------------------------
2004-04-06 13:19:42 +00:00
DbConnectInf . SetDsn ( ODBCSource ) ; // ODBC data source name (created with ODBC Administrator under Win95/NT)
DbConnectInf . SetUserID ( UserName ) ; // database username - must already exist in the data source
DbConnectInf . SetPassword ( Password ) ; // password database username
2001-02-03 17:55:00 +00:00
db_BrowserDB = wxDbGetConnection ( & DbConnectInf ) ;
2001-02-01 20:24:44 +00:00
// wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str());
if ( db_BrowserDB = = NULL )
{
2001-02-03 17:55:00 +00:00
DbConnectInf . SetDsn ( wxT ( " " ) ) ;
DbConnectInf . SetUserID ( wxT ( " " ) ) ;
DbConnectInf . SetPassword ( wxT ( " " ) ) ;
2001-02-01 20:24:44 +00:00
if ( ! Quiet )
{
wxLogMessage ( _ ( " \n -E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : 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 table prior to making a connection \n (using tools provided by the database manufacturer) " ) ) ;
wxLogMessage ( _ ( " -I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms " ) , ODBCSource . c_str ( ) , sw . Time ( ) ) ;
}
2001-02-03 17:55:00 +00:00
DbConnectInf . FreeHenv ( ) ;
2004-06-01 18:27:09 +00:00
return false ;
2001-02-01 20:24:44 +00:00
}
//--------------------------------------------------------------------------------------
if ( ! Quiet )
{
Temp1 = db_BrowserDB - > GetDatabaseName ( ) ;
Temp2 = db_BrowserDB - > GetDataSource ( ) ;
wxLogMessage ( _ ( " -I-> BrowserDB::OnGetDataSourceODBC() - DatabaseName(%s) ; DataSource(%s) " ) , Temp1 . c_str ( ) , Temp2 . c_str ( ) ) ;
wxLogMessage ( _ ( " -I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms " ) , ODBCSource . c_str ( ) , sw . Time ( ) ) ;
}
2004-06-01 18:27:09 +00:00
return true ;
2001-02-01 20:24:44 +00:00
}
else
2001-02-03 17:55:00 +00:00
{
DbConnectInf . FreeHenv ( ) ;
2004-06-01 18:27:09 +00:00
return false ;
2001-02-03 17:55:00 +00:00
}
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-02-12 14:11:17 +00:00
//----------------------------------------------------------------------------------------
2000-07-15 19:51:35 +00:00
bool BrowserDB : : OnCloseDB ( int Quiet )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
if ( ! Quiet )
wxLogMessage ( _ ( " -I-> BrowserDB::OnCloseDB() : Begin " ) ) ;
if ( db_BrowserDB )
{
// db_BrowserDB->Close();
wxDbFreeConnection ( db_BrowserDB ) ;
2001-02-03 17:55:00 +00:00
DbConnectInf . FreeHenv ( ) ;
2001-02-01 20:24:44 +00:00
db_BrowserDB = NULL ;
}
if ( ! Quiet )
wxLogMessage ( _ ( " \n -I-> BrowserDB::OnCloseDB() : End " ) ) ;
2004-06-01 18:27:09 +00:00
return true ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
2004-02-08 11:53:48 +00:00
bool BrowserDB : : OnGetNext ( int Cols , int WXUNUSED ( Quiet ) )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
SDWORD cb ;
2004-04-06 13:19:42 +00:00
int i_dbDataType ;
2004-01-11 22:08:25 +00:00
wxChar s_temp [ 1024 + 1 ] ;
2004-04-06 13:19:42 +00:00
long l_temp ;
double f_temp ;
int AnzError = 0 ;
2001-02-01 20:24:44 +00:00
TIMESTAMP_STRUCT t_temp ;
wxString Temp0 ;
//-----------------------------
if ( ! db_BrowserDB - > GetNext ( ) )
{
2004-02-08 11:53:48 +00:00
# ifdef __WXDEBUG__
2001-02-01 20:24:44 +00:00
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnGetNext - ODBC-Error with GetNext \n -E-> " ) ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
wxLogMessage ( Temp0 ) ;
wxMessageBox ( Temp0 ) ;
2004-02-08 11:53:48 +00:00
# endif
2004-06-01 18:27:09 +00:00
return false ;
2001-02-01 20:24:44 +00:00
}
else
{
2004-04-06 13:19:42 +00:00
int i ;
2001-02-01 20:24:44 +00:00
for ( i = 0 ; i < Cols ; i + + )
{
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , _T ( " -E-> " ) ) ;
2001-05-28 12:02:51 +00:00
i_dbDataType = ( cl_BrowserDB + i ) - > pColFor - > i_dbDataType ;
2004-04-06 13:19:42 +00:00
if ( i_dbDataType = = 0 ) // Filter unsupported dbDataTypes
2001-02-01 20:24:44 +00:00
{
2001-05-28 12:02:51 +00:00
if ( ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType = = SQL_VARCHAR ) | |
2004-04-06 13:19:42 +00:00
( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType = = SQL_LONGVARCHAR ) )
2001-02-01 20:24:44 +00:00
i_dbDataType = DB_DATA_TYPE_VARCHAR ;
2001-05-28 12:02:51 +00:00
if ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType = = SQL_C_DATE )
2001-02-01 20:24:44 +00:00
i_dbDataType = DB_DATA_TYPE_DATE ;
2001-05-28 12:02:51 +00:00
if ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType = = SQL_C_BIT )
2001-02-01 20:24:44 +00:00
i_dbDataType = DB_DATA_TYPE_INTEGER ;
2001-05-28 12:02:51 +00:00
if ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType = = SQL_NUMERIC )
2001-02-01 20:24:44 +00:00
i_dbDataType = DB_DATA_TYPE_VARCHAR ;
2001-05-28 12:02:51 +00:00
if ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType = = SQL_REAL )
2001-02-01 20:24:44 +00:00
i_dbDataType = DB_DATA_TYPE_FLOAT ;
}
2001-05-28 12:02:51 +00:00
if ( ( i_dbDataType = = DB_DATA_TYPE_INTEGER ) & &
2004-04-06 13:19:42 +00:00
( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType = = SQL_C_DOUBLE ) )
{ // DBASE Numeric
2001-02-01 20:24:44 +00:00
i_dbDataType = DB_DATA_TYPE_FLOAT ;
}
switch ( i_dbDataType )
{
case DB_DATA_TYPE_VARCHAR :
2004-01-11 22:08:25 +00:00
wxStrcpy ( s_temp , _T ( " " ) ) ;
2004-10-05 15:38:40 +00:00
if ( ! db_BrowserDB - > GetData ( ( UWORD ) ( i + 1 ) , ( SWORD ) ( ( cl_BrowserDB + i ) - > pColFor - > i_dbDataType ) , & s_temp [ 0 ] , sizeof ( s_temp ) , & cb ) )
2001-02-01 20:24:44 +00:00
{
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnGetNext - ODBC-Error with GetNext of >%s<. \n -E-> " ) , ( cl_BrowserDB + i ) - > tableName ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
wxLogMessage ( Temp0 ) ;
}
2001-05-28 12:02:51 +00:00
Temp0 . Printf ( ( cl_BrowserDB + i ) - > pColFor - > s_Field , s_temp ) ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
break ;
case DB_DATA_TYPE_INTEGER :
l_temp = 0 ;
2004-10-05 15:38:40 +00:00
if ( ! db_BrowserDB - > GetData ( ( UWORD ) ( i + 1 ) , ( SWORD ) ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType ) , & l_temp , sizeof ( l_temp ) , & cb ) )
2001-02-01 20:24:44 +00:00
{
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n -E-> " ) ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
}
else
{
2001-05-28 12:02:51 +00:00
Temp0 . Printf ( ( cl_BrowserDB + i ) - > pColFor - > s_Field , l_temp ) ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
}
break ;
case DB_DATA_TYPE_FLOAT :
f_temp = 0 ;
2004-10-05 15:38:40 +00:00
if ( ! db_BrowserDB - > GetData ( ( UWORD ) ( i + 1 ) , ( SWORD ) ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType ) , & f_temp , sizeof ( f_temp ) , & cb ) )
2001-02-01 20:24:44 +00:00
{
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n -E-> " ) ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
wxMessageBox ( Temp0 ) ;
}
else
{
2001-05-28 12:02:51 +00:00
Temp0 . Printf ( ( cl_BrowserDB + i ) - > pColFor - > s_Field , f_temp ) ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
}
break ;
case DB_DATA_TYPE_DATE :
2004-10-05 15:38:40 +00:00
t_temp . day = 0 ;
t_temp . month = 0 ;
t_temp . year = 0 ;
t_temp . hour = 0 ;
t_temp . minute = 0 ;
t_temp . second = 0 ;
t_temp . fraction = 0 ;
if ( ! db_BrowserDB - > GetData ( ( UWORD ) ( i + 1 ) , ( SWORD ) ( ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType ) , & t_temp , sizeof ( t_temp ) , & cb ) )
2001-02-01 20:24:44 +00:00
{
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n -E-> " ) ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
}
else
{
// i_Nation = 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US
2004-04-06 13:19:42 +00:00
if ( ( ( cl_BrowserDB + i ) - > pColFor - > i_Nation = = 0 ) | | // TS YYYY-MM-DD
( ( cl_BrowserDB + i ) - > pColFor - > i_Nation = = 3 ) ) // IT YYYY-MM-DD
2001-02-01 20:24:44 +00:00
{
2001-05-28 12:02:51 +00:00
Temp0 . Printf ( ( cl_BrowserDB + i ) - > pColFor - > s_Field , t_temp . year , t_temp . month , t_temp . day ,
2001-02-01 20:24:44 +00:00
t_temp . hour , t_temp . minute , t_temp . second , t_temp . fraction ) ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
}
2001-05-28 12:02:51 +00:00
if ( ( ( cl_BrowserDB + i ) - > pColFor - > i_Nation = = 1 ) | | // EU DD.MM.YYYY
( ( cl_BrowserDB + i ) - > pColFor - > i_Nation = = 2 ) ) // UK DD/MM/YYYY
2001-02-01 20:24:44 +00:00
{
2001-05-28 12:02:51 +00:00
Temp0 . Printf ( ( cl_BrowserDB + i ) - > pColFor - > s_Field , t_temp . day , t_temp . month , t_temp . year ,
2001-02-01 20:24:44 +00:00
t_temp . hour , t_temp . minute , t_temp . second , t_temp . fraction ) ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
}
2004-04-06 13:19:42 +00:00
if ( ( cl_BrowserDB + i ) - > pColFor - > i_Nation = = 3 ) // US MM/DD/YYYY
2001-02-01 20:24:44 +00:00
{
2001-05-28 12:02:51 +00:00
Temp0 . Printf ( ( cl_BrowserDB + i ) - > pColFor - > s_Field , t_temp . month , t_temp . day , t_temp . year ,
2001-02-01 20:24:44 +00:00
t_temp . hour , t_temp . minute , t_temp . second , t_temp . fraction ) ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
}
}
break ;
default :
AnzError + + ;
if ( AnzError < = 100 )
{
Temp0 = ( cl_BrowserDB + i ) - > colName ;
2001-05-28 12:02:51 +00:00
wxLogMessage ( _ ( " -E-> BrowserDB::OnGetNext - DB_DATA_TYPE_?? (%d) in Col(%s) " ) , ( cl_BrowserDB + i ) - > pColFor - > i_dbDataType , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
}
else
2004-06-01 18:27:09 +00:00
return true ;
2001-05-28 12:02:51 +00:00
Temp0 . Printf ( _ ( " -E-> unknown Format(%d) - sql(%d) " ) , ( cl_BrowserDB + i ) - > pColFor - > i_dbDataType , ( cl_BrowserDB + i ) - > pColFor - > i_sqlDataType ) ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( ( cl_BrowserDB + i ) - > tableName , Temp0 . c_str ( ) ) ;
2001-02-01 20:24:44 +00:00
break ;
} ; // switch
} // for
} // else
2004-06-01 18:27:09 +00:00
return true ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
2000-07-15 19:51:35 +00:00
bool BrowserDB : : OnSelect ( wxString tb_Name , int Quiet )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
wxStopWatch sw ;
wxString SQLStmt ;
i_Records = 0 ;
//---------------------------------------------------------------------------------------
2004-02-08 11:53:48 +00:00
wxString tablename = db_BrowserDB - > SQLTableName ( tb_Name . c_str ( ) ) ;
SQLStmt . sprintf ( _T ( " SELECT * FROM %s " ) , tablename . c_str ( ) ) ;
2004-01-11 22:08:25 +00:00
if ( ! db_BrowserDB - > ExecSql ( ( wxChar * ) ( SQLStmt . GetData ( ) ) ) )
2001-02-01 20:24:44 +00:00
{
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnSelect - ODBC-Error with ExecSql of >%s<. \n -E-> " ) , tb_Name . c_str ( ) ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
wxLogMessage ( Temp0 ) ;
2004-01-11 22:08:25 +00:00
wxMessageBox ( _T ( " -E-> BrowserDB::OnSelect - GetData() " ) ) ;
2004-06-01 18:27:09 +00:00
return false ;
2001-02-01 20:24:44 +00:00
}
//---------------------------------------------------------------------------------------
while ( db_BrowserDB - > GetNext ( ) )
{
i_Records + + ;
}
//---------------------------------------------------------------------------------------
2004-01-11 22:08:25 +00:00
if ( ! db_BrowserDB - > ExecSql ( ( wxChar * ) ( SQLStmt . GetData ( ) ) ) )
2001-02-01 20:24:44 +00:00
{
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnSelect - ODBC-Error with ExecSql of >%s<. \n -E-> " ) , tb_Name . c_str ( ) ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
wxLogMessage ( Temp0 ) ;
2004-06-01 18:27:09 +00:00
return false ;
2001-02-01 20:24:44 +00:00
}
//---------------------------------------------------------------------------------------
2004-11-10 10:31:13 +00:00
// SetColDefs ( 0, "NAME", DB_DATA_TYPE_VARCHAR, Name, SQL_C_WXCHAR, sizeof(Name), true, true); // Primary index
2001-02-01 20:24:44 +00:00
//---------------------------------------------------------------------------------------
if ( ! Quiet )
{
wxLogMessage ( _ ( " \n -I-> BrowserDB::OnSelect(%s) Records(%d): End - Time needed : %ld ms " ) , tb_Name . c_str ( ) , i_Records , sw . Time ( ) ) ;
}
2004-06-01 18:27:09 +00:00
return true ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
2000-07-15 19:51:35 +00:00
bool BrowserDB : : OnExecSql ( wxString SQLStmt , int Quiet )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
//---------------------------------------------------------------------------------------
2004-01-11 22:08:25 +00:00
if ( ! db_BrowserDB - > ExecSql ( ( wxChar * ) ( SQLStmt . GetData ( ) ) ) )
2001-02-01 20:24:44 +00:00
{
Temp0 . Printf ( _ ( " \n -E-> BrowserDB::OnExecSQL - ODBC-Error with ExecSql of >%s<. \n -E-> " ) , SQLStmt . c_str ( ) ) ;
2004-01-11 22:08:25 +00:00
Temp0 + = GetExtendedDBErrorMsg ( __TFILE__ , __LINE__ ) ;
2001-02-01 20:24:44 +00:00
if ( ! Quiet )
wxLogMessage ( Temp0 ) ;
else
2004-01-11 22:08:25 +00:00
wxMessageBox ( _T ( " -E-> BrowserDB::OnExecSql - ExecSql() " ) ) ;
2004-06-01 18:27:09 +00:00
return false ;
2001-02-01 20:24:44 +00:00
}
if ( ! Quiet )
{
// wxLogMessage(_("\n-I-> BrowserDB::OnExecSql(%s) - End - Time needed : %ld ms"),SQLStmt.c_str(),sw.Time());
}
2004-06-01 18:27:09 +00:00
return true ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
2004-02-08 11:53:48 +00:00
wxDbInf * BrowserDB : : OnGetCatalog ( int WXUNUSED ( Quiet ) )
2000-01-28 15:25:32 +00:00
{
2004-01-11 22:08:25 +00:00
wxChar UName [ 255 ] ;
wxStrcpy ( UName , UserName ) ;
2001-02-01 20:24:44 +00:00
ct_BrowserDB = db_BrowserDB - > GetCatalog ( UName ) ;
return ct_BrowserDB ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
2004-02-08 11:53:48 +00:00
wxDbColInf * BrowserDB : : OnGetColumns ( wxChar * tableName , UWORD numCols , int WXUNUSED ( Quiet ) )
2000-01-28 15:25:32 +00:00
{
2004-01-11 22:08:25 +00:00
wxChar UName [ 255 ] ;
2001-02-01 20:24:44 +00:00
int i ;
2004-01-11 22:08:25 +00:00
wxStrcpy ( UName , UserName ) ;
2001-02-01 20:24:44 +00:00
cl_BrowserDB = db_BrowserDB - > GetColumns ( tableName , & numCols , UName ) ;
2001-05-28 12:02:51 +00:00
// cl_BrowserDB->pColFor = new wxDbColFor[numCols];
2001-02-01 20:24:44 +00:00
for ( i = 0 ; i < numCols ; i + + )
{
2001-05-28 12:02:51 +00:00
// (cl_BrowserDB->pColFor+i)->Format(1,(cl_BrowserDB+i)->dbDataType,(cl_BrowserDB+i)->sqlDataType,
// (cl_BrowserDB+i)->columnSize, (cl_BrowserDB+i)->decimalDigits);
( cl_BrowserDB + i ) - > pColFor = new wxDbColFor ;
( cl_BrowserDB + i ) - > pColFor - > Format ( 1 ,
( cl_BrowserDB + i ) - > dbDataType ,
( cl_BrowserDB + i ) - > sqlDataType ,
2004-11-05 14:30:05 +00:00
( cl_BrowserDB + i ) - > columnLength ,
2001-05-28 12:02:51 +00:00
( cl_BrowserDB + i ) - > decimalDigits ) ;
2001-02-01 20:24:44 +00:00
}
return cl_BrowserDB ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
2001-02-03 17:55:00 +00:00
void BrowserDB : : PointerToNULL ( int Art )
2000-01-28 15:25:32 +00:00
{
2001-02-01 20:24:44 +00:00
if ( Art = = 1 ) // L<> schen
{
if ( cl_BrowserDB ! = NULL )
{ // Destroy the memory
delete [ ] cl_BrowserDB ;
}
if ( ct_BrowserDB ! = NULL )
{ // Destroy the memory
delete [ ] ct_BrowserDB ;
}
if ( db_BrowserDB ! = NULL )
{
db_BrowserDB - > CommitTrans ( ) ;
db_BrowserDB - > Close ( ) ;
wxDbCloseConnections ( ) ;
delete db_BrowserDB ;
}
}
2004-04-06 13:19:42 +00:00
cl_BrowserDB = NULL ;
ct_BrowserDB = NULL ;
db_BrowserDB = NULL ;
p_LogWindow = NULL ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
void BrowserDB : : OnFillSqlTyp ( )
{
2004-01-11 22:08:25 +00:00
i_SqlTyp [ 1 ] = SQL_C_BINARY ; s_SqlTyp [ 1 ] = _T ( " SQL_C_BINARY " ) ;
i_SqlTyp [ 2 ] = SQL_C_BIT ; s_SqlTyp [ 2 ] = _T ( " SQL_C_BIT " ) ;
i_SqlTyp [ 3 ] = SQL_C_BOOKMARK ; s_SqlTyp [ 3 ] = _T ( " SQL_C_BOOKMARK " ) ;
2004-11-04 21:36:32 +00:00
i_SqlTyp [ 4 ] = SQL_C_WXCHAR ; s_SqlTyp [ 4 ] = _T ( " SQL_C_WXCHAR " ) ;
2004-01-11 22:08:25 +00:00
i_SqlTyp [ 5 ] = SQL_C_DATE ; s_SqlTyp [ 5 ] = _T ( " SQL_C_DATE " ) ;
i_SqlTyp [ 6 ] = SQL_C_DEFAULT ; s_SqlTyp [ 6 ] = _T ( " SQL_C_DEFAULT " ) ;
i_SqlTyp [ 7 ] = SQL_C_DOUBLE ; s_SqlTyp [ 7 ] = _T ( " SQL_C_DOUBLE " ) ;
i_SqlTyp [ 8 ] = SQL_C_FLOAT ; s_SqlTyp [ 8 ] = _T ( " SQL_C_FLOAT " ) ;
i_SqlTyp [ 9 ] = SQL_C_LONG ; s_SqlTyp [ 9 ] = _T ( " SQL_C_LONG " ) ;
i_SqlTyp [ 10 ] = SQL_C_SHORT ; s_SqlTyp [ 10 ] = _T ( " SQL_C_SHORT " ) ;
i_SqlTyp [ 11 ] = SQL_C_SLONG ; s_SqlTyp [ 11 ] = _T ( " SQL_C_SLONG " ) ;
i_SqlTyp [ 12 ] = SQL_C_SSHORT ; s_SqlTyp [ 12 ] = _T ( " SQL_C_SSHORT " ) ;
i_SqlTyp [ 13 ] = SQL_C_STINYINT ; s_SqlTyp [ 13 ] = _T ( " SQL_C_STINYINT " ) ;
i_SqlTyp [ 14 ] = SQL_C_TIME ; s_SqlTyp [ 14 ] = _T ( " SQL_C_TIME " ) ;
i_SqlTyp [ 15 ] = SQL_C_TIMESTAMP ; s_SqlTyp [ 15 ] = _T ( " SQL_C_TIMESTAMP " ) ;
i_SqlTyp [ 16 ] = SQL_C_TINYINT ; s_SqlTyp [ 16 ] = _T ( " SQL_C_TINYINT " ) ;
i_SqlTyp [ 17 ] = SQL_C_ULONG ; s_SqlTyp [ 17 ] = _T ( " SQL_C_ULONG " ) ;
i_SqlTyp [ 18 ] = SQL_C_USHORT ; s_SqlTyp [ 18 ] = _T ( " SQL_C_USHORT " ) ;
i_SqlTyp [ 19 ] = SQL_C_UTINYINT ; s_SqlTyp [ 19 ] = _T ( " SQL_C_UTINYINT " ) ;
i_SqlTyp [ 20 ] = SQL_VARCHAR ; s_SqlTyp [ 20 ] = _T ( " SQL_VARCHAR " ) ;
i_SqlTyp [ 21 ] = SQL_NUMERIC ; s_SqlTyp [ 21 ] = _T ( " SQL_NUMERIC " ) ;
i_SqlTyp [ 22 ] = SQL_LONGVARCHAR ; s_SqlTyp [ 22 ] = _T ( " SQL_LONGVARCHAR " ) ;
i_SqlTyp [ 23 ] = SQL_REAL ; s_SqlTyp [ 23 ] = _T ( " SQL_REAL " ) ;
i_SqlTyp [ 0 ] = 23 ; s_SqlTyp [ 0 ] = _T ( " " ) ;
2000-01-28 15:25:32 +00:00
}
2001-02-01 20:24:44 +00:00
2000-01-28 15:25:32 +00:00
//----------------------------------------------------------------------------------------
void BrowserDB : : OnFilldbTyp ( )
{
2004-01-11 22:08:25 +00:00
i_dbTyp [ 1 ] = DB_DATA_TYPE_VARCHAR ; s_dbTyp [ 1 ] = _T ( " DB_DATA_TYPE_VARCHAR " ) ;
i_dbTyp [ 2 ] = DB_DATA_TYPE_INTEGER ; s_dbTyp [ 2 ] = _T ( " DB_DATA_TYPE_INTEGER " ) ;
i_dbTyp [ 3 ] = DB_DATA_TYPE_FLOAT ; s_dbTyp [ 3 ] = _T ( " DB_DATA_TYPE_FLOAT " ) ;
i_dbTyp [ 4 ] = DB_DATA_TYPE_DATE ; s_dbTyp [ 4 ] = _T ( " DB_DATA_TYPE_DATE " ) ;
i_dbTyp [ 0 ] = 4 ; s_dbTyp [ 0 ] = _T ( " " ) ;
2000-01-28 15:25:32 +00:00
}
//----------------------------------------------------------------------------------------