1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/**************************************************
*
*
**************************************************
* This code was created by Peter Harvey @ CodeByDesign.
* Released under GPL 18.FEB.99
*
* Contributions from...
* -----------------------------------------------
* Peter Harvey - pharvey@codebydesign.com
**************************************************/
#include "classODBC.h"
#include <qpixmap.h>
#include <classDrivers.h>
#include <classDataSources.h>
#include "ODBC.xpm"
// ***********************************
// Common Utilities
// ***********************************
void my_msgBox( const QString & className,
const QString & actionName,
SQLRETURN rc,
SQLHENV hEnv,
SQLHDBC hDbc,
SQLHSTMT hStmt,
const QString & moreInfo,
QMessageBox::Icon icon )
{
QString caption = "DataManager - " + className + " - " + actionName ;
QString text = actionName ;
if ( rc )
text += " failed, rc=" + QString::number(rc) ;
if ( hEnv || hDbc || hStmt )
{
char szState[SQL_SQLSTATE_SIZE+1] ; szState[0] = 0 ;
char szBuf[SQL_MAX_MESSAGE_LENGTH+1] ; szBuf[0] = 0 ;
SQLINTEGER sqlCode = 0;
SQLSMALLINT length = 0 ;
int nRec = 0 ;
while (SQL_SUCCEEDED(SQLGetDiagRec( hStmt ? SQL_HANDLE_STMT : hDbc ? SQL_HANDLE_DBC : SQL_HANDLE_ENV,
hStmt ? hStmt : hDbc ? hDbc : hEnv,
++nRec,
(SQLCHAR*)szState,
&sqlCode,
(SQLCHAR*)szBuf,
sizeof(szBuf),
&length) ) )
text += QString().sprintf("\n[%d] SQLSTATE:%s SQLCODE:%d %s", nRec, szState, sqlCode, szBuf) ;
}
if ( !moreInfo.isEmpty() )
text += "\n\nInfo:" + moreInfo ;
QMessageBox(caption, text, icon, QMessageBox::Ok | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, QMessageBox::NoButton ).exec() ;
}
// ***********************************
// ***********************************
classODBC::classODBC( QListView *pParent, classCanvas *pCanvas )
: classNode( pParent, pCanvas ) , pDrivers ( NULL ) , pDataSourcesUser( NULL ) , pDataSourcesSystem( NULL )
{
setPixmap( 0, QPixmap(xpmODBC) );
setText( 0, "ODBC" );
setText( 1, "" );
setText( 2, "Open Database Connectivity" );
setExpandable( TRUE );
}
void classODBC::setOpen( bool bOpen )
{
if ( bOpen && !childCount() ) // Only create item once
{
// ADD CHILD NODES; only classODBC knows what they may be
pDrivers = new classDrivers ( this, NULL, pCanvas );
pDataSourcesSystem = new classDataSources( this, pDrivers, pCanvas, System );
pDataSourcesUser = new classDataSources( this, pDataSourcesSystem, pCanvas, User );
}
QListViewItem::setOpen( bOpen );
}
void classODBC::selectionChanged( QListViewItem *p )
{
if ( pDataSourcesUser ) pDataSourcesUser->selectionChanged( p );
if ( pDataSourcesSystem ) pDataSourcesSystem->selectionChanged( p );
}
|