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

📄 datasplit.pc

📁 一个LINUX下面
💻 PC
📖 第 1 页 / 共 5 页
字号:
			sprintf(chTemp2,"WHERE accounte_date='%s' AND seq=%d AND table_name=upper('%s') ",g_strPreYMonth,iMaxSeq,pTableSet[i].Table_Name);
			sprintf( achSql, "%s%s",chTemp1,chTemp2);
			EXEC SQL PREPARE select_stmt FROM :achSql;
			EXEC SQL EXECUTE select_stmt;
		
			sprintf(chTemp1,"UPDATE his_expimp_tab_cfg SET state=0 ");
			sprintf(chTemp2,"WHERE upper(table_name)=upper('%s') AND on_system='%s' AND do_class='%c' ",pTableSet[i].Table_Name,pTableSet[i].On_System,pTableSet[i].Do_Class);
			sprintf( achSql, "%s%s",chTemp1,chTemp2);
			EXEC SQL PREPARE select_stmt FROM :achSql;
			EXEC SQL EXECUTE select_stmt;	
		}
		if ( iRtn == 0 )
		{
			sprintf(chTemp1,"UPDATE his_expimp_tab_log SET end_time=sysdate,succ_flag='F' ");
			sprintf(chTemp2,"WHERE accounte_date='%s' AND seq=%d AND table_name=upper('%s') ",g_strPreYMonth,iMaxSeq,pTableSet[i].Table_Name);
			sprintf( achSql, "%s%s",chTemp1,chTemp2);
			EXEC SQL PREPARE select_stmt FROM :achSql;
			EXEC SQL EXECUTE select_stmt;
		}
		iRtn = CommitWork();
		/*写日志文件*/
	}/*end for*/
	if( ConnectDB(g_strDestDB)!=1 )
	{
		/**/
		printf("connect hisDB failed!!\n\n");
		return 0;
	}
	sprintf(chTemp1,"UPDATE his_expimp_log SET end_time=sysdate,do_numbers=%d + %d, succ_numbers=%d, failed_numbers=%d ",sCnts,fCnts,sCnts,fCnts);
	sprintf(chTemp2,"WHERE accounte_date='%s' AND seq=%d ",g_strPreYMonth,iMaxSeq);
	sprintf( achSql, "%s%s",chTemp1,chTemp2);
	EXEC SQL PREPARE select_stmt FROM :achSql;
	EXEC SQL EXECUTE select_stmt;
	
	iRtn = CommitWork();

	/*处理结束,记录日志表和写日志文件*/
	sprintf( g_strLogLine, "Together deal %d tables,success %d tables,failed %d tables! \n", sCnts + fCnts, sCnts, fCnts );
	WriteLog( g_strLogLine );
	sprintf( g_strLogLine, "************************Progress   End***********************\n\n");
	WriteLog( g_strLogLine );
	return 1;
	
