Exemplo n.º 1
0
Datum
_lt_q_regex(PG_FUNCTION_ARGS)
{
	ArrayType  *_tree = PG_GETARG_ARRAYTYPE_P(0);
	ArrayType  *_query = PG_GETARG_ARRAYTYPE_P(1);
	lquery	   *query = (lquery *) ARR_DATA_PTR(_query);
	bool		res = false;
	int			num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));

	if (ARR_NDIM(_query) > 1)
		ereport(ERROR,
				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
				 errmsg("array must be one-dimensional")));
	if (ARR_HASNULL(_query))
		ereport(ERROR,
				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
				 errmsg("array must not contain nulls")));

	while (num > 0)
	{
		if (array_iterator(_tree, ltq_regex, (void *) query, NULL))
		{
			res = true;
			break;
		}
		num--;
		query = (lquery *) NEXTVAL(query);
	}

	PG_FREE_IF_COPY(_tree, 0);
	PG_FREE_IF_COPY(_query, 1);
	PG_RETURN_BOOL(res);
}
Exemplo n.º 2
0
int main(void)
{
  int array[6] = {98, 402, 35, 42, 1024, 64};

  array_iterator(array, 6, &action);
  return (0);
}
Exemplo n.º 3
0
int32
array_all_int4gt(ArrayType *array, int4 value)
{
    return array_iterator((Oid) 23,	/* int4 */
			  (Oid) 147,	/* int4gt */
			  1,		/* logical and */
			  array, (Datum)value);
}
Exemplo n.º 4
0
int32
array_int4eq(ArrayType *array, int4 value)
{
    return array_iterator((Oid) 23,	/* int4 */
			  (Oid) 65,	/* int4eq */
			  0,		/* logical or */
			  array, (Datum)value);
}
Exemplo n.º 5
0
int32
array_all_char16regexeq(ArrayType *array, char* value)
{
    return array_iterator((Oid) 20,	/* char16 */
			  (Oid) 700,	/* char16regexeq */
			  1,		/* logical and */
			  array, (Datum)value);
}
Exemplo n.º 6
0
int32
array_char16eq(ArrayType *array, char* value)
{
    return array_iterator((Oid) 20,	/* char16 */
			  (Oid) 490,	/* char16eq */
			  0,		/* logical or */
			  array, (Datum)value);
}
Exemplo n.º 7
0
int32
array_all_textregexeq(ArrayType *array, char* value)
{
    return array_iterator((Oid) 25,	/* text */
			  (Oid) 81,	/* textregexeq */
			  1,		/* logical and */
			  array, (Datum)value);
}
Exemplo n.º 8
0
int32
array_texteq(ArrayType *array, char* value)
{
    return array_iterator((Oid) 25,	/* text */
			  (Oid) 67,	/* texteq */
			  0,		/* logical or */
			  array, (Datum)value);
}
Exemplo n.º 9
0
Datum
_ltree_risparent(PG_FUNCTION_ARGS)
{
	ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
	ltree	   *query = PG_GETARG_LTREE(1);
	bool		res = array_iterator(la, ltree_risparent, (void *) query, NULL);

	PG_FREE_IF_COPY(la, 0);
	PG_FREE_IF_COPY(query, 1);
	PG_RETURN_BOOL(res);
}
Exemplo n.º 10
0
Datum
_ltxtq_exec(PG_FUNCTION_ARGS)
{
	ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
	ltxtquery  *query = PG_GETARG_LTXTQUERY(1);
	bool		res = array_iterator(la, ltxtq_exec, (void *) query, NULL);

	PG_FREE_IF_COPY(la, 0);
	PG_FREE_IF_COPY(query, 1);
	PG_RETURN_BOOL(res);
}
Exemplo n.º 11
0
Datum
_ltxtq_extract_exec(PG_FUNCTION_ARGS)
{
	ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
	ltxtquery  *query = PG_GETARG_LTXTQUERY(1);
	ltree	   *found,
			   *item;

	if (!array_iterator(la, ltxtq_exec, (void *) query, &found))
	{
		PG_FREE_IF_COPY(la, 0);
		PG_FREE_IF_COPY(query, 1);
		PG_RETURN_NULL();
	}

	item = (ltree *) palloc(VARSIZE(found));
	memcpy(item, found, VARSIZE(found));

	PG_FREE_IF_COPY(la, 0);
	PG_FREE_IF_COPY(query, 1);
	PG_RETURN_POINTER(item);
}
void array_iterator(int *arr, int n, void (*func)(int)) {
  if (n) {
    func(*arr);
    array_iterator(++arr, --n, func);
  }
}