user-0 提问: 嵌入式sql sybase数据库数据中转 C实现

回复:
user: user-1
content: 没有搞过，帮顶

user: user-0
content: int main() {  	char begintime[20]=""; 	int transnum=0; 	char endtime[20]=""; 	char errostr[20]=""; 	//定义变量 	EXEC SQL BEGIN DECLARE SECTION;  	/*连接数据库参数*/ 	char *SERVER_SLP=NULL; 	char *USER_SLP=NULL; 	char *PWD_SLP=NULL; 	char *DBNAME_SLP=NULL; 	 	char *SERVER_CARD=NULL; 	char *USER_CARD=NULL; 	char *PWD_CARD=NULL; 	char *DBNAME_CARD=NULL; 	/*查询清理情况表变量*/ 	int clpernum; 	 	int clcode; 	char clper[30]; 	char cltype; 	char clflag ; 	int cld_slpcard_num;  	 	char localTime[256]=""; 	/*取新删表中期数、卡号*/ 	int Acode; 	char Aperiodname[30]=""; 	char Acardno[20]=""; 	char Aflag[10]=""; 	 	int AMcode; 	char AMperiodname[30]=""; 	char AMcardno[20]=""; 	 	/*取新增表中期数、卡号*/ 	int Ccode; 	char Cperiodname[30]=""; 	char Ccardno[20]=""; 	 	int CMcode; 	char CMperiodname[30]=""; 	char CMcardno[20]="";  	/*已清理数据*/ 	int cleannum=0; 	/* 传输日志*/ 	char logtime[20]; 	char logms[500]; 	char logvalue[512]; 	char logflag[10];  	/* 记录传输情况记录表中有多少期记录要处理 */ 	int countpernum; 	EXEC SQL END DECLARE SECTION; 	 	 	//获取连接睡眠卡数据库参数 	//getInforFromConfig(CONFIG_PATH_SLP,USER_SLP,line_user_slp); 	//getInforFromConfig(CONFIG_PATH_SLP,PWD_SLP,line_pwd_slp); 	//getInforFromConfig(CONFIG_PATH_SLP,DBNAME_SLP,line_dbname_slp); 	strcpy(SERVER_SLP,"gcard31"); 	strcpy(USER_SLP,"sld"); 	strcpy(PWD_SLP,"123456"); 	strcpy(DBNAME_SLP,"sld");    	//连接睡眠卡数据库 	EXEC SQL CONNECT :USER_SLP IDENTIFIED BY :PWD_SLP USING:SERVER_SLP; 	 	EXEC SQL USE DBNAME; 	if(sqlca.sqlcode!=0) 		printf("connect slpdatabase failed!%d\n",__LINE__); 	/*	判断清理情况记录表中是否有数据要处理*/ 	//获取表中要清理记录个数 	  	/*如果没有直接退出*/ 	if(clpernum==0) 	{ 		printf("clean_record list has not anything to move!\n"); 		return ;  	}   	 	//查询睡眠卡库清理清况记录表 	EXEC SQL 		DECLARE serch_clean_record CURSOR FOR 		//按期数、操作类型、传输标志、传输数目查询 	 	SELECT  code,periodname,opetype,flag ,d_slpcard_num FROM clean_record WHERE flag='1';  	/* 打开游标*/ 	EXEC SQL OPEN serch_clean_record;  	//处理数据中传输标志为1的相应数据表 	for (;;) 	{ 		/* 记录传输情况记录表中有多少期记录要处理 */  		 		EXEC SQL FETCH serch_clean_record  INTO :clcode,:clper, 			:cltype,:clflag,:clslpcard_num; 			//记录传输开始时间 			//***************************** 			begintime=getLocalTime(); 			 			 //**************************** 		//新删表有数据要传 		if ( cltype == 1) 		{ 			cleannum=0; 			//根据期数查询新删表 			EXEC SQL 				DECLARE serch_activatelist_slp CURSOR FOR 				//根据规则编码、期数、卡号查询指定期号，标志为0未传输的数据 	 			SELECT code,periodname,cardno,FROM activatelist_slp 	 	 	 			WHERE periodname=issue,flag='0';  			/* 打开游标*/ 			EXEC SQL OPEN serch_activatelist_slp; 			 			//获取连接交易卡数据库参数 				//getInforFromConfig(CONFIG_PATH_CARD,SERVER_CARD,USER_CARD,PWD_CARD,DBNAME_CARD,line_server_card, 				//		line_user_card,line_pwd_card,line_dbname_card); 				   			strcpy(SERVER_CARD,"gcard"); 			strcpy(DBNAME_CARD,"XUNI3"); 			strcpy(USER_CARD,"oiler"); 			strcpy(PWD_CARD,"2D23C731"); 				//连接交易卡数据库 				EXEC SQL CONNECT :USER_CARD IDENTIFIED BY :PWD_CARD USING:SERVER_CARD; 				 				EXEC SQL USE DBNAME; 			/*如果连接省中心交易库失败写入省中心睡眠卡库传输日志  */ 			if(sqlca.sqlcode!=0) 			{ 				printf("connect carddatabase failed !%d\n",__LINE__); 				logtime=getLocalTime(void); 				strcpy(logms,"connect carddatabase "); 				strcpy(logvalue,"connect carddatabase failed."); 				strcpy(logflag,"-1") 				EXEC SQL  					insert into trans_log(code,periodname,opetime,opems,opevalue,flag) 					values(clcode,clper,logtime,logms,logvalue,logflag); 			} 			while(1) 			{ 				 				//获取每一行结果,插入新删中间表中 				EXEC SQL FETCH serch_activatelist_slp  INTO :Acode, 							:Aperiodname,:Acardno; 				 				 				EXEC SQL INSERT INTO ActivateListMid_slp(code,periodname,cardno)	 					VALUES (Acode,Aperiodname,Acardno); 				//插入完成后修改标志位为1(即已传输) 				EXEC SQL UPDATE activatelist_slp 　　				SET flag = '1' 　　				WHERE cardno = :Acardno;  				/*记录传输数目并打印出传输内容 */ 				transnum++; 				printf("%d %s %s",Acode,Aperiodname,Acardno); 			} 			//记录传输的数据数目(利用sql语句读取省中心交易卡库新删中间表中所有数据，即为已传输数据数目) 			//写入本期传输记录表 			//***************************** 			endtime=getLocalTime(); 			 			EXEC SQL INSERT INTO trans_record(code,periodname,begtime,endtime,trans_num,logvalue,flag) 					VALUES (); 			/*如果cleannum==transnum则没有重复，cleannum>transnum则有重复数据  */ 			//复制新增清理清单中间表到相应新增清理清单表中(没有重复数据) 			EXEC SQL INSERT INTO cleanlist_slp 				SELECT distinct code,periodname,cardno from cleanlistmid_slp; 			/* 关闭查询新删表游标*/ 			EXEC SQL CLOSE serch_activatelist_slp; 		} 		//新增表有数据要传 		if(cltype ==0) 		{ 			cleannum=0; 			//根据期数查询新增表 			EXEC SQL 				DECLARE serch_cleanlist_slp CURSOR FOR 				//期号、卡号查询指定期号，标志为0未传输的数据 	 			SELECT code,periodname,cardno FROM CleanList_slp 	 	 	 			WHERE periodname=issue,flag=0;  			/* 打开游标*/ 			EXEC SQL OPEN serch_cleanlist_slp; 			//获取连接交易卡数据库参数 				getInforFromConfig(CONFIG_PATH_CARD,SERVER_CARD,USER_CARD,PWD_CARD,DBNAME_CARD,line_server_card, 						line_user_card,line_pwd_card,line_dbname_card); 				    				//连接交易卡数据库 				EXEC SQL CONNECT :USER_CARD IDENTIFIED BY :PWD_CARD USING:SERVER_CARD; 				 				EXEC SQL USE DBNAME; 			/*如果连接省中心交易库失败写入省中心睡眠卡库传输日志  */ 			if(sqlca.sqlcode!=0) 			{ 				printf("connect carddatabase failed !%d\n",__LINE__); 				logtime=getLocalTime(); 				strcpy(logms,"connect carddatabase "); 				strcpy(logvalue,"connect carddatabase failed."); 				strcpy(logflag,"-1") 				EXEC SQL  					insert into trans_log(code,periodname,opetime,opems,opevalue,flag) 					values(clcode,clper,logtime,logms,logvalue,logflag); 			}  			while(1) 			{ 				//获取每一行结果,插入新删中间表中 				EXEC SQL FETCH serch_CleanList_slp  INTO :Ccode, 							:Cperiodname:Ccardno; 				 				 				EXEC SQL INSERT INTO CleanListMid_slp(code,periodname,cardno)	 					VALUES (:Ccode,:Cperiodname,:Ccardno); 				//插入完成后修改标志位为1(即已传输) 				EXEC SQL UPDATE CleanList_slp 　　				SET flag = '1' 　　				WHERE cardno = :Ccardno;  				/*记录传输数目并打印出传输内容 */ 				transnum++; 				printf("%d %s %s",Ccode,Cperiodname,Ccardno); 			} 			//写入本期传输记录表 			//***************************** 			endtime=getLocalTime(); 			 		 			EXEC SQL USE trans_record; 			 			EXEC SQL INSERT INTO trans_record(code,periodname,begtime,endtime,trans_num,logvalue,flag) 					VALUES (); 			 			 			//复制新删清理清单中间表到相应新删清理清单表中(没有重复数据) 				 					EXEC SQL INSERT INTO activateList_slp 						SELECT distinct code,periodname,cardno from activateListMid_sle; 			/*关闭新增查询游标*/ 			EXCE SQL CLOSE serch_cleanlist_slp; 		} 		 		 		 		/*关闭清理清单查询游标*/ 		EXCE SQL CLOSE serch_clean_record; 		//处理的期数并打印出期号 		countpernum++; 		printf("%s\n",clper); 	} 	//传输完成，清除传输标志为1的数据(即已传输数据) 	EXEC SQL DELETE FROM activateList_slp  	WHERE flag = '1';  	//修改清理情况记录表 	EXEC SQL UPDATE clean_record 　　				SET flag = '1'; 　　				WHERE periodname= :issue;  	  	  	//断开所有连接 	EXEC SQL DISCONNECT ALL; //==============================================transdata end====================================   	return 0; }

user: user-0
content: 我可以把我代码放上面你帮我看看有什么问题不？

user: user-0
content: 数据库1中表1的数据转到表2中：             server1               server2             dbname1               dbname2             user1                 user2             pwd1                  pwd2             表1                   表2 我想用嵌入式sql C程序实现 数据库是sybase

user: user-2
content: 解析一种数据表，获取到有效数据后组合成另外一种数据表！