goto_err01:
    printf("main() Cursor(cur1) fetch fail! error code: %d --- %s",sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
    EXEC SQL ROLLBACK WORK;
	return -900;
}/*end fun*/
/************************************************************************************
//功能:	连接数据库
//参数:
//返回值:>0 成功   <0 失败
************************************************************************************/
int ConnectDB(char dataSource[])
{
    EXEC SQL WHENEVER SQLWARNING CONTINUE;
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    EXEC SQL WHENEVER NOT FOUND CONTINUE;
    EXEC SQL CONNECT :dataSource;
	if (sqlca.sqlcode != 0)
	{	/*试3遍*/
		sleep(10);
	    EXEC SQL CONNECT :dataSource;
		if (sqlca.sqlcode != 0)
		{
		    EXEC SQL CONNECT :dataSource;
			if (sqlca.sqlcode != 0)
				return -900;
		}
	}
    return 1;
}
/************************************************************************************
//功能:	断开数据库
//参数:
//返回值:>0 成功   <0 失败
************************************************************************************/
int  ReleaseDB()
{
	EXEC SQL ROLLBACK WORK RELEASE;
	if ( sqlca.sqlcode == 0 )
		return 1;
	else
		return 0;
}
/************************************************************************************
//功能:	提交事务
//参数:
//返回值:>0 成功   <0 失败
************************************************************************************/
int  CommitWork()
{
	/*EXEC SQL COMMIT WORK RELEASE;*/
	EXEC SQL COMMIT;
	if ( sqlca.sqlcode == 0 )
		return 1;
	else
		return 0;
}/*end fun*/
/************************************************************************************
//功能:	回滚事务
//参数:
//返回值:>0 成功   <0 失败
************************************************************************************/
int  RollbackWork()
{
	EXEC SQL ROLLBACK;
	if ( sqlca.sqlcode == 0 )
		return 1;
	else
		return 0;
}/*end fun*/
/************************************************************************************
//功能:处理acct_item_area01-10、payment和bill表,同一个表会在dmp下产生两个dmp文件,一个是
//全备份,一个是要倒入在线库的dmp文件
//参数:结构体(存放A类表名、保留月份数等)
//返回值:0表示失败,1表示成功
************************************************************************************/
int DoAClass(pTabParameter)	
struct Tab_Parameter *pTabParameter;
{
	char szCurTime[15];
	int iRtn  = 0;			/*获得函数调用的返回值*/
	long lSRows = 0;		/*记录表处理之前的记录数*/
	long lRows  = 0;		/*中间变量*/
	char szCntSQL[256];		/*构建统计表记录数的SQL语句*/
	char szIMPstmt[256];	/*构建IMPORT的系统语句*/
	char szEXPstmt[256];	/*构建EXPORT的系统语句*/
	struct PFILE pFile;		/*记录创建EXPORT参数文件的必须内容*/
	long lAllRows;			/*记录3个表的倒换之前的所有记录数*/
	long lPartRows[2];		/*记录3个表与临时表关联倒换的DMP记录数*/
	char szAllDFile[80];	/*全表备份时保存倒出的DMP文件名*/
	char szPartDFile[2][80];/*分离数据时保存倒出的DMP文件名*/
	char chPartRows[13];	/*保存长整型转换为字串的值*/
	int i=0;
	
	sprintf( g_strLogLine, "DoAClass deal begin   %s\n", pTabParameter->Table_Name );
	WriteLog( g_strLogLine );
	memset( szAllDFile, '\0', sizeof(szAllDFile) );
	memset( szPartDFile[0], '\0', sizeof(szPartDFile[0]) );
	memset( szPartDFile[1], '\0', sizeof(szPartDFile[1]) );
	memset(szCurTime,'\0',sizeof(szCurTime));
	
	/*公免的跟缴费数据分开做,如果带了第四个参数'pub',则只做公免,否则做缴费**/
	if( strcmp(g_strPublic,"pub")==0)
	{
		if( strcmp(pTabParameter->Table_Name,"PAYMENT")!=0 && strcmp(pTabParameter->Table_Name,"BILL")!=0 )
		{
				if(DoAClassPublic(pTabParameter)<=0)
				return 0;
		}
		else
		{
			sprintf( g_strLogLine, "  Table %s needn't deal public phone!\n", pTabParameter->Table_Name );
			WriteLog( g_strLogLine );
		}
		return 1;
	}
	/******************************统计倒换之前表中记录数:开始*****************************/
	sprintf( g_strLogLine, " count all records\n" );
	WriteLog( g_strLogLine );
	if ( ConnectDB(g_strSrcDB)!=1 )
	{
		sprintf( g_strLogLine, "DoAClass Connect to source db failed! \n\n" );
		WriteLog( g_strLogLine );
		return 0;
	}

