static BOOL tupleExists()

in results.c [2280:2312]


static BOOL	tupleExists(StatementClass *stmt, const KeySet *keyset)
{
	PQExpBufferData	selstr = {0};
	const TABLE_INFO	*ti = stmt->ti[0];
	QResultClass	*res;
	RETCODE		ret = FALSE;
	const char *bestqual = GET_NAME(ti->bestqual);
	char table_fqn[256];

	initPQExpBuffer(&selstr);
	printfPQExpBuffer(&selstr,
			 "select 1 from %s where ctid = '(%u,%u)'",
			 ti_quote(stmt, keyset->oid, table_fqn, sizeof(table_fqn)),
			 keyset->blocknum, keyset->offset);
	if (NULL != bestqual && 0 != keyset->oid && !TI_has_subclass(ti))
	{
		appendPQExpBuffer(&selstr, " and ");
		appendPQExpBuffer(&selstr, bestqual, keyset->oid);
	}
	if (PQExpBufferDataBroken(selstr))
	{
		SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Out of memory in tupleExists()", __FUNCTION__);
		goto cleanup;
	}
	res = CC_send_query(SC_get_conn(stmt), selstr.data, NULL, READ_ONLY_QUERY, NULL);
	if (QR_command_maybe_successful(res) && 1 == res->num_cached_rows)
		ret = TRUE;
	QR_Destructor(res);
cleanup:
	if (!PQExpBufferDataBroken(selstr))
		termPQExpBuffer(&selstr);
	return ret;
}