Ejemplo n.º 1
0
/* ----------------
 *		index_rescan  - (re)start a scan of an index
 *
 * During a restart, the caller may specify a new set of scankeys and/or
 * orderbykeys; but the number of keys cannot differ from what index_beginscan
 * was told.  (Later we might relax that to "must not exceed", but currently
 * the index AMs tend to assume that scan->numberOfKeys is what to believe.)
 * To restart the scan without changing keys, pass NULL for the key arrays.
 * (Of course, keys *must* be passed on the first call, unless
 * scan->numberOfKeys is zero.)
 * ----------------
 */
void
index_rescan(IndexScanDesc scan,
			 ScanKey keys, int nkeys,
			 ScanKey orderbys, int norderbys)
{
	FmgrInfo   *procedure;

	SCAN_CHECKS;
	GET_SCAN_PROCEDURE(amrescan);

	Assert(nkeys == scan->numberOfKeys);
	Assert(norderbys == scan->numberOfOrderBys);

	/* Release any held pin on a heap page */
	if (BufferIsValid(scan->xs_cbuf))
	{
		ReleaseBuffer(scan->xs_cbuf);
		scan->xs_cbuf = InvalidBuffer;
	}

	scan->xs_continue_hot = false;

	scan->kill_prior_tuple = false;		/* for safety */

	FunctionCall5(procedure,
				  PointerGetDatum(scan),
				  PointerGetDatum(keys),
				  Int32GetDatum(nkeys),
				  PointerGetDatum(orderbys),
				  Int32GetDatum(norderbys));
}
Ejemplo n.º 2
0
/*
 *	Perform default encoding conversion using cached FmgrInfo. Since
 *	this function does not access database at all, it is safe to call
 *	outside transactions. Explicit setting client encoding required
 *	before calling this function. Otherwise no conversion is
 *	performed.
*/
static unsigned char *
perform_default_encoding_conversion(unsigned char *src, int len, bool is_client_to_server)
{
	unsigned char *result;
	int			src_encoding,
				dest_encoding;
	FmgrInfo   *flinfo;

	if (is_client_to_server)
	{
		src_encoding = ClientEncoding->encoding;
		dest_encoding = DatabaseEncoding->encoding;
		flinfo = ToServerConvProc;
	}
	else
	{
		src_encoding = DatabaseEncoding->encoding;
		dest_encoding = ClientEncoding->encoding;
		flinfo = ToClientConvProc;
	}

	if (flinfo == NULL)
		return src;

	result = palloc(len * 4 + 1);

	FunctionCall5(flinfo,
				  Int32GetDatum(src_encoding),
				  Int32GetDatum(dest_encoding),
				  CStringGetDatum(src),
				  CStringGetDatum(result),
				  Int32GetDatum(len));
	return result;
}
Ejemplo n.º 3
0
/*
 *	Perform default encoding conversion using cached FmgrInfo. Since
 *	this function does not access database at all, it is safe to call
 *	outside transactions. Explicit setting client encoding required
 *	before calling this function. Otherwise no conversion is
 *	performed.
 *
 *  NOTE: this function was slightly updated to allow passing in a source
 *  encoding that is not necessarily ClientEncoding->encoding for client-to-
 *  server conversion. Default value is -1, which means: use ClientEncoding.
 *  See pg_custom_client_to_server for information.
 */
static char *
perform_default_encoding_conversion(const char *src, int len, bool is_client_to_server, 
									int custom_client_encoding, 
									FmgrInfo *custom_encoding_proc)
{
	char	   *result;
	int			src_encoding,
				dest_encoding;
	FmgrInfo   *flinfo;

	if (is_client_to_server)
	{
		if(custom_client_encoding == -1)
		{
			/* this is the normal path of execution */
			src_encoding = ClientEncoding->encoding;
			dest_encoding = DatabaseEncoding->encoding;
			flinfo = ToServerConvProc;			
		}
		else
		{
			/* this is the custom path of execution, for external tbl encodings */
			src_encoding = custom_client_encoding;
			dest_encoding = DatabaseEncoding->encoding;
			flinfo = custom_encoding_proc;
		}
	}
	else
	{
		if(custom_client_encoding == -1)
		{
			/* this is the normal path of execution */
			src_encoding = DatabaseEncoding->encoding;
			dest_encoding = ClientEncoding->encoding;
			flinfo = ToClientConvProc;			
		}
		else
		{
			/* this is the custom path of execution, for external tbl encodings */
			src_encoding = DatabaseEncoding->encoding;
			dest_encoding = custom_client_encoding;
			flinfo = custom_encoding_proc;
		}
	}

	if (flinfo == NULL)
		return (char *) src;

	/*
	 * Allocate space for conversion result, being wary of integer overflow
	 */
	if ((Size) len >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
		ereport(ERROR,
				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
				 errmsg("out of memory"),
		 errdetail("String of %d bytes is too long for encoding conversion.",
				   len)));

	result = palloc(len * MAX_CONVERSION_GROWTH + 1);

	FunctionCall5(flinfo,
				  Int32GetDatum(src_encoding),
				  Int32GetDatum(dest_encoding),
				  CStringGetDatum((char *) src),
				  CStringGetDatum(result),
				  Int32GetDatum(len));
		
	return result;
}