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

📄 data.c

📁 postgresql8.3.4源码,开源数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
								*((char *) (var + offset * act_tuple)) = true;							else if (offset == sizeof(int))								*((int *) (var + offset * act_tuple)) = true;							else								ecpg_raise(lineno, ECPG_CONVERT_BOOL,										   ECPG_SQLSTATE_DATATYPE_MISMATCH,										   "different size");							break;						}						else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))						{							/* NULL is valid */							break;						}					}					ecpg_raise(lineno, ECPG_CONVERT_BOOL,							   ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);					return (false);					break;				case ECPGt_char:				case ECPGt_unsigned_char:					if (pval)					{						if (varcharsize == 0 || varcharsize > size)							strncpy((char *) ((long) var + offset * act_tuple), pval, size + 1);						else						{							strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);							if (varcharsize < size)							{								/* truncation */								switch (ind_type)								{									case ECPGt_short:									case ECPGt_unsigned_short:										*((short *) (ind + ind_offset * act_tuple)) = size;										break;									case ECPGt_int:									case ECPGt_unsigned_int:										*((int *) (ind + ind_offset * act_tuple)) = size;										break;									case ECPGt_long:									case ECPGt_unsigned_long:										*((long *) (ind + ind_offset * act_tuple)) = size;										break;#ifdef HAVE_LONG_LONG_INT_64									case ECPGt_long_long:									case ECPGt_unsigned_long_long:										*((long long int *) (ind + ind_offset * act_tuple)) = size;										break;#endif   /* HAVE_LONG_LONG_INT_64 */									default:										break;								}								sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';							}						}						pval += size;					}					break;				case ECPGt_varchar:					if (pval)					{						struct ECPGgeneric_varchar *variable =						(struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);						variable->len = size;						if (varcharsize == 0)							strncpy(variable->arr, pval, variable->len);						else						{							strncpy(variable->arr, pval, varcharsize);							if (variable->len > varcharsize)							{								/* truncation */								switch (ind_type)								{									case ECPGt_short:									case ECPGt_unsigned_short:										*((short *) (ind + offset * act_tuple)) = variable->len;										break;									case ECPGt_int:									case ECPGt_unsigned_int:										*((int *) (ind + offset * act_tuple)) = variable->len;										break;									case ECPGt_long:									case ECPGt_unsigned_long:										*((long *) (ind + offset * act_tuple)) = variable->len;										break;#ifdef HAVE_LONG_LONG_INT_64									case ECPGt_long_long:									case ECPGt_unsigned_long_long:										*((long long int *) (ind + ind_offset * act_tuple)) = variable->len;										break;#endif   /* HAVE_LONG_LONG_INT_64 */									default:										break;								}								sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';								variable->len = varcharsize;							}						}						pval += size;					}					break;				case ECPGt_decimal:				case ECPGt_numeric:					if (pval)					{						if (isarray && *pval == '"')							nres = PGTYPESnumeric_from_asc(pval + 1, &scan_length);						else							nres = PGTYPESnumeric_from_asc(pval, &scan_length);						/* did we get an error? */						if (nres == NULL)						{							ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",									 lineno, pval ? pval : "", errno);							if (INFORMIX_MODE(compat))							{								/*								 * Informix wants its own NULL value here								 * instead of an error								 */								nres = PGTYPESnumeric_new();								if (nres)									ECPGset_noind_null(ECPGt_numeric, nres);								else								{									ecpg_raise(lineno, ECPG_OUT_OF_MEMORY,									 ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);									return (false);								}							}							else							{								ecpg_raise(lineno, ECPG_NUMERIC_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						else						{							if (isarray && *scan_length == '"')								scan_length++;							if (garbage_left(isarray, scan_length, compat))							{								free(nres);								ecpg_raise(lineno, ECPG_NUMERIC_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						pval = scan_length;					}					else						nres = PGTYPESnumeric_from_asc("0.0", &scan_length);					if (type == ECPGt_numeric)						PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));					else						PGTYPESnumeric_to_decimal(nres, (decimal *) (var + offset * act_tuple));					free(nres);					break;				case ECPGt_interval:					if (pval)					{						if (isarray && *pval == '"')							ires = PGTYPESinterval_from_asc(pval + 1, &scan_length);						else							ires = PGTYPESinterval_from_asc(pval, &scan_length);						/* did we get an error? */						if (ires == NULL)						{							ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",									 lineno, pval ? pval : "", errno);							if (INFORMIX_MODE(compat))							{								/*								 * Informix wants its own NULL value here								 * instead of an error								 */								ires = (interval *) ecpg_alloc(sizeof(interval), lineno);								if (!ires)									return (false);								ECPGset_noind_null(ECPGt_interval, ires);							}							else							{								ecpg_raise(lineno, ECPG_INTERVAL_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						else						{							if (isarray && *scan_length == '"')								scan_length++;							if (garbage_left(isarray, scan_length, compat))							{								free(ires);								ecpg_raise(lineno, ECPG_INTERVAL_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						pval = scan_length;					}					else						ires = PGTYPESinterval_from_asc("0 seconds", NULL);					PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));					free(ires);					break;				case ECPGt_date:					if (pval)					{						if (isarray && *pval == '"')							ddres = PGTYPESdate_from_asc(pval + 1, &scan_length);						else							ddres = PGTYPESdate_from_asc(pval, &scan_length);						/* did we get an error? */						if (errno != 0)						{							ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",									 lineno, pval ? pval : "", errno);							if (INFORMIX_MODE(compat))							{								/*								 * Informix wants its own NULL value here								 * instead of an error								 */								ECPGset_noind_null(ECPGt_date, &ddres);							}							else							{								ecpg_raise(lineno, ECPG_DATE_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						else						{							if (isarray && *scan_length == '"')								scan_length++;							if (garbage_left(isarray, scan_length, compat))							{								ecpg_raise(lineno, ECPG_DATE_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						*((date *) (var + offset * act_tuple)) = ddres;						pval = scan_length;					}					break;				case ECPGt_timestamp:					if (pval)					{						if (isarray && *pval == '"')							tres = PGTYPEStimestamp_from_asc(pval + 1, &scan_length);						else							tres = PGTYPEStimestamp_from_asc(pval, &scan_length);						/* did we get an error? */						if (errno != 0)						{							ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",									 lineno, pval ? pval : "", errno);							if (INFORMIX_MODE(compat))							{								/*								 * Informix wants its own NULL value here								 * instead of an error								 */								ECPGset_noind_null(ECPGt_timestamp, &tres);							}							else							{								ecpg_raise(lineno, ECPG_TIMESTAMP_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						else						{							if (isarray && *scan_length == '"')								scan_length++;							if (garbage_left(isarray, scan_length, compat))							{								ecpg_raise(lineno, ECPG_TIMESTAMP_FORMAT,									  ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);								return (false);							}						}						*((timestamp *) (var + offset * act_tuple)) = tres;						pval = scan_length;					}					break;				default:					ecpg_raise(lineno, ECPG_UNSUPPORTED,							   ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,							   ecpg_type_name(type));					return (false);					break;			}			if (isarray == ECPG_ARRAY_ARRAY)			{				bool		string = false;				/* set array to next entry */				++act_tuple;				/* set pval to the next entry */				for (; string || (*pval != ',' && *pval != '}' && *pval != '\0'); ++pval)					if (*pval == '"')						string = string ? false : true;				if (*pval == ',')					++pval;			}			else if (isarray == ECPG_ARRAY_VECTOR)			{				bool		string = false;				/* set array to next entry */				++act_tuple;				/* set pval to the next entry */				for (; string || (*pval != ' ' && *pval != '\0'); ++pval)					if (*pval == '"')						string = string ? false : true;				if (*pval == ' ')					++pval;			}		}	} while (*pval != '\0' && ((isarray == ECPG_ARRAY_ARRAY && *pval != '}') || isarray == ECPG_ARRAY_VECTOR));	return (true);}

⌨️ 快捷键说明

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