	/*统计表的记录数*/
	sprintf( g_strLogLine, "   select count(1) from %s \n",pTabParameter->Table_Name);
	WriteLog( g_strLogLine );
	lAllRows = CountRows(pTabParameter->Table_Name);
	if ( lAllRows < 0 )
	{
		/*统计出错*/
		sprintf( g_strLogLine, "count is failed or record rows = 0! \n\n" );
		WriteLog( g_strLogLine );
		iRtn = ReleaseDB();
		return 0;
	}
	else
	{
		/*统计成功*/
		sprintf( g_strLogLine, "   rows of %s = %ld! \n",pTabParameter->Table_Name,lAllRows );
		WriteLog( g_strLogLine );
	}
	ReleaseDB();
	/******************************统计倒换之前表中记录数:结束*****************************/

	/******************************将倒换表做全备份:开始*************************************/
	/*时间不够,不做全备
	sprintf( g_strLogLine, " all data back\n" );
	WriteLog( g_strLogLine );
	*/
	/*dump 表*/
	/*
	sprintf( g_strLogLine, "  Now begin dump %s table indexs and all rows\n",pTabParameter->Table_Name);
	WriteLog( g_strLogLine );
	lRows = 0;
	strcpy( pFile.USERID, g_strSrcDB );
	strcpy( pFile.TABLE, pTabParameter->Table_Name );
	pFile.PARTITION[0] = '\0';
	pFile.QUERY[0] = '\0';
	*/
	/*sprintf( pFile.QUERY, " where rownum < 2");*/
	/*
	lRows = expData( &pFile );
	strcpy( szAllDFile, pFile.dmpFileName );
	sleep(2);
	if ( lRows == lAllRows )
	{
	*/
		/*成功*/
	/*	sprintf( g_strLogLine, "   dump %s indexs and all rows succeed! dump file name is %s\n",pTabParameter->Table_Name,pFile.dmpFileName );
		WriteLog( g_strLogLine );
	}
	else
	{
	*/
		/*失败*/
	/*	sprintf( g_strLogLine, "dump table %s indexs and all rows failed! \n\n",pTabParameter->Table_Name);
		WriteLog( g_strLogLine );
		return 0;
	}
	*/
	/******************************做全备份:结束*************************************/

	/******************************与临时表关联生成多个DMP并保留DMP文件名:开始*************/
	sprintf( g_strLogLine, " Now begin split table data\n" );
	WriteLog( g_strLogLine );
	sprintf( g_strLogLine, "  Now begin export data %s\n",pTabParameter->Table_Name);
	WriteLog( g_strLogLine );
	/*第一个dump*/
	if ( ConnectDB(g_strSrcDB)!=1 )
	{
		sprintf( g_strLogLine, "DoAClass Connect to source db failed,please check! \n\n" );
		WriteLog( g_strLogLine ); 
		return 0;
	}
	/*与临时表关联生成要DUMP online的临时表*/
	if(strcmp(pTabParameter->Table_Name,"PAYMENT")==0||strcmp(pTabParameter->Table_Name,"PREPAY_DETAIL")==0)
		iRtn=CrtOnlinePayment(pTabParameter->Table_Name,"");
	else
		iRtn=CrtOnlineTempTab(pTabParameter->Table_Name,"");
	if (iRtn != 1 )
	{
		sprintf( g_strLogLine, "create online temp %s failed! \n\n",pTabParameter->Table_Name);
		WriteLog( g_strLogLine ); 
		return 0;
	}
	iRtn = ReleaseDB();
	/*DMP*/
	strcpy( pFile.USERID, g_strTempDB );
	strcpy( pFile.TABLE, pTabParameter->Table_Name );
	pFile.PARTITION[0] = '\0';
	pFile.QUERY[0] = '\0';
	lRows = 0;
	lRows = expData( &pFile );
	lPartRows[0] = lRows;
	strcpy( szPartDFile[0], pFile.dmpFileName );
	sleep(2);/*避免重名*/
	
