📄 swbltin.c
字号:
/* swbltin.c - built-in processing routines (if,cursor,symbol, etc)/*/* Copyright (c) 1995-1999 Applied Information Technologies, Inc./* All Rights Reserved./* /* Distributed uder the GNU General Public License which was included in/* the file named "LICENSE" in the package that you recieved./* If not, write to:/* The Free Software Foundation, Inc.,/* 675 Mass Ave, Cambridge, MA 02139, USA. */#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <fcntl.h>#include <sys/types.h>#include <sys/wait.h>#include "sqlweb.h"/*/* Internal Private Functions.... */static eBoolean_t iCp2CookList(PI *pPI);static eBoolean_t iCp2PIList(PI *pPI);static eBoolean_t iCp2PIAList(SYMBOL *pPIA);static eBoolean_t ChopPI(PI *pPI,eBoolean_t b);/* Global Variables defined elsewhere... */extern SQLWEB_LDA gLDA;extern eBoolean_t gbBufferOutput;/*/* Global Variables used by all modules/* but owned by this one! *//* Global Variables Private to THIS FILE */static LIST *glCookList ,*glPIList ,*glPIAList ;eBoolean_tsqlweb_if( PI *pPI ,eBoolean_t *pbExpr ){ char sSQL[MAX_TOKVAL_SIZE]; char *pSQL, *pBuf, *pExpr; SQLWEB_CURSOR cda; *pbExpr = eFalse; if(!is_casematch(pPI->pTagName,"IF") && !is_casematch(pPI->pTagName,"SQLWEB-IF")) { MsgPush("sqlweb_if:Can't Process %s",pPI->pTagName); return(eFalse); } /* /* Process IF Tag */ (*pbExpr) = eFalse; if(ISeTrue(GetPIAValueREF(pPI,"EXPR",&pExpr))) { if(ISeTrue(GetPIAValueREF(pPI,"EVAL",&pBuf)) && (is_casematch(pBuf,"TRUE")) ) { ExpandString(pExpr,&pBuf); RemoveCharCodes(pBuf); pExpr = pBuf; } sprintf(sSQL,"%s %s",gpIfExpr,pExpr); RETeFalse(DbOpenCursor(&gLDA,sSQL,&cda) ,"DbOpenCursor Failed" ); RETeFalse(DbFetchCursor(&cda,eTrue) /* Close */ ,"DbFetchCursor Failed" ); (*pbExpr) = cda.bFound; ChopPI(pPI,(*pbExpr)); /* Chop Children IFF expression is FALSE */ } /* Got the "Required EXPR" symbol... */ return(eTrue);}eBoolean_tsqlweb_cursor( PI *pPI ,eBoolean_t *pbExpr ){ char *pSQL, *pBuf; SQLWEB_CURSOR cda; LIST *lBINDList; LIST *lTmpCookList; LIST *lTmpPIList; int iLoopCount=0; *pbExpr = eFalse; if(!is_casematch(pPI->pTagName,"CURSOR") &&!is_casematch(pPI->pTagName,"SQLWEB-CURSOR")) { MsgPush("sqlweb_cursor:Can't Process %s",pPI->pTagName); return(eFalse); } /* /* Process a CURSOR Tag */ DebugHTML(__FILE__,__LINE__,4,"Got a CURSOR!"); if(ISeFalse(GetPIAValueREF(pPI,"SQL",&pSQL))){ pSQL= gpNullSelect; } if(ISeTrue(GetPIAValueREF(pPI,"EVAL",&pBuf)) &&(is_casematch(pBuf,"TRUE"))) { DebugHTML(__FILE__,__LINE__,2,"Opening SQL=\"%s\"",pSQL); ExpandString(pSQL,&pBuf); RemoveCharCodes(pBuf); pSQL = pBuf; } DebugHTML(__FILE__,__LINE__,2,"Opening SQL=\"%s\"",pSQL); RETeFalse(DbOpenCursor(&gLDA,pSQL,&cda) ,"DbOpenCursor Failed" ); DebugHTML(__FILE__,__LINE__,4,"Its OPEN!"); /* /* Save the CURSOR's PI List the lBINDList. /* and create a New, clean, consolidated list and /* setup a global pointer to the new list. */ lTmpCookList = glCookList; lTmpPIList = glPIList; lBINDList = pPI->lPI; pPI->lPI = l_create("QUEUE"); glPIList = pPI->lPI; /* /* Fetch LOOP */ for(iLoopCount=0;;){ /* /* Do the FETCH */ DebugHTML(__FILE__,__LINE__,4 ,"Attempting a FETCH(%d)!" ,cda.iCursorIndex); RETeFalse(DbFetchCursor(&cda,eFalse) ,"DbFetchCursor Failed" ); if(ISeFalse(cda.bFound)) { DebugHTML(__FILE__,__LINE__,4,"Fetch Done."); break; } iLoopCount++; DebugHTML(__FILE__,__LINE__,4,"Got a ROW, attempting LIST Dup"); /* Step 1 /* Duplicate the Origional LIST to BIND to the FETCHED ROW */ if( !(glCookList = l_create("QUEUE"))) { MsgPush("l_create(lglookList) Failed"); return(eFalse); } RETeFalse(l_scan(lBINDList,(PFI)iCp2CookList) ,"l_scan(iCp2CookList) Failed" ); /* Step 2 /* Cook the Newly build glCookList built in the above step */ RETeFalse(l_scan(glCookList,(PFI)CookPI) ,"CookPI Failed in w/in CURSOR" ); if(ISeTrue(gbBufferOutput)){ /* Step 3 /* Add the newly Cooked Items to the pPI-lPI LIST /* where it belongs. */ RETeFalse(l_scan(glCookList,(PFI)iCp2PIList) ,"l_scan(iCp2PIlist) Failed" ); } l_destroy(glCookList); } /* Chop "template" Children IFF no rows processed */ if(iLoopCount==0) { ChopPI(pPI,eFalse); } /* Never Re-Cook Looped Stuff */ *pbExpr = eFalse; glCookList = lTmpCookList; glPIList = lTmpPIList; return(eTrue);}eBoolean_tsqlweb_while( PI *pPI ,eBoolean_t *pbExpr ){ char *pExpr, *pBuf; LIST *lBINDList; LIST *lTmpCookList; LIST *lTmpPIList; int iLoopCount=0; *pbExpr = eFalse; if(!is_casematch(pPI->pTagName,"WHILE") &&!is_casematch(pPI->pTagName,"SQLWEB-WHILE")) { MsgPush("sqlweb_while:Can't Process %s",pPI->pTagName); return(eFalse); } /* /* Process a WHILE Tag */ DebugHTML(__FILE__,__LINE__,3,"Got a WHILE!"); if(ISeFalse(GetPIAValueREF(pPI,"EXPR",&pExpr))) { DebugHTML(__FILE__,__LINE__,0 ,"WARN: No EXPR for While on line %d" ,pPI->iLineNbr ); MsgPush("sqlweb_while:No EXPR"); return(eTrue); } if(ISeTrue(GetPIAValueREF(pPI,"EVAL",&pBuf)) &&(is_casematch(pBuf,"TRUE"))) { ExpandString(pExpr,&pBuf); RemoveCharCodes(pBuf); pExpr = pBuf; } /* /* Save the WHILE's PI List the lBINDList. /* and create a New, clean, consolidated list and /* setup a global pointer to the new list. */ lTmpCookList = glCookList; lTmpPIList = glPIList; lBINDList = pPI->lPI; pPI->lPI = l_create("QUEUE"); glPIList = pPI->lPI; /* /* Fetch LOOP */ for(iLoopCount=0;;){ DebugHTML(__FILE__,__LINE__,2,"While-Expr=\"%s\"",pExpr); /* /* Process EXPR */ RETeFalse2(ParseIf(pExpr,pbExpr) ,"Failed to expand WHILE:%s" ,pExpr ); DebugHTML(__FILE__,__LINE__,4,"While-Expr:Done:(%s %d Children)" ,ISeFalse((*pbExpr))?"CHOP":"KEEP" ,pPI->lPI? l_size(pPI->lPI): -1 ); if(ISeFalse(*pbExpr)) { DebugHTML(__FILE__,__LINE__,4,"While Done."); break; } iLoopCount++; DebugHTML(__FILE__,__LINE__,4,"Got a TRUE, attempting LIST Dup"); /* Step 1 /* Duplicate the Origional LIST to BIND to the FETCHED ROW */ if( !(glCookList = l_create("QUEUE"))) { MsgPush("l_create(lglookList) Failed"); return(eFalse); } RETeFalse(l_scan(lBINDList,(PFI)iCp2CookList) ,"l_scan(iCp2CookList) Failed" ); /* Step 2 /* Cook the Newly build glCookList built in the above step */ RETeFalse(l_scan(glCookList,(PFI)CookPI) ,"CookPI Failed in w/in CURSOR" ); if(ISeTrue(gbBufferOutput)){ /* Step 3 /* Add the newly Cooked Items to the pPI-lPI LIST /* where it belongs. */ RETeFalse(l_scan(glCookList,(PFI)iCp2PIList) ,"l_scan(iCp2PIlist) Failed" ); } l_destroy(glCookList); } /* Chop "template" Children IFF no rows processed */ if(iLoopCount==0) { ChopPI(pPI,eFalse); } /* Never Re-Cook Looped Stuff */ *pbExpr = eFalse; glCookList = lTmpCookList; glPIList = lTmpPIList; return(eTrue);}eBoolean_tsqlweb_connect( PI *pPI ,eBoolean_t *pbExpr ){ char *pBuf, *pName; *pbExpr = eFalse; if(!is_casematch(pPI->pTagName,"CONNECT") &&!is_casematch(pPI->pTagName,"SQLWEB-CONNECT")) { MsgPush("sqlweb_connect:Can't Process %s",pPI->pTagName); return(eFalse); } if(ISeFalse(GetPIAValueREF(pPI,"NAME",&pName))) { if(ISeFalse(GetPIAValueREF(pPI,"SCHEMA",&pName))) { /* If no name or schema; use default found in "ini" file */ RETeFalse(DbConnect(0,&gLDA),"Failed to CONNECT to Database"); return(eTrue); } } ExpandString(pName,&pBuf); RemoveCharCodes(pBuf); pName = pBuf; RETeFalse(DbConnect(pName,&gLDA),"Failed to CONNECT to Database"); *pbExpr = eFalse; return(eTrue);}static eBoolean_tiCp2CookList( PI *pPI )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -