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

📄 bind.c

📁 postgresql-odbc,跨平台应用
💻 C
📖 第 1 页 / 共 2 页
字号:
		self->parameters = new_bindings;		self->allocated = num_params;	}	mylog("exit %s=%p\n", func, self->parameters);}voidextend_iparameter_bindings(IPDFields *self, int num_params){	CSTR func = "extend_iparameter_bindings";	ParameterImplClass *new_bindings;	mylog("%s: entering ... self=%p, parameters_allocated=%d, num_params=%d\n", func, self, self->allocated, num_params);	/*	 * if we have too few, allocate room for more, and copy the old	 * entries into the new structure	 */	if (self->allocated < num_params)	{		new_bindings = (ParameterImplClass *) realloc(self->parameters, sizeof(ParameterImplClass) * num_params);		if (!new_bindings)		{			mylog("%s: unable to create %d new bindings from %d old bindings\n", func, num_params, self->allocated);			self->parameters = NULL;			self->allocated = 0;			return;		}		memset(&new_bindings[self->allocated], 0,			sizeof(ParameterImplClass) * (num_params - self->allocated));		self->parameters = new_bindings;		self->allocated = num_params;	}	mylog("exit %s=%p\n", func, self->parameters);}voidreset_a_parameter_binding(APDFields *self, int ipar){	CSTR func = "reset_a_parameter_binding";	mylog("%s: entering ... self=%p, parameters_allocated=%d, ipar=%d\n", func, self, self->allocated, ipar);	if (ipar < 1 || ipar > self->allocated)		return;	ipar--;	self->parameters[ipar].buflen = 0;	self->parameters[ipar].buffer = NULL;	self->parameters[ipar].used =	self->parameters[ipar].indicator = NULL;	self->parameters[ipar].CType = 0;	self->parameters[ipar].data_at_exec = FALSE;	self->parameters[ipar].precision = 0;	self->parameters[ipar].scale = 0;}voidreset_a_iparameter_binding(IPDFields *self, int ipar){	CSTR func = "reset_a_iparameter_binding";	mylog("%s: entering ... self=%p, parameters_allocated=%d, ipar=%d\n", func, self, self->allocated, ipar);	if (ipar < 1 || ipar > self->allocated)		return;	ipar--;	NULL_THE_NAME(self->parameters[ipar].paramName);	self->parameters[ipar].paramType = 0;	self->parameters[ipar].SQLType = 0;	self->parameters[ipar].column_size = 0;	self->parameters[ipar].decimal_digits = 0;	self->parameters[ipar].precision = 0;	self->parameters[ipar].scale = 0;	self->parameters[ipar].PGType = 0;}intCountParameters(const StatementClass *self, Int2 *inputCount, Int2 *ioCount, Int2 *outputCount){	CSTR func = "CountParameters";	IPDFields	*ipdopts = SC_get_IPDF(self);	int	i, num_params, valid_count;	if (inputCount)		*inputCount = 0;	if (ioCount)		*ioCount = 0;	if (outputCount)		*outputCount = 0;	if (!ipdopts)	return -1;	num_params = self->num_params;	if (ipdopts->allocated < num_params)		num_params = ipdopts->allocated;	for (i = 0, valid_count = 0; i < num_params; i++)	{		if (SQL_PARAM_OUTPUT == ipdopts->parameters[i].paramType)		{			if (outputCount)			{				(*outputCount)++;				valid_count++;			}		}		else if (SQL_PARAM_INPUT_OUTPUT == ipdopts->parameters[i].paramType)		{			if (ioCount)			{				(*ioCount)++;				valid_count++;			}		}		else if (inputCount)		{			 (*inputCount)++;			valid_count++;		}	}	return valid_count;}/* *	Free parameters and free the memory. */voidAPD_free_params(APDFields *apdopts, char option){	CSTR	func = "APD_free_params";	mylog("%s:  ENTER, self=%p\n", func, apdopts);	if (!apdopts->parameters)		return;	if (option == STMT_FREE_PARAMS_ALL)	{		free(apdopts->parameters);		apdopts->parameters = NULL;		apdopts->allocated = 0;	}	mylog("%s:  EXIT\n", func);}voidPDATA_free_params(PutDataInfo *pdata, char option){	CSTR	func = "PDATA_free_params";	int			i;	mylog("%s:  ENTER, self=%p\n", func, pdata);	if (!pdata->pdata)		return;	for (i = 0; i < pdata->allocated; i++)	{		if (pdata->pdata[i].EXEC_used)		{			free(pdata->pdata[i].EXEC_used);			pdata->pdata[i].EXEC_used = NULL;		}		if (pdata->pdata[i].EXEC_buffer)		{			free(pdata->pdata[i].EXEC_buffer);			pdata->pdata[i].EXEC_buffer = NULL;		}	}	if (option == STMT_FREE_PARAMS_ALL)	{		free(pdata->pdata);		pdata->pdata = NULL;		pdata->allocated = 0;	}	mylog("%s:  EXIT\n", func);}/* *	Free parameters and free the memory. */voidIPD_free_params(IPDFields *ipdopts, char option){	CSTR	func = "IPD_free_params";	mylog("%s:  ENTER, self=%p\n", func, ipdopts);	if (!ipdopts->parameters)		return;	if (option == STMT_FREE_PARAMS_ALL)	{		free(ipdopts->parameters);		ipdopts->parameters = NULL;		ipdopts->allocated = 0;	}	mylog("%s:  EXIT\n", func);}voidextend_column_bindings(ARDFields *self, int num_columns){	CSTR func = "extend_column_bindings";	BindInfoClass *new_bindings;	int			i;	mylog("%s: entering ... self=%p, bindings_allocated=%d, num_columns=%d\n", func, self, self->allocated, num_columns);	/*	 * if we have too few, allocate room for more, and copy the old	 * entries into the new structure	 */	if (self->allocated < num_columns)	{		new_bindings = create_empty_bindings(num_columns);		if (!new_bindings)		{			mylog("%s: unable to create %d new bindings from %d old bindings\n", func, num_columns, self->allocated);			if (self->bindings)			{				free(self->bindings);				self->bindings = NULL;			}			self->allocated = 0;			return;		}		if (self->bindings)		{			for (i = 0; i < self->allocated; i++)				new_bindings[i] = self->bindings[i];			free(self->bindings);		}		self->bindings = new_bindings;		self->allocated = num_columns;	}	/*	 * There is no reason to zero out extra bindings if there are more	 * than needed.  If an app has allocated extra bindings, let it worry	 * about it by unbinding those columns.	 */	/* SQLBindCol(1..) ... SQLBindCol(10...)   # got 10 bindings */	/* SQLExecDirect(...)  # returns 5 cols */	/* SQLExecDirect(...)  # returns 10 cols  (now OK) */	mylog("exit %s=%p\n", func, self->bindings);}voidreset_a_column_binding(ARDFields *self, int icol){	CSTR func = "reset_a_column_binding";	BindInfoClass	*bookmark;	mylog("%s: entering ... self=%p, bindings_allocated=%d, icol=%d\n", func, self, self->allocated, icol);	if (icol > self->allocated)		return;	/* use zero based col numbers from here out */	if (0 == icol)	{		if (bookmark = self->bookmark, bookmark != NULL)		{			bookmark->buffer = NULL;			bookmark->used =			bookmark->indicator = NULL;		}	}	else	{		icol--;		/* we have to unbind the column */		self->bindings[icol].buflen = 0;		self->bindings[icol].buffer = NULL;		self->bindings[icol].used =		self->bindings[icol].indicator = NULL;		self->bindings[icol].returntype = SQL_C_CHAR;	}}void	ARD_unbind_cols(ARDFields *self, BOOL freeall){	Int2	lf;inolog("ARD_unbind_cols freeall=%d allocated=%d bindings=%p", freeall, self->allocated, self->bindings);	for (lf = 1; lf <= self->allocated; lf++)		reset_a_column_binding(self, lf);	if (freeall)	{		if (self->bindings)			free(self->bindings);		self->bindings = NULL;		self->allocated = 0;	}}void	GDATA_unbind_cols(GetDataInfo *self, BOOL freeall){	Int2	lf;inolog("GDATA_unbind_cols freeall=%d allocated=%d gdata=%p", freeall, self->allocated, self->gdata);	if (self->fdata.ttlbuf)	{		free(self->fdata.ttlbuf);		self->fdata.ttlbuf = NULL;	}	self->fdata.ttlbuflen = self->fdata.ttlbufused = 0;	self->fdata.data_left = -1;	for (lf = 1; lf <= self->allocated; lf++)		reset_a_getdata_info(self, lf);	if (freeall)	{		if (self->gdata)			free(self->gdata);		self->gdata = NULL;		self->allocated = 0;	}}void GetDataInfoInitialize(GetDataInfo *gdata_info){	gdata_info->fdata.data_left = -1;	gdata_info->fdata.ttlbuf = NULL;	gdata_info->fdata.ttlbuflen = gdata_info->fdata.ttlbufused = 0;	gdata_info->allocated = 0;	gdata_info->gdata = NULL;}static GetDataClass *create_empty_gdata(int num_columns){	GetDataClass	*new_gdata;	int			i;	new_gdata = (GetDataClass *) malloc(num_columns * sizeof(GetDataClass));	if (!new_gdata)		return NULL;	for (i = 0; i < num_columns; i++)	{		new_gdata[i].data_left = -1;		new_gdata[i].ttlbuf = NULL;		new_gdata[i].ttlbuflen = 0;		new_gdata[i].ttlbufused = 0;	}	return new_gdata;}voidextend_getdata_info(GetDataInfo *self, int num_columns, BOOL shrink){	CSTR func = "extend_getdata_info";	GetDataClass	*new_gdata;	mylog("%s: entering ... self=%p, gdata_allocated=%d, num_columns=%d\n", func, self, self->allocated, num_columns);	/*	 * if we have too few, allocate room for more, and copy the old	 * entries into the new structure	 */	if (self->allocated < num_columns)	{		new_gdata = create_empty_gdata(num_columns);		if (!new_gdata)		{			mylog("%s: unable to create %d new gdata from %d old gdata\n", func, num_columns, self->allocated);			if (self->gdata)			{				free(self->gdata);				self->gdata = NULL;			}			self->allocated = 0;			return;		}		if (self->gdata)		{			size_t	i;			for (i = 0; i < self->allocated; i++)				new_gdata[i] = self->gdata[i];			free(self->gdata);		}		self->gdata = new_gdata;		self->allocated = num_columns;	}	else if (shrink && self->allocated > num_columns)	{		int	i;		for (i = self->allocated; i > num_columns; i--)			reset_a_getdata_info(self, i);		self->allocated = num_columns;		if (0 == num_columns)		{			free(self->gdata);			self->gdata = NULL;		}	} 	/*	 * There is no reason to zero out extra gdata if there are more	 * than needed.  If an app has allocated extra gdata, let it worry	 * about it by unbinding those columns.	 */	mylog("exit extend_gdata_info=%p\n", self->gdata);}void	reset_a_getdata_info(GetDataInfo *gdata_info, int icol){	if (icol < 1 || icol > gdata_info->allocated)		return;	icol--;	if (gdata_info->gdata[icol].ttlbuf)	{		free(gdata_info->gdata[icol].ttlbuf);		gdata_info->gdata[icol].ttlbuf = NULL;	}	gdata_info->gdata[icol].ttlbuflen =	gdata_info->gdata[icol].ttlbufused = 0;	gdata_info->gdata[icol].data_left = -1;}void PutDataInfoInitialize(PutDataInfo *pdata_info){	pdata_info->allocated = 0;	pdata_info->pdata = NULL;}voidextend_putdata_info(PutDataInfo *self, int num_params, BOOL shrink){	CSTR func = "extend_putdata_info";	PutDataClass	*new_pdata;	mylog("%s: entering ... self=%p, parameters_allocated=%d, num_params=%d\n", func, self, self->allocated, num_params);	/*	 * if we have too few, allocate room for more, and copy the old	 * entries into the new structure	 */	if (self->allocated < num_params)	{		if (self->allocated <= 0 && self->pdata)		{			mylog("??? pdata is not null while allocated == 0\n");			self->pdata = NULL; 		}		new_pdata = (PutDataClass *) realloc(self->pdata, sizeof(PutDataClass) * num_params);		if (!new_pdata)		{			mylog("%s: unable to create %d new pdata from %d old pdata\n", func, num_params, self->allocated);			self->pdata = NULL;			self->allocated = 0;			return;		}		memset(&new_pdata[self->allocated], 0,			sizeof(PutDataClass) * (num_params - self->allocated));		self->pdata = new_pdata;		self->allocated = num_params;	}	else if (shrink && self->allocated > num_params)	{		int	i;		for (i = self->allocated; i > num_params; i--)			reset_a_putdata_info(self, i);		self->allocated = num_params;		if (0 == num_params)		{			free(self->pdata);			self->pdata = NULL;		}	}	mylog("exit %s=%p\n", func, self->pdata);}void	reset_a_putdata_info(PutDataInfo *pdata_info, int ipar){	if (ipar < 1 || ipar > pdata_info->allocated)		return;	ipar--;	if (pdata_info->pdata[ipar].EXEC_used)	{		free(pdata_info->pdata[ipar].EXEC_used);		pdata_info->pdata[ipar].EXEC_used = NULL;	}	if (pdata_info->pdata[ipar].EXEC_buffer)	{		free(pdata_info->pdata[ipar].EXEC_buffer);		pdata_info->pdata[ipar].EXEC_buffer = NULL;	}	pdata_info->pdata[ipar].lobj_oid = 0;}void SC_param_next(const StatementClass *stmt, int *param_number, ParameterInfoClass **apara, ParameterImplClass **ipara){	int	next;	IPDFields	*ipdopts = SC_get_IPDF(stmt);	if (*param_number < 0)		next = stmt->proc_return;	else		next = *param_number + 1;	if (stmt->discard_output_params)	{		for (;next < ipdopts->allocated && SQL_PARAM_OUTPUT == ipdopts->parameters[next].paramType; next++) ;	}	*param_number = next;	if (ipara)	{		if (next < ipdopts->allocated)			*ipara = ipdopts->parameters + next;		else			*ipara = NULL;	}	if (apara)	{		APDFields	*apdopts = SC_get_APDF(stmt);		if (next < apdopts->allocated)			*apara = apdopts->parameters + next;		else			*apara = NULL;	}}

⌨️ 快捷键说明

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