	/*第二个dump*/
	if ( ConnectDB(g_strSrcDB)!=1 )
	{
		sprintf( g_strLogLine, "Connect to source db failed! \n\n" );
		WriteLog( g_strLogLine ); 
		return 0;
	}
	/*与临时表关联生成要DUMP his的临时表*/
	if(strcmp(pTabParameter->Table_Name,"PAYMENT")==0||strcmp(pTabParameter->Table_Name,"PREPAY_DETAIL")==0)
		iRtn=CrtHisPayment(pTabParameter->Table_Name,"");/*payment,PREPAY_DETAIL与其它表条件不同*/
	else
		iRtn=CrtHisTempTab(pTabParameter->Table_Name,"");
	if (iRtn != 1 )
	{
		sprintf( g_strLogLine, "create his temp %s failed! \n\n",pTabParameter->Table_Name);
		WriteLog( g_strLogLine ); 
		return 0;
	}
	iRtn = ReleaseDB();
	
	/*DMP*/
	/*strcpy( pFile.USERID, g_strTempDB);继承上一个dmp的条件(一样的)
	strcpy( pFile.TABLE, pTabParameter->Table_Name );
	pFile.PARTITION[0] = '\0';
	pFile.QUERY[0] = '\0';*/
	lRows = 0;
	lRows = expDataHisDmp( &pFile );
	lPartRows[1] = lRows;
	strcpy( szPartDFile[1], pFile.dmpFileName );
	sleep(2);
	/*判分离是否成功*/
	sprintf( g_strLogLine, "   %s counts[%ld]= 1st[%ld] + 2nd[%ld]\n",pTabParameter->Table_Name,lAllRows,lPartRows[0],lPartRows[1] );
	WriteLog( g_strLogLine );
	if ( lAllRows == ( lPartRows[0] + lPartRows[1] ) )
	{
		/*成功*/
		sprintf( g_strLogLine, "   %s dump succeed! file is:one[%s]\n\t\t\ttwo[%s]\n",pTabParameter->Table_Name,szPartDFile[0], szPartDFile[1] );
		WriteLog( g_strLogLine );
	}
	else
	{
		/*失败*/
		sprintf( g_strLogLine, "%s dump failed!\n\n",pTabParameter->Table_Name);
		WriteLog( g_strLogLine );
		return 0;
	}

	/******************将第二个DMP的相关数据信息保存在his_imp_tab_info表中***************/
	if ( ConnectDB(g_strDestDB)!=1 )
	{
		sprintf( g_strLogLine, "Connect to source hisdb failed! \n\n" );
		WriteLog( g_strLogLine ); 
		return 0;
	}
	iRtn=SaveHisDmpInfo(pTabParameter->Table_Name,"",szPartDFile[1],lPartRows[1]);
	if ( iRtn != 1 )
	{
		sprintf( g_strLogLine, "deal table %s call SaveHisDmpInfo failed! \n\n",pTabParameter->Table_Name);
		WriteLog( g_strLogLine ); 
		return 0;
	}
	iRtn = ReleaseDB();
	/******************************与临时表关联生成多个DMP并保留DMP文件名:结束*************/
	
	/******************************TRUNCATE原表、删除索引:开始*****************************/
	sprintf( g_strLogLine, " Now begin truncate data and drop indexes\n" );
	WriteLog( g_strLogLine );
	if ( ConnectDB(g_strSrcDB)!=1 )
	{
		sprintf( g_strLogLine, "Connect to source db failed,please check! \n\n" );
		WriteLog( g_strLogLine );
		return 0;
	}
	/*删除索引*/
	iRtn = DropAllIndexes(pTabParameter->Table_Name);
	if ( iRtn != 0 )
	{
		sleep(10);
		iRtn = DropAllIndexes(pTabParameter->Table_Name);
	}
	sprintf( g_strLogLine, "   Drop table %s Indexes succeed! \n",pTabParameter->Table_Name);
	WriteLog( g_strLogLine );
	/*TRUNCATE原表*/
	iRtn = TruncateTab(pTabParameter->Table_Name);
	if ( iRtn == 0 )
	{
		sprintf( g_strLogLine, "Truncate table %s failed! \n\n",pTabParameter->Table_Name);
		WriteLog( g_strLogLine );
		iRtn = ReleaseDB();

⌨️ 快捷键说明

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