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

📄 execute.c

📁 postgresql8.3.4源码,开源数据库
💻 C
📖 第 1 页 / 共 4 页
字号:
		/* filling the array of (char*)s */		char	  **current_string = (char **) var->value;		/* storing the data (after the last array element) */		char	   *current_data_location = (char *) &current_string[ntuples + 1];		for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)		{			int			len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;			if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,							 var->type, var->ind_type, current_data_location,							   var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))				status = false;			else			{				*current_string = current_data_location;				current_data_location += len;				current_string++;			}		}		/* terminate the list */		*current_string = NULL;	}	else	{		for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)		{			if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,							   var->type, var->ind_type, var->value,							   var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))				status = false;		}	}	return status;}boolecpg_store_input(const int lineno, const bool force_indicator, const struct variable * var,				 char **tobeinserted_p, bool quote){	char	   *mallocedval = NULL;	char	   *newcopy = NULL;	/*	 * arrays are not possible unless the attribute is an array too FIXME: we	 * do not know if the attribute is an array here	 */#if 0	if (var->arrsize > 1 &&...)	{		ecpg_raise(lineno, ECPG_ARRAY_INSERT, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);		return false;	}#endif	/*	 * Some special treatment is needed for records since we want their	 * contents to arrive in a comma-separated list on insert (I think).	 */	*tobeinserted_p = "";	/* check for null value and set input buffer accordingly */	switch (var->ind_type)	{		case ECPGt_short:		case ECPGt_unsigned_short:			if (*(short *) var->ind_value < 0)				*tobeinserted_p = NULL;			break;		case ECPGt_int:		case ECPGt_unsigned_int:			if (*(int *) var->ind_value < 0)				*tobeinserted_p = NULL;			break;		case ECPGt_long:		case ECPGt_unsigned_long:			if (*(long *) var->ind_value < 0L)				*tobeinserted_p = NULL;			break;#ifdef HAVE_LONG_LONG_INT_64		case ECPGt_long_long:		case ECPGt_unsigned_long_long:			if (*(long long int *) var->ind_value < (long long) 0)				*tobeinserted_p = NULL;			break;#endif   /* HAVE_LONG_LONG_INT_64 */		case ECPGt_NO_INDICATOR:			if (force_indicator == false)			{				if (ECPGis_noind_null(var->type, var->value))					*tobeinserted_p = NULL;			}			break;		default:			break;	}	if (*tobeinserted_p != NULL)	{		int			asize = var->arrsize ? var->arrsize : 1;		switch (var->type)		{				int			element;			case ECPGt_short:				if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%hd", *((short *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_int:				if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "{");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "}");				}				else					sprintf(mallocedval, "%d", *((int *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_unsigned_short:				if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%hu", *((unsigned short *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_unsigned_int:				if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%u", *((unsigned int *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_long:				if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%ld", *((long *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_unsigned_long:				if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%lu", *((unsigned long *) var->value));				*tobeinserted_p = mallocedval;				break;#ifdef HAVE_LONG_LONG_INT_64			case ECPGt_long_long:				if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%lld", *((long long *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_unsigned_long_long:				if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%llu", *((unsigned long long *) var->value));				*tobeinserted_p = mallocedval;				break;#endif   /* HAVE_LONG_LONG_INT_64 */			case ECPGt_float:				if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%.14g", *((float *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_double:				if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))					return false;				if (asize > 1)				{					strcpy(mallocedval, "array [");					for (element = 0; element < asize; element++)						sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else					sprintf(mallocedval, "%.14g", *((double *) var->value));				*tobeinserted_p = mallocedval;				break;			case ECPGt_bool:				if (!(mallocedval = ecpg_alloc(var->arrsize + sizeof("array []"), lineno)))					return false;				if (var->arrsize > 1)				{					strcpy(mallocedval, "array [");					if (var->offset == sizeof(char))						for (element = 0; element < var->arrsize; element++)							sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');					/*					 * this is necessary since sizeof(C++'s bool)==sizeof(int)					 */					else if (var->offset == sizeof(int))						for (element = 0; element < var->arrsize; element++)							sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');					else						ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");					strcpy(mallocedval + strlen(mallocedval) - 1, "]");				}				else				{					if (var->offset == sizeof(char))						sprintf(mallocedval, "%c", (*((char *) var->value)) ? 't' : 'f');					else if (var->offset == sizeof(int))						sprintf(mallocedval, "%c", (*((int *) var->value)) ? 't' : 'f');					else						ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");				}				*tobeinserted_p = mallocedval;				break;			case ECPGt_char:			case ECPGt_unsigned_char:				{					/* set slen to string length if type is char * */					int			slen = (var->varcharsize == 0) ? strlen((char *) var->value) : var->varcharsize;					if (!(newcopy = ecpg_alloc(slen + 1, lineno)))						return false;					strncpy(newcopy, (char *) var->value, slen);					newcopy[slen] = '\0';					mallocedval = quote_postgres(newcopy, quote, lineno);					if (!mallocedval)						return false;					*tobeinserted_p = mallocedval;				}				break;			case ECPGt_const:			case ECPGt_char_variable:				{					int			slen = strlen((char *) var->value);					if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))						return false;					strncpy(mallocedval, (char *) var->value, slen);					mallocedval[slen] = '\0';					*tobeinserted_p = mallocedval;				}				break;			case ECPGt_varchar:				{					struct ECPGgeneric_varchar *variable =					(struct ECPGgeneric_varchar *) (var->value);					if (!(newcopy = (char *) ecpg_alloc(variable->len + 1, lineno)))						return false;					strncpy(newcopy, variable->arr, variable->len);					newcopy[variable->len] = '\0';					mallocedval = quote_postgres(newcopy, quote, lineno);					if (!mallocedval)						return false;					*tobeinserted_p = mallocedval;				}				break;			case ECPGt_decimal:			case ECPGt_numeric:				{					char	   *str = NULL;					int			slen;					numeric    *nval;					if (var->arrsize > 1)					{						for (element = 0; element < var->arrsize; element++)						{							nval = PGTYPESnumeric_new();							if (!nval)								return false;							if (var->type == ECPGt_numeric)								PGTYPESnumeric_copy((numeric *) ((var + var->offset * element)->value), nval);							else								PGTYPESnumeric_from_decimal((decimal *) ((var + var->offset * element)->value), nval);							str = PGTYPESnumeric_to_asc(nval, nval->dscale);							slen = strlen(str);							PGTYPESnumeric_free(nval);							if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [] "), lineno)))							{								ecpg_free(str);								return false;

⌨️ 快捷键说明

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