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

📄 db.cpp

📁 墨香最新私服
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				break;
			case 	SQL_SUCCESS_WITH_INFO:	
				break;
			case 	SQL_SUCCESS:	
				break;
			case 	SQL_STILL_EXECUTING:	
				break;
			case 	SQL_NEED_DATA:	
				break;
			case 	SQL_ERROR:
			case 	SQL_INVALID_HANDLE:	
			default:
				DisplaySQLError(pCon);
		}
	}
	SQLFreeHandle(SQL_HANDLE_STMT,hStmt);

	return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
// Insert, Update, Delete 巩 傈侩 窃荐
// 盔窍绰 器杆捞 绝绰 版快 流立 孽府巩阑 累己
// 牢磊狼 箭磊啊 逞 促剧秦 档历洒 嘎苗临荐啊 绝澜..^^;;;
// 窜 select 巩篮 酒贰 促弗 孽府窃荐甫 捞侩且 巴
////////////////////////////////////////////////////////////////////////////////////////////
BOOL	CDB::ExcuteIUD(LPDBCON pCon, LPSTR szQuery)
{
	RETCODE		retCode;
	
	if (pCon == NULL) return 0;

	char Buffer[MAX_LENGTH_QUERY];
	strcpy(Buffer,szQuery);

	if (pCon->hStmt == NULL)
	{
		retCode = SQLAllocHandle(SQL_HANDLE_STMT, pCon->hDBC, &(pCon->hStmt));
		if(retCode != SQL_SUCCESS && retCode != SQL_SUCCESS_WITH_INFO)
			DisplaySQLError(pCon);
	}


	retCode = SQLExecDirect(pCon->hStmt, (UCHAR *)Buffer, SQL_NTS);
	if (SQLOK(retCode))
	{
		return 1;
	}
	else
	{
		switch(retCode)
		{
			case 	SQL_NO_DATA:
				m_pWriteMessage("ExcuteIUD Fail : No Data");
				break;
			case 	SQL_SUCCESS_WITH_INFO:	
				break;
			case 	SQL_SUCCESS:	
				break;
			case 	SQL_STILL_EXECUTING:	
				break;
			case 	SQL_NEED_DATA:	
				break;
			case 	SQL_ERROR:
			case 	SQL_INVALID_HANDLE:	
			default:
				DisplaySQLError(pCon);
		}
	}
	return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
// 裹侩 肺变 窃荐 
// 牢磊啊 腹酒辑 汗棱茄 捞蜡绰 裹侩捞扁 锭巩捞促.
// 喊档肺 SimpleLogin 窃荐 力傍 
// 牢磊汲疙 
// 目池记, 抛捞喉 捞抚, ID漠烦捞抚 , PW漠烦捞抚, 荤侩磊啊 涝仿茄 酒捞叼, 菩胶况靛, 府畔蔼阑 茫酒尘 漠烦捞抚, 府畔蔼阑 持阑 器牢磐, 府畔蔼狼 辨捞, 府畔蔼狼 蜡屈
// 酒捞叼客 菩胶况靛啊 老摹窍绰 饭内靛甫 八祸秦 秦寸 饭内靛啊 乐绰 版快
// 秦寸 饭内靛狼 pRetCol 漠烦狼 郴侩阑 sqlType屈栏肺 佬绢辑 iLength辨捞父怒 佬绢辑 pRetValue俊 淬酒焊辰促. 
// 绝阑 版快 FASLE 府畔.
// 府畔蔼 蜡屈 Dword: SQL_C_UBIGINT, 胶飘傅 SQL_C_CHAR 唱赣瘤绰 饭欺繁胶 曼炼 
// 静饭爹 荤侩矫俊档 贸府 犬牢皋技瘤甫 馆靛矫 罐酒具 窍绰 窃荐!
////////////////////////////////////////////////////////////////////////////////////////////
BOOL	CDB::Login(LPDBCON pCon, LPSTR szTableName, LPSTR pColID, LPSTR pColPW, LPSTR pID, LPSTR pPW, LPSTR pRetCol, LPVOID pRetValue, int iLength, SQLSMALLINT sqlType)
{
	RETCODE		retCode;
	SDWORD		cbValue;
	
	if (pCon == NULL) return 0;
	if (pPW == NULL || pID == NULL) return 0;
	if (pColPW == NULL || pColID == NULL) return 0;

	char Buffer[MAX_LENGTH_QUERY];

	sprintf(Buffer, "SELECT  %s FROM %s where %s = '%s' AND %s = '%s'",pRetCol, szTableName, pColID, pID, pColPW, pPW);

	if (pCon->hStmt == NULL)
	{
		retCode = SQLAllocHandle(SQL_HANDLE_STMT, pCon->hDBC, &(pCon->hStmt));
		if(retCode != SQL_SUCCESS && retCode != SQL_SUCCESS_WITH_INFO)
			DisplaySQLError(pCon);
	}

	retCode = SQLExecDirect(pCon->hStmt, (UCHAR *)Buffer, SQL_NTS);
	if (SQLOK(retCode))
	{
		retCode = SQLFetch(pCon->hStmt);

		if (retCode == SQL_SUCCESS)
		{
			retCode = SQLGetData(pCon->hStmt, 1, sqlType, pRetValue, iLength, &cbValue);
			if (retCode == SQL_SUCCESS && pRetValue> 0)
			{
				SQLFreeStmt(pCon->hStmt,SQL_CLOSE);
				return 1;
			}
			else 
			{
				SQLFreeStmt(pCon->hStmt,SQL_CLOSE);
				return 0;
			}
		}
	}
	else
		DisplaySQLError(pCon);

	SQLFreeStmt(pCon->hStmt,SQL_CLOSE);
//	pCon->hStmt = NULL;
	return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
// 缴敲 肺变 窃荐 
// 埃窜窍霸 富秦 荤侩磊啊 涝仿茄 拌沥捞抚苞 厚锅阑 八荤秦 嘎栏搁 捞 蜡历狼 绊蜡dword酒捞叼甫 器牢磐俊 持绢霖促.
// 捞 痹蘑俊 嘎瘤 臼霸 DB啊 汲拌等 版快 困狼 裹侩 肺变窃荐甫 镜 巴.
// 牢磊汲疙 
// 目池记, 荤侩磊啊 涝仿茄 酒捞叼, 菩胶况靛, 府畔蔼阑 持阑 器牢磐
// 酒捞叼客 菩胶况靛啊 老摹窍绰 饭内靛甫 八祸秦 秦寸 饭内靛啊 乐绰 版快
// 秦寸 饭内靛狼 DEFAULT_USER_GUID_COL漠烦狼 dwUserId蔼阑 pRetValue俊 淬酒 逞败霖促.
// 绝阑 版快 FASLE 府畔.
// 府畔蔼 蜡屈 Dword: SQL_C_UBIGINT, 胶飘傅 SQL_C_CHAR 唱赣瘤绰 饭欺繁胶 曼炼 
////////////////////////////////////////////////////////////////////////////////////////////
BOOL	CDB::SimpleLogin(LPDBCON pCon,LPSTR pID, LPSTR pPW, LPVOID pRetValue)
{
	RETCODE		retCode;
	SDWORD		cbValue;
	
	if (pCon == NULL) return 0;
	if (pPW == NULL || pID == NULL) return 0;

	char Buffer[MAX_LENGTH_QUERY];

	sprintf(Buffer, "SELECT  %s FROM %s where %s = '%s' AND %s = '%s'",m_szDefault_User_guid, m_szDefault_User_table, m_szDefault_User_account, pID, m_szDefault_User_pw, pPW);

	if (pCon->hStmt == NULL)
	{
		retCode = SQLAllocHandle(SQL_HANDLE_STMT, pCon->hDBC, &(pCon->hStmt));
		if(retCode != SQL_SUCCESS && retCode != SQL_SUCCESS_WITH_INFO)
			DisplaySQLError(pCon);
	}

	retCode = SQLExecDirect(pCon->hStmt, (UCHAR *)Buffer, SQL_NTS);
	if (SQLOK(retCode))
	{
		retCode = SQLFetch(pCon->hStmt);

		if (retCode == SQL_SUCCESS)
		{
			retCode = SQLGetData(pCon->hStmt, 1, SQL_C_UBIGINT, pRetValue, 4, &cbValue);
			if (retCode == SQL_SUCCESS && pRetValue> 0)
			{
				SQLFreeStmt(pCon->hStmt,SQL_CLOSE);
				return 1;
			}
			else 
			{
				SQLFreeStmt(pCon->hStmt,SQL_CLOSE);
				return 0;
			}
		}
	}
	else
		DisplaySQLError(pCon);

	SQLFreeStmt(pCon->hStmt,SQL_CLOSE);
//	pCon->hStmt = NULL;
	return 0;
}


////////////////////////////////////////////////////////////////////////////////////////////
// 磊蜡孽府 窃荐(SELECT巩 傈侩)
// 牢磊汲疙 
// 目池记, 孽府巩, 馆券登绰 饭内靛狼 箭磊甫 淬阑 DWORD狼 器牢磐
// "select City, FirstName from employees" 鞍篮 侥栏肺 孽府巩阑 父甸绢 持绢霖促.
// 捞 窃荐绰 define蔼阑 曼炼秦 皋葛府甫 棱绊 孽府狼 搬苞甫 淬篮 备炼眉狼 器牢磐甫 府畔茄促.
// 促吝漠烦 孽府 啊瓷
// 林狼!!!!
// 郴何俊辑 皋葛府甫 棱酒辑 器牢磐甫 逞扁骨肺 罐酒辑 荤侩茄 饶 怖 皋葛府甫 钱绢拎具 茄促.!!!!!!!!!!!!!!
// 皋牢橇废狼 VK_F4 锅阑 曼炼..(荤侩抗)
// 捞巴捞 捞弗官 Column -Wise Binding 规侥捞促.
////////////////////////////////////////////////////////////////////////////////////////////

LPQUERY FAR PASCAL CDB::FreeQuery(LPDBCON pCon,LPSTR szBuffer, LPDWORD pNumRow)
{
	SWORD     nCols = 0;                  // # of result columns
	SWORD     nCount;                     // index
	SQLRETURN nReturn;                    // return code
	
	if (pCon->hStmt == NULL)
	{
		nReturn = SQLAllocHandle(SQL_HANDLE_STMT, pCon->hDBC, &(pCon->hStmt));
		if(nReturn != SQL_SUCCESS && nReturn != SQL_SUCCESS_WITH_INFO)
		{
			m_pWriteMessage(szBuffer);
			DisplaySQLError(pCon);
		}
	}

  // execute SQL and process errors if any
   // call SQLExecDirect to execute the SQL statement
   nReturn = SQLExecDirect(pCon->hStmt, (UCHAR *)szBuffer, SQL_NTS);
   if (nReturn != SQL_SUCCESS) 
   {
	    m_pWriteMessage(szBuffer);
		DisplaySQLError(pCon);
      // if the return value was just information, carry on
      if (nReturn != SQL_SUCCESS_WITH_INFO) 
	  {
         // Close the open result set.
         SQLCloseCursor(pCon->hStmt);
         return (LPQUERY) NULL;
      }
   }

   // call SQLNumResultCols to calculate the number of columns in
   // the result set, if more than the MAX_COL (the array boundary)
   // limit the number to MAX_COL and display truncation warning.
   // if it is 0, the statement probably was a non-SELECT simply return

   nReturn = SQLNumResultCols(pCon->hStmt, &nCols);
   if (nCols >= MAX_COL_NUM) 
   {
      nCols = MAX_COL_NUM;
   }
   else if (nCols == 0) 
   {
      // Close the open result set.
      SQLCloseCursor(pCon->hStmt);
      return (LPQUERY) NULL;
   }
	// 单捞鸥甫 淬扁 困茄 皋葛府甫 且寸茄促.
	QUERYST stData;
	memset(&stData,0,sizeof(QUERYST));
//	for (int k=0;k<MAX_COL_NUM;k++)
//		stData.Length[k] = 0;
	stData.nNum = nCols;
	
//	LPQUERY RealData = new QUERYST[MAX_ROW_NUM];
	LPQUERY RealData = (LPQUERY) m_pResultMemory->Alloc();
	if(!RealData) 
	{
		m_pWriteMessage("FreeQuery : Fail to alloc memory");
		return (LPQUERY) NULL;
	}
	memset(RealData,0,MAX_ROW_NUM*sizeof(QUERYST));
   // call SQLBindCol to bind column data array and column data length
   // array to the result set
   for(nCount=0; nCount<nCols; nCount++)
      SQLBindCol(pCon->hStmt, (UWORD)(nCount+1), SQL_C_CHAR, stData.Data[nCount], MAX_COL_LENGTH, &(stData.Length[nCount]));


/* // call SQLDescribeCol to get description of each column in the
   // result set. Store the column name in the display buffer and
   // make it the first entry in the results list box of the MDI
   // child window.
   for(nCount=1; nCount <= nCols; nCount++)
   {
      SQLDescribeCol(pCon->hStmt, nCount, szBuffer, MAX_DATA_LEN, &swColLength, &swColType, &udwColDef,
                     &swColScale, &swColNull);
   }
*/
   // call SQLFetch to fetch each row of the result set. Extract data
   // value and store it in the display buffer, separated by tabs.
   // continue until SQLFetch fails.
   DWORD nCountRow = 0;
   for(; (nReturn = SQLFetch(pCon->hStmt))==SQL_SUCCESS || nReturn==SQL_SUCCESS_WITH_INFO;)
   {
      
	   if (nCountRow == MAX_ROW_NUM) break;
	   memcpy(&(RealData[nCountRow]),&stData,sizeof(QUERYST));
	   nCountRow++;
	   if (nReturn != SQL_SUCCESS)
	   {
			m_pWriteMessage(szBuffer);
			DisplaySQLError(pCon);
	   }
   }

   // if there was any error returned by SQLFetch, display it
   if (nReturn == SQL_ERROR)
   {
		m_pWriteMessage(szBuffer);
		DisplaySQLError(pCon);
   }

   // Close the open result set.
   // Unbind all bound columns.
	SQLCloseCursor(pCon->hStmt);
	SQLFreeStmt(pCon->hStmt, SQL_UNBIND);
	SQLFreeStmt(pCon->hStmt, SQL_RESET_PARAMS);
//	pCon->hStmt = NULL;

   memcpy(pNumRow,&nCountRow,4);
   return RealData;
}

////////////////////////////////////////////////////////////////////////////////////////////
// 磊蜡Middle孽府 窃荐(SELECT巩 傈侩)
// 牢磊汲疙 
// 目池记, 孽府巩, 馆券登绰 饭内靛狼 箭磊甫 淬阑 DWORD狼 器牢磐
// 橇府孽府客 扼瘤 孽府狼 吝埃. 橇府孽府焊促绰 辨绊 扼瘤 孽府焊促绰 陋篮 蔼阑 罐酒柯促. 
////////////////////////////////////////////////////////////////////////////////////////////
LPMIDDLEQUERY FAR PASCAL CDB::FreeMiddleQuery(LPDBCON pCon,LPSTR szBuffer, LPDWORD pNumRow)
{
	SWORD     nCols = 0;                  // # of result columns
	SWORD     nCount;                     // index
	SQLRETURN nReturn;                    // return code
	
	if (pCon->hStmt == NULL)
	{
		nReturn = SQLAllocHandle(SQL_HANDLE_STMT, pCon->hDBC, &(pCon->hStmt));
		if(nReturn != SQL_SUCCESS && nReturn != SQL_SUCCESS_WITH_INFO)
		{
			m_pWriteMessage(szBuffer);
			DisplaySQLError(pCon);
		}
	}

  // execute SQL and process errors if any
   // call SQLExecDirect to execute the SQL statement
   nReturn = SQLExecDirect(pCon->hStmt, (UCHAR *)szBuffer, SQL_NTS);
   if (nReturn != SQL_SUCCESS) 
   {
	    m_pWriteMessage(szBuffer);
		DisplaySQLError(pCon);
      // if the return value was just information, carry on
      if (nReturn != SQL_SUCCESS_WITH_INFO) 
	  {
         // Close the open result set.
         SQLCloseCursor(pCon->hStmt);
         return (LPMIDDLEQUERY) NULL;
      }
   }

   // call SQLNumResultCols to calculate the number of columns in
   // the result set, if more than the MAX_COL (the array boundary)
   // limit the number to MAX_COL and display truncation warning.
   // if it is 0, the statement probably was a non-SELECT simply return

   nReturn = SQLNumResultCols(pCon->hStmt, &nCols);
   if (nCols >= MAX_MIDDLECOL_NUM) 
   {
      nCols = MAX_MIDDLECOL_NUM;
   }
   else if (nCols == 0) 
   {
      // Close the open result set.
      SQLCloseCursor(pCon->hStmt);
      return (LPMIDDLEQUERY) NULL;
   }
	// 单捞鸥甫 淬扁 困茄 皋葛府甫 且寸茄促.
	MIDDLEQUERYST stData;
	memset(&stData,0,sizeof(MIDDLEQUERYST));
//	for (int k=0;k<MAX_COL_NUM;k++)
//		stData.Length[k] = 0;
	stData.nNum = nCols;
	
//	LPQUERY RealData = new QUERYST[MAX_ROW_NUM];
	LPMIDDLEQUERY RealData = (LPMIDDLEQUERY) m_pResultMemory->Alloc();
	if(!RealData) 
	{
		m_pWriteMessage("FreeMiddleQuery : Fail to alloc memory");
		return (LPMIDDLEQUERY) NULL;
	}
	memset(RealData,0,MAX_MIDDLECOL_NUM*sizeof(MIDDLEQUERYST));
   // call SQLBindCol to bind column data array and column data length
   // array to the result set
   for(nCount=0; nCount<nCols; nCount++)

⌨️ 快捷键说明

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