[摘要]rc == SQL_SUCCESS_WITH_INFO) /*如果执行成功*/ SQLTransact(henv,hdbc,SQL_COMMIT); SQLFreeStmt(hstmt,...
rc == SQL_SUCCESS_WITH_INFO)
{ /*如果执行成功*/
SQLTransact(henv,hdbc,SQL_COMMIT);
SQLFreeStmt(hstmt,SQL_DROP) ;
return TRUE ;
}
else
{
m_sErrMsg = "" ;
while(SQLError(0,
0,
hstmt,
szSQLSTATE,
&nErr,
msg,
sizeof(msg),
&cbmsg) == SQL_SUCCESS)
m_sErrMsg = "\t\t" + (CString) msg + "\n" ;
SQLFreeStmt(hstmt,SQL_DROP) ;
return FALSE ;
}
}
CString CWdcDatabase::Quote(CString &sText)
{
CString sResult="" ;
CString sChar ;
int iTextLen = sText.GetLength() ;
for(int pos = 0 ;pos<iTextLen;pos++)
{
sChar = sText.Mid(pos,1) ;
if (sChar == "'")
sChar = "''" ;
sResult += sChar ;
}
return CString("'" + sResult + "'") ;
}
BOOL CWdcDatabase::AddRecord()
{
unsigned char szSQLSTATE[6] ;
SDWORD nErr ;
unsigned char msg[MAX_ERROR_MSG+1] ;
SWORD cbmsg ;
CString sTemp ;
if(!m_bOpen)
return FALSE ;
m_sQuery.Format("Insert Into %s(",m_sTable) ;
int ff=0 ;
for(int f=0 ;f<m_nFields;f++)
{
if(ff>0)
m_sQuery += "," ;
ff ++ ;
m_sQuery += m_sFieldName[f] ;
}
m_sQuery += ") values(" ;
ff = 0 ;
for(f=0 ;f<m_nFields ;f++)
{
if(ff>0)
m_sQuery += "," ;
ff ++ ;
/*---如果数据不为空*/
if(m_sFieldValue[f]!="")
{
if(m_bNumeric[f])
sTemp.Format("%s",m_sFieldValue[f]) ;
else
sTemp.Format("%s",Quote(m_sFieldValue[f])) ;
}
else
{ /*如果数据为空*/
sTemp.Format("%s","NULL") ;
}
m_sQuery += sTemp ;
}
m_sQuery += ")" ;
memset((char*)szQuery,0x00,sizeof(szQuery)) ;
strcpy((char*)szQuery,m_sQuery) ;
SQLAllocStmt(hdbc,&hstmt) ;
rc = SQLExecDirect(hstmt,
szQuery,
SQL_NTS) ;
m_nError = (int) rc ;
if(rc == SQL_SUCCESS (北联网教程,专业提供视频软件下载)
……