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

📄 fakebinds.c

📁 适合于Unix/Linux下的一个持久数据库连接池
💻 C
字号:
// Copyright (c) 1999-2001  David Muse// See the file COPYING for more information#include <config.h>#include <sqlrconnection.h>stringbuffer *sqlrcursor_svr::fakeInputBinds(const char *query) {	// return null if there aren't any input binds	if (!inbindcount) {		return NULL;	}	stringbuffer	*outputquery=new stringbuffer();	// loop through the query, performing substitutions	char	prefix=inbindvars[0].variable[0];	char	*ptr=(char *)query;	int	index=1;	bool	inquotes=false;	while (*ptr) {		// are we inside of quotes ?		if (*ptr=='\'') {			if (inquotes) {				inquotes=false;			} else {				inquotes=true;			}		}		// look for the bind var prefix or ? if not inside of quotes		if (!inquotes && (*ptr==prefix || *ptr=='?')) {			// look through the list of vars			for (int16_t i=0; i<inbindcount; i++) {				// if we find a match, perform the substitution				// and skip past the variable...				//				// for bind-by-name cases, we need to check				// after the variable for whitespace, a comma				// or a right parenthesis to make sure that we 				// don't make the following mistake:				//				// select :var1,:var15 from mytable				//				// :var1=3				// :var15=2				//				// correct:				//      select 3,2 from mytable				//				// mistake:				//      select 3,35 from mytable				if (					(*ptr=='?' && 					charstring::toInteger(						inbindvars[i].variable+1)==									index) 					||					(!charstring::compare(ptr,						inbindvars[i].variable,						inbindvars[i].variablesize) 					 		&&					(*(ptr+inbindvars[i].variablesize)==					 		' ' ||					*(ptr+inbindvars[i].variablesize)==							'	' ||					*(ptr+inbindvars[i].variablesize)==							'\n' ||					*(ptr+inbindvars[i].variablesize)==							')' ||					*(ptr+inbindvars[i].variablesize)==							',' ||					*(ptr+inbindvars[i].variablesize)==							(char)NULL)					)) {					performSubstitution(outputquery,i);					if (*ptr=='?') {						ptr++;					} else {						ptr=ptr+inbindvars[i].								variablesize;					}					index++;					break;				}			}		}		// write the input query to the output query		if (*ptr) {			outputquery->append(*ptr);			ptr++;		}	}	return outputquery;}void sqlrcursor_svr::performSubstitution(stringbuffer *buffer, int16_t index) {	if (inbindvars[index].type==STRING_BIND) {		buffer->append("'");		size_t	length=inbindvars[index].valuesize;		for (size_t ind=0; ind<length; ind++) {			char	ch=inbindvars[index].value.stringval[ind];			// escape \'s, quotes and NULL's			if (ch=='\'' || ch=='\\') {				buffer->append('\\');			} else if (ch=='\0') {				buffer->append("\\0");			}			buffer->append(ch);		}		buffer->append("'");	} else if (inbindvars[index].type==INTEGER_BIND) {		buffer->append(inbindvars[index].value.integerval);	} else if (inbindvars[index].type==DOUBLE_BIND) {		buffer->append(inbindvars[index].value.doubleval.value,				inbindvars[index].value.doubleval.precision,				inbindvars[index].value.doubleval.scale);	} else if (inbindvars[index].type==NULL_BIND) {		buffer->append("NULL");	}}

⌨️ 快捷键说明

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