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

📄 execute.c

📁 postgresql8.3.4源码,开源数据库
💻 C
📖 第 1 页 / 共 4 页
字号:
							}							if (!element)								strcpy(mallocedval, "array [");							strncpy(mallocedval + strlen(mallocedval), str, slen + 1);							strcpy(mallocedval + strlen(mallocedval), ",");							ecpg_free(str);						}						strcpy(mallocedval + strlen(mallocedval) - 1, "]");					}					else					{						nval = PGTYPESnumeric_new();						if (!nval)							return false;						if (var->type == ECPGt_numeric)							PGTYPESnumeric_copy((numeric *) (var->value), nval);						else							PGTYPESnumeric_from_decimal((decimal *) (var->value), nval);						str = PGTYPESnumeric_to_asc(nval, nval->dscale);						slen = strlen(str);						PGTYPESnumeric_free(nval);						if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))						{							free(str);							return false;						}						strncpy(mallocedval, str, slen);						mallocedval[slen] = '\0';						ecpg_free(str);					}					*tobeinserted_p = mallocedval;				}				break;			case ECPGt_interval:				{					char	   *str = NULL;					int			slen;					if (var->arrsize > 1)					{						for (element = 0; element < var->arrsize; element++)						{							str = quote_postgres(PGTYPESinterval_to_asc((interval *) ((var + var->offset * element)->value)), quote, lineno);							if (!str)								return false;							slen = strlen(str);							if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), lineno)))							{								ecpg_free(str);								return false;							}							if (!element)								strcpy(mallocedval, "array [");							strncpy(mallocedval + strlen(mallocedval), str, slen + 1);							strcpy(mallocedval + strlen(mallocedval), ",");							ecpg_free(str);						}						strcpy(mallocedval + strlen(mallocedval) - 1, "]");					}					else					{						str = quote_postgres(PGTYPESinterval_to_asc((interval *) (var->value)), quote, lineno);						if (!str)							return false;						slen = strlen(str);						if (!(mallocedval = ecpg_alloc(slen + sizeof("interval ") + 1, lineno)))						{							ecpg_free(str);							return false;						}						/* also copy trailing '\0' */						strncpy(mallocedval + strlen(mallocedval), str, slen + 1);						ecpg_free(str);					}					*tobeinserted_p = mallocedval;				}				break;			case ECPGt_date:				{					char	   *str = NULL;					int			slen;					if (var->arrsize > 1)					{						for (element = 0; element < var->arrsize; element++)						{							str = quote_postgres(PGTYPESdate_to_asc(*(date *) ((var + var->offset * element)->value)), quote, lineno);							if (!str)								return false;							slen = strlen(str);							if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), lineno)))							{								ecpg_free(str);								return false;							}							if (!element)								strcpy(mallocedval, "array [");							strncpy(mallocedval + strlen(mallocedval), str, slen + 1);							strcpy(mallocedval + strlen(mallocedval), ",");							ecpg_free(str);						}						strcpy(mallocedval + strlen(mallocedval) - 1, "]");					}					else					{						str = quote_postgres(PGTYPESdate_to_asc(*(date *) (var->value)), quote, lineno);						if (!str)							return false;						slen = strlen(str);						if (!(mallocedval = ecpg_alloc(slen + sizeof("date ") + 1, lineno)))						{							ecpg_free(str);							return false;						}						/* also copy trailing '\0' */						strncpy(mallocedval + strlen(mallocedval), str, slen + 1);						ecpg_free(str);					}					*tobeinserted_p = mallocedval;				}				break;			case ECPGt_timestamp:				{					char	   *str = NULL;					int			slen;					if (var->arrsize > 1)					{						for (element = 0; element < var->arrsize; element++)						{							str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), quote, lineno);							if (!str)								return false;							slen = strlen(str);							if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), lineno)))							{								ecpg_free(str);								return false;							}							if (!element)								strcpy(mallocedval, "array [");							strncpy(mallocedval + strlen(mallocedval), str, slen + 1);							strcpy(mallocedval + strlen(mallocedval), ",");							ecpg_free(str);						}						strcpy(mallocedval + strlen(mallocedval) - 1, "]");					}					else					{						str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), quote, lineno);						if (!str)							return false;						slen = strlen(str);						if (!(mallocedval = ecpg_alloc(slen + sizeof("timestamp") + 1, lineno)))						{							ecpg_free(str);							return false;						}						/* also copy trailing '\0' */						strncpy(mallocedval + strlen(mallocedval), str, slen + 1);						ecpg_free(str);					}					*tobeinserted_p = mallocedval;				}				break;			case ECPGt_descriptor:				break;			default:				/* Not implemented yet */				ecpg_raise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (char *) ecpg_type_name(var->type));				return false;				break;		}	}	return true;}static voidfree_params(const char **paramValues, int nParams, bool print, int lineno){	int			n;	for (n = 0; n < nParams; n++)	{		if (print)			ecpg_log("free_params line %d: parameter %d = %s\n", lineno, n + 1, paramValues[n] ? paramValues[n] : "null");		ecpg_free((void *) (paramValues[n]));	}	ecpg_free(paramValues);}static boolinsert_tobeinserted(int position, int ph_len, struct statement * stmt, char *tobeinserted){	char	*newcopy;	if (!(newcopy = (char *) ecpg_alloc(strlen(stmt->command)										+ strlen(tobeinserted)										+ 1, stmt->lineno)))	{		ecpg_free(tobeinserted);		return false;	}	strcpy(newcopy, stmt->command);	strcpy(newcopy + position - 1, tobeinserted);	/*	 * The strange thing in the second argument is the rest of the	 * string from the old string	 */	strcat(newcopy,		   stmt->command		   + position		   + ph_len - 1);	ecpg_free(stmt->command);	stmt->command = newcopy;	ecpg_free((char *) tobeinserted);	return true;}static boolecpg_execute(struct statement * stmt){	bool		status = false;	char	   *cmdstat;	PGresult   *results;	PGnotify   *notify;	struct variable *var;	int			desc_counter = 0;	const char **paramValues = NULL;	int			nParams = 0;	int			position = 0;	struct sqlca_t *sqlca = ECPGget_sqlca();	bool		clear_result = true;	/*	 * If the type is one of the fill in types then we take the argument and	 * enter it to our parameter array at the first position. Then if there	 * are any more fill in types we add more parameters.	 */	var = stmt->inlist;	while (var)	{		char *tobeinserted;		int			counter = 1;		tobeinserted = NULL;		/*		 * A descriptor is a special case since it contains many variables but		 * is listed only once.		 */		if (var->type == ECPGt_descriptor)		{			/*			 * We create an additional variable list here, so the same logic			 * applies.			 */			struct variable desc_inlist;			struct descriptor *desc;			struct descriptor_item *desc_item;			desc = ecpg_find_desc(stmt->lineno, var->pointer);			if (desc == NULL)				return false;			desc_counter++;			for (desc_item = desc->items; desc_item; desc_item = desc_item->next)			{				if (desc_item->num == desc_counter)				{					desc_inlist.type = ECPGt_char;					desc_inlist.value = desc_item->data;					desc_inlist.pointer = &(desc_item->data);					desc_inlist.varcharsize = strlen(desc_item->data);					desc_inlist.arrsize = 1;					desc_inlist.offset = 0;					if (!desc_item->indicator)					{						desc_inlist.ind_type = ECPGt_NO_INDICATOR;						desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;						desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;					}					else					{						desc_inlist.ind_type = ECPGt_int;						desc_inlist.ind_value = &(desc_item->indicator);						desc_inlist.ind_pointer = &(desc_inlist.ind_value);						desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;						desc_inlist.ind_offset = 0;					}					if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))						return false;					break;				}			}			if (desc->count == desc_counter)				desc_counter = 0;		}		else		{			if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))				return false;		}		/*		 * now tobeinserted points to an area that contains the next parameter		 * now find the positin in the string where it belongs		 */		if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)		{			/*			 * We have an argument but we dont have the matched up			 * placeholder in the string			 */			ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,					ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,					   NULL);			free_params(paramValues, nParams, false, stmt->lineno);			return false;		}		/* 		 * if var->type=ECPGt_char_variable we have a dynamic cursor we have		 * to simulate a dynamic cursor because there is no backend		 * functionality for it		 */		if (var->type == ECPGt_char_variable)		{			int	ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");			if (!insert_tobeinserted(position, ph_len, stmt, tobeinserted))			{				free_params(paramValues, nParams, false, stmt->lineno);				return false;			}			tobeinserted = NULL;		}		/*		 * if the placeholder is '$0' we have to replace it on the client side		 * this is for places we want to support variables at that are not supported in the backend		 */		else if (stmt->command[position] == '0' ) 		{			if (!insert_tobeinserted(position, 2, stmt, tobeinserted))			{				free_params(paramValues, nParams, false, stmt->lineno);				return false;			}			tobeinserted = NULL;		}		else		{			nParams++;			if (!(paramValues = (const char **) ecpg_realloc(paramValues, sizeof(const char *) * nParams, stmt->lineno)))			{				ecpg_free(paramValues);				return false;			}			paramValues[nParams - 1] = tobeinserted;			/* let's see if this was an old style placeholder */			if (stmt->command[position] == '?')			{				/* yes, replace with new style */				int			buffersize = sizeof(int) * CHAR_BIT * 10 / 3;		/* a rough guess of the																				 * size we need */				if (!(tobeinserted = (char *) ecpg_alloc(buffersize, stmt->lineno)))				{					free_params(paramValues, nParams, false, stmt->lineno);					return false;				}				snprintf(tobeinserted, buffersize, "$%d", counter++);				if (!insert_tobeinserted(position, 2, stmt, tobeinserted))

⌨️ 快捷键说明

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