?? lrunsql.cpp
字號:
// LRunSql.cpp: implementation of the LRunSql class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "JXC.h"
#include "LRunSql.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
_ConnectionPtr LRunSql::m_database;
LRunSql::LRunSql()
{
m_recordset.CreateInstance(__uuidof(Recordset));
}
LRunSql::~LRunSql()
{
}
bool LRunSql::RunSQL(CString sql)
{
_bstr_t sql_=sql;
try{
m_recordset=m_database->Execute(sql_,NULL,adCmdText);
}
catch(_com_error& e)
{
ErrorsPtr pErrors=m_database->GetErrors();
if (pErrors->GetCount()==0)
{
//AfxMessageBox(e.ErrorMessage());
afxDump<<e.ErrorMessage();
}
else
{
for (int i=0;i<pErrors->GetCount();i++)
{
_bstr_t desc=pErrors->GetItem((long)i)->GetDescription();
// AfxMessageBox(desc);
afxDump<<(char*)desc;
}
}
return false;
}
return true;
}
bool LRunSql::CheckSQLResult(CString sql)
{
if(!this->RunSQL(sql))
return false;
else
{
if(!this->m_recordset->adoEOF)
return true;
else
return false;
}
return true;
}
void DateToInt(CString date,int& year,int& month,int& day)
{
int a_1=date.Find('-',0);
int a_2=date.Find('-',5);
CString y=date.Mid(0,4);
CString m=date.Mid(a_1+1,a_2-a_1);
CString d=date.Mid(a_2+1,date.GetLength()-a_2);
year=atoi(y);
month=atoi(m);
day=atoi(d);
}
bool LRunSql::ConnectDataBase()
{
try{
m_database->Open(L"jjj","","",-1);
}
catch(...)
{
::ShellExecute(NULL,"open","AutoConfig.exe",NULL,NULL,SW_HIDE);
return false;
}
return true;
}
bool LRunSql::InitConnectPtr()
{
// ::CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);
if(FAILED(m_database.CreateInstance(__uuidof(Connection))))
return false;
if(ConnectDataBase()==false)
{
::Sleep(1000);
if(ConnectDataBase()==false)
{
MessageBox(NULL,"系統(tǒng)試圖自動為您配置ODBC,但由于一些原因沒有完成,請手工配置!","系統(tǒng)提示",MB_OK|MB_ICONSTOP);
return false;
}
}
return true;
}
bool LRunSql::Close()
{
return (!FAILED(m_database->Close()));
}
bool LRunSql::BeginTrans()
{
return (!FAILED(m_database->BeginTrans()));
}
bool LRunSql::CommitTrans()
{
return (!FAILED(m_database->CommitTrans()));
}
bool LRunSql::RollbackTrans()
{
return (!FAILED(m_database->RollbackTrans()));
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -