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

📄 cdrreadforcombined.cpp

📁 Mysql的处理
💻 CPP
字号:
#include "Date.h"#include "CDRReadForCombined.h"#include<stdio.h>#include<stdio.h>#include<iostream.h>#include<vector>using namespace std;C_CDRReadForCombined::C_CDRReadForCombined(){}C_CDRReadForCombined::~C_CDRReadForCombined(){}/** 	!!!!!!!输入的时间段需要修改*/bool C_CDRReadForCombined::SelectSCDR(		const char* szTableDate,		const char* szTableDate2,		const char* szSQLWhere,		S_OSCDR** ppCDR, int *nOutNumber, 		S_LCLOC** ppChanageLoc, int* nOutChangeLoc,		S_LLOTV** ppLOTV, int* nLOTV,		S_LCOMM** ppCommon, int* nCommon){	int i;	int result;	//List	vector<S_OSCDR*> m_nCdrs;	vector<S_LCLOC*> m_nLChangeLocation;	vector<S_LLOTV*> m_nLlotv;	vector<S_LCOMM*> m_nLcommon;	//count	vector<int> m_nCountCdrs;	vector<int> m_nCountChangeLocation;	vector<int> m_nCountlotv;	vector<int> m_nCountcommon;	int nOutNumber1(0); 	int nOutChangeLoc1(0);	int nLOTV1(0);	int nCommon1(0);		int j;	//[1]返回值设置为0	*nOutNumber= *nOutChangeLoc= *nLOTV= *nCommon=0;	//[2]计算时间段	CDate date(szTableDate, szTableDate2);	date.Calculate();	int all = date.GetCount();	//cout << "######" << all << endl;	//[3]读取列表	for(int kk=0;kk<all;kk++)	{		char dString[20];		string dString2 = date.GetAt(kk);		snprintf(dString, 20, "%s", dString2.c_str());		char szTableName[LEN_TABLENAME+1];		snprintf(szTableName, LEN_TABLENAME+1, "OSCDR%s", dString);	S_OSCDR* pCDR = NULL;		if(DbOSCDRSelect((char*)szTableName, (char*)szSQLWhere, &pCDR, &nOutNumber1, &m_Out))		{			return false;		}	//	cout << "#1" <<nOutNumber1<< endl;		if(nOutNumber1>0)		{			m_nCdrs.push_back(pCDR);			m_nCountCdrs.push_back(nOutNumber1);		}				for(int i=0;i<nOutNumber1;i++)		{			S_OSCDR* pCDR2 = &pCDR[i];			char *szSeqId = pCDR2->SeqId;				S_LCLOC* pChanageLoc = NULL;	S_LLOTV* pLOTV = NULL;	S_LCOMM* pCommon = NULL;	/*		snprintf(szTableName, LEN_TABLENAME+1, "LCLOC_OS%s", dString);			if(DbLCLOCSelect(szTableName, szSeqId, &pChanageLoc, &nOutChangeLoc1, &m_Out))			{			//	return false;			}			if(nOutChangeLoc1>0)			{				m_nLChangeLocation.push_back(pChanageLoc);				m_nCountChangeLocation.push_back(nOutChangeLoc1);			}	*/					snprintf(szTableName, LEN_TABLENAME+1, "LLOTV_OS%s", dString);			if(DbLLOTVSelect(szTableName, szSeqId, &pLOTV, &nLOTV1, &m_Out))			{			//	return false;			}			if(nLOTV1>0)			{				m_nLlotv.push_back(pLOTV);				m_nCountlotv.push_back(nLOTV1);			}				/*		snprintf(szTableName, LEN_TABLENAME+1, "LCOMM_OS%s", dString);			if(DbLCOMMSelect(szTableName, szSeqId, &pCommon, &nCommon1, &m_Out))			{			//	return false;			}						if(nCommon1>0)			{				m_nLcommon.push_back(pCommon);				m_nCountcommon.push_back(nCommon1);			}			*/		}	}	//[4]写上输出结果	//[4-1]计算总长度	int nCdrs = m_nCountCdrs.size();	for(i=0;i<nCdrs;i++) 		*nOutNumber+= m_nCountCdrs.at(i);	int nLcloc = m_nCountChangeLocation.size();	for(i=0;i<nLcloc;i++)		*nOutChangeLoc+= m_nCountChangeLocation.at(i);	int nLlotv = m_nCountlotv.size();	for(i=0;i<nLlotv;i++)		*nLOTV+= m_nCountlotv.at(i);	int nLComm = m_nCountcommon.size();	for(i=0;i<nLComm;i++)		*nCommon+= m_nCountcommon.at(i);	//cout << "#1 " <<*nOutNumber<< endl;	//cout << "#2 " <<*nOutChangeLoc<< endl;	//cout << "#3 " <<*nLOTV<< endl;	//cout << "#4 " <<*nCommon<< endl;	//[4-2]分配空间	S_OSCDR *ppCDR2 = NULL;	S_LCLOC *ppChanageLoc2 = NULL;	S_LLOTV *ppLOTV2 = NULL;	S_LCOMM *ppCommon2 = NULL;	if(*nOutNumber>0)		ppCDR2 = (S_OSCDR*)malloc(*nOutNumber* SIZE_S_OSCDR);	if(*nOutChangeLoc>0)		ppChanageLoc2 = (S_LCLOC*)malloc(*nOutChangeLoc*SIZE_S_LCLOC);	if(*nLOTV>0)		ppLOTV2 = (S_LLOTV*)malloc(*nLOTV*SIZE_S_LLOTV);	if(*nCommon>0)		ppCommon2 = (S_LCOMM*)malloc(*nCommon*SIZE_S_LCOMM);	//[4-3]组装结构	int index=0;	for(i=0,index=0;i<nCdrs;i++)	{		S_OSCDR* p = m_nCdrs.at(i);		if(p != NULL)		{			int size = m_nCountCdrs.at(i);			memcpy(&ppCDR2[index], p, size* SIZE_S_OSCDR);			index+=size;			free(p);			p = NULL;		//	cout << "## " << nCdrs << "##" << i<< "##" << size  << endl;		}	}	for(i=0,index=0;i<nLcloc;i++)	{		S_LCLOC* p = m_nLChangeLocation.at(i);		if(p != NULL)		{			int size = m_nCountChangeLocation.at(i);			memcpy(&ppChanageLoc2[index], p, size*SIZE_S_LCLOC);			index+=size;			free(p);			p = NULL;		//	cout << "## " << nLcloc << "##" << i<< "##" << size  << endl;		}	}	for(i=0,index=0;i<nLlotv;i++)	{		S_LLOTV* p = m_nLlotv.at(i);		if(p != NULL)		{			int size = m_nCountlotv.at(i);			memcpy(&ppLOTV2[index], p, size*SIZE_S_LLOTV);			index+=size;			free(p);			p = NULL;		//	cout << "## " << nLlotv << "##" << i<< "##" << size  << endl;		}	}/*	for(i=0,index=0;i<nLComm;i++)	{		S_LCOMM* p = m_nLcommon.at(i);		if(p != NULL)		{			int size = m_nCountcommon.at(i);			memcpy(&ppCommon2[index], p, size*SIZE_S_LCOMM);			index+=size;			free(p);			p = NULL;		}	}*/	*ppCDR = ppCDR2;	*ppChanageLoc = ppChanageLoc2;	*ppLOTV = ppLOTV2;	*ppCommon = ppCommon2;	//[4-4]释放空间	m_nCdrs.clear();	m_nLChangeLocation.clear();	m_nLlotv.clear();	m_nLcommon.clear();	//count	m_nCountCdrs.clear();	m_nCountChangeLocation.clear();	m_nCountlotv.clear();	m_nCountcommon.clear();	return true;}/** 	!!!!!!!输入的时间段需要修改*/bool C_CDRReadForCombined::SelectGCDR(		const char* szTableDate,		const char* szTableDate2,		const char* szSQLWhere,		S_OGCDR** ppCDR, int *nOutNumber, 		S_LCLOC** ppChanageLoc, int *nOutChangeLoc,		S_LLOTV** ppLOTV, int *nLOTV,		S_LCOMM** ppCommon, int *nCommon){	cout << "C_CDRReadForCombined::SelectGCDR" << endl;	int i;	int result;	//List	vector<S_OGCDR*> m_nCdrs;	vector<S_LCLOC*> m_nLChangeLocation;	vector<S_LLOTV*> m_nLlotv;	vector<S_LCOMM*> m_nLcommon;	//count	vector<int> m_nCountCdrs;	vector<int> m_nCountChangeLocation;	vector<int> m_nCountlotv;	vector<int> m_nCountcommon;	int nOutNumber1; 	int nOutChangeLoc1;	int nLOTV1;	int nCommon1;		int j;	//[1]返回值设置为0	*nOutNumber= *nOutChangeLoc= *nLOTV= *nCommon=0;	//[2]计算时间段	CDate date(szTableDate, szTableDate2);	date.Calculate();	int all = date.GetCount();//	cout << "######" << all << endl;	//[3]读取列表	for(int kk=0;kk<all;kk++)	{		char dString[20];		string dString2 = date.GetAt(kk);		snprintf(dString, 20, "%s", dString2.c_str());		char szTableName[LEN_TABLENAME+1];		snprintf(szTableName, LEN_TABLENAME+1, "OGCDR%s", dString);		S_OGCDR* pCDR = NULL;		if(DbOGCDRSelect((char*)szTableName, (char*)szSQLWhere, &pCDR, &nOutNumber1, &m_Out))		{		//	return false;		}//		cout << "*****************" <<nOutNumber1<< endl;		if(nOutNumber1>0)		{			m_nCdrs.push_back(pCDR);			m_nCountCdrs.push_back(nOutNumber1);		}				for(int i=0;i<nOutNumber1;i++)		{			S_OGCDR* pCDR2 = &pCDR[i];			char *szSeqId = pCDR2->SeqId;						S_LCLOC* pChanageLoc = NULL;			S_LLOTV* pLOTV = NULL;			S_LCOMM* pCommon = NULL;			//			cout << "@@@@@@@0 " <<nOutNumber1<< endl;	/*		snprintf(szTableName, LEN_TABLENAME+1, "LCLOC_OG%s", dString);			if(DbLCLOCSelect(szTableName, szSeqId, &pChanageLoc, &nOutChangeLoc1, &m_Out))			{			//	return false;			}			if(nOutChangeLoc1>0)			{				m_nLChangeLocation.push_back(pChanageLoc);				m_nCountChangeLocation.push_back(nOutChangeLoc1);			}//			cout << "@@@@@@@1 " <<nOutChangeLoc1<< endl;	*/					snprintf(szTableName, LEN_TABLENAME+1, "LLOTV_OG%s", dString);			if(DbLLOTVSelect(szTableName, szSeqId, &pLOTV, &nLOTV1, &m_Out))			{			//	return false;			}			if(nLOTV1>0)			{				m_nLlotv.push_back(pLOTV);				m_nCountlotv.push_back(nLOTV1);			}//			cout << "@@@@@@@2 " <<nLOTV1<< endl;						snprintf(szTableName, LEN_TABLENAME+1, "LCOMM_OG%s", dString);			if(DbLCOMMSelect(szTableName, szSeqId, &pCommon, &nCommon1, &m_Out))			{			//	return false;			}						if(nCommon1>0)			{				m_nLcommon.push_back(pCommon);				m_nCountcommon.push_back(nCommon1);			}			//			cout << "@@@@@@@3 " <<nCommon1<< endl;		}	}	//[4]写上输出结果	//[4-1]计算总长度	int nCdrs = m_nCountCdrs.size();	for(i=0;i<nCdrs;i++) 		*nOutNumber+= m_nCountCdrs.at(i);	int nLcloc = m_nCountChangeLocation.size();	for(i=0;i<nLcloc;i++)		*nOutChangeLoc+= m_nCountChangeLocation.at(i);	int nLlotv = m_nCountlotv.size();	for(i=0;i<nLlotv;i++)		*nLOTV+= m_nCountlotv.at(i);	int nLComm = m_nCountcommon.size();	for(i=0;i<nLComm;i++)		*nCommon+= m_nCountcommon.at(i);//	cout << "#1 " <<*nOutNumber<< endl;//	cout << "#2 " <<*nOutChangeLoc<< endl;//	cout << "#3 " <<*nLOTV<< endl;//	cout << "#4 " <<*nCommon<< endl;	//[4-2]分配空间	S_OGCDR *ppCDR2 = NULL;	S_LCLOC *ppChanageLoc2 = NULL;	S_LLOTV *ppLOTV2 = NULL;	S_LCOMM *ppCommon2 = NULL;	if(*nOutNumber>0)		ppCDR2 = (S_OGCDR*)malloc(*nOutNumber* SIZE_S_OGCDR);	if(*nOutChangeLoc>0)		ppChanageLoc2 = (S_LCLOC*)malloc(*nOutChangeLoc*SIZE_S_LCLOC);	if(*nLOTV>0)		ppLOTV2 = (S_LLOTV*)malloc(*nLOTV*SIZE_S_LLOTV);	if(*nCommon>0)		ppCommon2 = (S_LCOMM*)malloc(*nCommon*SIZE_S_LCOMM);	//[4-3]组装结构	int index=0;	for(i=0,index=0;i<nCdrs;i++)	{		S_OGCDR* p = m_nCdrs.at(i);		if(p != NULL)		{			int size = m_nCountCdrs.at(i);			memcpy(&ppCDR2[index], p, size* SIZE_S_OGCDR);			index+=size;			free(p);			p = NULL;		//	cout << "## " << nCdrs << "##" << i<< "##" << size  << endl;		}	}	for(i=0,index=0;i<nLcloc;i++)	{		S_LCLOC* p = m_nLChangeLocation.at(i);		if(p != NULL)		{			int size = m_nCountChangeLocation.at(i);			memcpy(&ppChanageLoc2[index], p, size*SIZE_S_LCLOC);			index+=size;			free(p);			p = NULL;		//	cout << "## " << nLcloc << "##" << i<< "##" << size  << endl;		}	}	for(i=0,index=0;i<nLlotv;i++)	{		S_LLOTV* p = m_nLlotv.at(i);		if(p != NULL)		{			int size = m_nCountlotv.at(i);			memcpy(&ppLOTV2[index], p, size*SIZE_S_LLOTV);			index+=size;			free(p);			p = NULL;		//	cout << "## " << nLlotv << "##" << i<< "##" << size  << endl;		}	}	for(i=0,index=0;i<nLComm;i++)	{		S_LCOMM* p = m_nLcommon.at(i);		if(p != NULL)		{			int size = m_nCountcommon.at(i);			memcpy(&ppCommon2[index], p, size*SIZE_S_LCOMM);			index+=size;			free(p);			p = NULL;		}	}	*ppCDR = ppCDR2;	*ppChanageLoc = ppChanageLoc2;	*ppLOTV = ppLOTV2;	*ppCommon = ppCommon2;	//[4-4]释放空间	m_nCdrs.clear();	m_nLChangeLocation.clear();	m_nLlotv.clear();	m_nLcommon.clear();	//count	m_nCountCdrs.clear();	m_nCountChangeLocation.clear();	m_nCountlotv.clear();	m_nCountcommon.clear();	return true;}void C_CDRReadForCombined::Test(){		S_OSCDR* ppSCDR=NULL; 		S_OGCDR* ppGCDR=NULL; 		S_LCLOC* ppSChanageLoc=NULL,* ppGChanageLoc=NULL; 		S_LLOTV* ppSLOTV=NULL,			* ppGLOTV=NULL; 		S_LCOMM* ppSCommon=NULL,		* ppGCommon=NULL; 		int nSOutNumber,nGOutNumber; 		int nSLOTV,			nGLOTV;		int nSChangeLoc,nGChangeLoc;		int nSCommon,		nGCommon;		char* szSTableDate=GetSysdate();		char* szGTableDate="";		char* szSSQLWhere="1=1";		char* szGSQLWhere="1=1";			printf("start to C_CDRReadForCombined !\n");					printf("1.1\n");		SelectSCDR(szSTableDate,"",szSSQLWhere,\		 &ppSCDR,&nSOutNumber, \		 &ppSChanageLoc,  &nSChangeLoc,\		 &ppSLOTV,  &nSLOTV,\		 &ppSCommon, &nSCommon);		 				printf("2.1  SCDR count is [%d]\n",nSOutNumber);			int s;		for( s=0;s<nSOutNumber;s++)		{			printf("SCDR:[%s][%d]\n",(ppSCDR+s)->SeqId,s);			printf("SCDR:[%s][%d]\n",(ppSCDR+s)->TableName,s);		//	printf("$$$$$$$$$$$$$$$$$$$$$$[%s][%d]\n",(ppSCDR+s)->CallDuration,s);		}	/*	printf("2.1  CLOC count is [%d]\n",nSChangeLoc);						for( s=0;s<nSChangeLoc;s++)						printf("CLOC:[%s][%d]\n",(ppSChanageLoc+s)->SeqId,s);		printf("2.1  LOTV count is [%d]\n",nSLOTV);			for( s=0;s<nSLOTV;s++)			printf("LOTV:[%s][%d]\n",(ppSLOTV+s)->SeqId,s);		printf("2.1  LCOMM count is [%d]\n",nSCommon);			for( s=0;s<nSCommon;s++)			printf("LCOMM:[%s][%d]\n",(ppSCommon+s)->SeqId,s);										printf("3.1\n");		SelectGCDR(szGTableDate,"",szGSQLWhere,		&ppGCDR, &nGOutNumber, 		&ppGChanageLoc, &nGChangeLoc,		&ppGLOTV,&nGLOTV,		&ppGCommon,&nGCommon);							printf("4.1\n");			printf("4.1.1\n GCDR count is :[%d]\n",nGOutNumber);		int g;		for( g=0;g<nGOutNumber;g++)			printf("GCDR:[%s][%d]\n",(ppGCDR+g)->SeqId,g);			printf("4.1.2  CLOC[%d]\n",nGChangeLoc);		for(int g=0;g<nGChangeLoc;g++)			printf("CLOC:[%s][%d]\n",(ppGChanageLoc+g)->SeqId,g);			printf("4.1.3LOTV[%d]\n",nGLOTV);		for(int g=0;g<nGLOTV;g++)			printf("LOTV:[%s][%d]\n",(ppGLOTV+g)->SeqId,g);			printf("4.1.4 LCOMM[%d]\n",nGCommon);		for(int g=0;g<nGCommon;g++)			printf("LCOMM:[%s][%d]\n",(ppGCommon+g)->SeqId,g);		}*/	}

⌨️ 快捷键说明

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