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

📄 delete.c

📁 在VC6环境下开发
💻 C
字号:
#include "eDbInit.h"

Table *eDbSrcListLookup(Parser *pParse, SrcList *pSrc){
	Table *pTab = 0;
	int i;
	for(i=0; i<pSrc->nSrc; i++){
		const char *zTab = pSrc->a[i].zName;
		const char *zDb = pSrc->a[i].zDatabase;
		pTab = eDbLocateTable(pParse, zTab, zDb);
		pSrc->a[i].pTab = pTab;
	}
	return pTab;
}

/*
** Process a DELETE FROM statement.
*/
void eDbDeleteFrom(
	Parser *pParse,         /* The parser context */
	SrcList *pTabList,     /* The table from which we should delete things */
	Expr *pWhere           /* The WHERE clause.  May be null */
){
	Table *pTab;           /* The table from which records will be deleted */
	eDb *db;			   /* Main database structure */
	int isView;            /* True if attempting to delete from a view */
	ParseResult *pRes = eDbMalloc(sizeof(ParseResult));
	if( pParse->nErr || eDb_malloc_failed ){
		pTabList = 0;
		goto delete_from_cleanup;
	}
	db = pParse->db;
	assert( pTabList->nSrc==1 );
	pTabList->a[0].iCursor = pParse->nTab++;
	/* Locate the table which we want to delete.
	*/
	pTab = eDbSrcListLookup(pParse, pTabList);
	if( pTab==0 )  goto delete_from_cleanup;
	isView = pTab->pSelect!=0;

	/* Resolve the column names in all the expressions.
	*/
	if( pWhere ){
		if( eDbExprResolveIds(pParse, pTabList, 0, pWhere) ){
			goto delete_from_cleanup;
		}
		if( eDbExprCheck(pParse, pWhere, 0, 0) ){
			goto delete_from_cleanup;
		}
	}
  
	/* Special case: A DELETE without a WHERE clause deletes everything.
	** It is easier just to erase the whole table.  Note, however, that
	** this means that the row change count will be incorrect.
	*/
	if( pWhere==0){
    
	}
	/* The usual case: There is a WHERE clause so we have to scan through
	** the table and pick which records to delete.
	*/
	else{
		eDbDealwithWhereClause(pTabList,pWhere);
	}
	pRes->pWhere = pWhere;
	pRes->pTable = pTab;
	pRes->op = Op_Delete;
	pParse->pResult = pRes;
	eDbSrcListDelete(pTabList);
	return;
delete_from_cleanup:
	eDbSrcListDelete(pTabList);
	eDbExprDelete(pWhere);
	eDbFree(pRes);
	return;
}

⌨️ 快捷键说明

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