⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringsql.cpp

📁 用户管理系统
💻 CPP
字号:
// StringSQL.cpp: implementation of the CStringSQL class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Kvip.h"
#include "StringSQL.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CStringSQL::CStringSQL()
{
  Reset();
}
CStringSQL::CStringSQL(LPCSTR pSelect)
{
  Reset();
  m_strSelect = pSelect;
}

CStringSQL::~CStringSQL()
{

}




void CStringSQL::Reset()
{
  m_strSelect = _T("");
  m_strFoot = _T("");
  m_strWhere = _T("");
}
////////////////////////////////////////////
//设置SELECT
void CStringSQL::SetSelect(LPCSTR pSelect)
///////////////////////////////////////////
{
  m_strSelect = pSelect;
}
////////////////////////////////////////////
//返回SQL
CString CStringSQL::GetSQL()
{
  if (m_strWhere.IsEmpty())
	return m_strSelect + _T(" ") + m_strFoot;
  else
    return m_strSelect + " Where " + m_strWhere + _T(" ") + m_strFoot;
}
///////////////////////////////////////////////////
//设置条件:
//strName   数据表项名称
//strCase   条件
//bLike     Like方式查找
//bText     条件是字符串,则加入单引号
void CStringSQL::SetWhere(CString strName, 
						  CString strCase, 
						  BOOL bLike, 
						  BOOL bText)
{
///////////////////////////////////////////////////
//合成SQL
  strCase.TrimLeft(); strCase.TrimRight();
  if (bLike)
  {
     if (strCase.IsEmpty())	 return;
     if (!m_strWhere.IsEmpty())
	     m_strWhere = m_strWhere + " And "; 
	 if (bText)
	   m_strWhere = m_strWhere + strName + " Like '%" + strCase + "%'";
	 else
	   m_strWhere = m_strWhere + strName + " Like %" + strCase + "%";
  }
  else
  {
     if (strCase.IsEmpty())	 return;
     if (!m_strWhere.IsEmpty())
	     m_strWhere = m_strWhere + " And ";
	 if (bText)
	  m_strWhere = m_strWhere + strName + " = '" + strCase + "'";
	 else
	  m_strWhere = m_strWhere + strName + " = " + strCase + "";
  }
}

void CStringSQL::SetFoot(LPCSTR pFoot)
{
   m_strFoot = pFoot;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -