www.pudn.com > dlldb.rar > dllDb.cpp
// dllDb.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "dllDb.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CDllDbApp
BEGIN_MESSAGE_MAP(CDllDbApp, CWinApp)
//{{AFX_MSG_MAP(CDllDbApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDllDbApp construction
CDllDbApp::CDllDbApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CDllDbApp object
CDllDbApp theApp;
CDbConn::CDbConn()
{
m_recordset=NULL;
}
CDbConn::~CDbConn()
{
}
BOOL CDbConn::Connect(CString StrDSN,CString StrUID,CString StrPWD)
{
BOOL flag;
if(StrDSN=="")
return false;
CString str="DSN="+StrDSN;
str+=";UID="+StrUID;
str+=";PWD="+StrPWD;
try
{
flag=m_db.OpenEx(_T(str));
}
catch(CDBException e)
{
return FALSE;
}
return flag;
}
BOOL CDbConn::Execute(CString Strsql)
{
if(Strsql=="")
return false;
try
{
m_db.ExecuteSQL(Strsql);
}
catch(CDBException e)
{
m_db.Rollback ();
return FALSE;
}
return true;
/*
TRY
{
m_dbCust.ExecuteSQL( strCmd );
}
CATCH(CDBException, e)
{
// The error code is in e->m_nRetCode
}
END_CATCH
*/
}
void * CDbConn::Query(CString Strsql)
{
CRecordset *rs1;
rs1=new CRecordset(&m_db);
try
{
rs1->Open(CRecordset::forwardOnly,Strsql);
}
catch(CDBException e)
{
return NULL;
}
m_recordset=rs1;
return (void *)m_recordset;
}
void CDbConn::DbClose()
{
if(m_db.IsOpen())
m_db.Close();
}
void CDbConn::RSClose()
{
if(m_recordset!=NULL)
{
m_recordset->Close();
delete m_recordset;
m_recordset=NULL;
}
}
BOOL CDbConn::IsDbOpen()
{
return m_db.IsOpen();
}
BOOL CDbConn::IsRSOpen()
{
if(m_recordset==NULL)
return FALSE;
return m_recordset->IsOpen();
}
BOOL CDbConn::SQLConfigDataSource(CString Driver, CString StrDSN, CString Server, CString DataBase)
{
int ret;
Driver+="\0";
CString str="server=";
str+=Server+"\0";
str+="DSN=";
str+=StrDSN+"\0";
str+="Database=";
str+=DataBase+"\0";
ret=::SQLConfigDataSource(NULL,
ODBC_ADD_SYS_DSN,
Driver,//"SQL Server\0",
str);//"server=WANGWEIM\0DSN=wang\0Database=sms\0");
if(!ret)
return TRUE;
else
return FALSE;
}