mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
i have made minor changes to array_iterator to make it work with
pgsql-6.3.2. I think array_iterator is a great thing to have!!! With best regards, Tobias Gabele
This commit is contained in:
@ -6,10 +6,9 @@
|
||||
* elements of the array and the value and compute a result as
|
||||
* the logical OR or AND of the iteration results.
|
||||
*
|
||||
* Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
|
||||
*
|
||||
* This file is distributed under the GNU General Public License
|
||||
* either version 2, or (at your option) any later version.
|
||||
* Copyright (c) 1997, Massimo Dal Zotto <dz@cs.unitn.it>
|
||||
* ported to postgreSQL 6.3.2,added oid_functions, 18.1.1999,
|
||||
* Tobias Gabele <gabele@wiz.uni-kassel.de>
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
@ -20,7 +19,7 @@
|
||||
#include "postgres.h"
|
||||
#include "miscadmin.h"
|
||||
#include "access/xact.h"
|
||||
#include "backend/fmgr.h"
|
||||
#include "fmgr.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/array.h"
|
||||
#include "utils/builtins.h"
|
||||
@ -29,20 +28,21 @@
|
||||
|
||||
#include "array_iterator.h"
|
||||
|
||||
static int32
|
||||
array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
|
||||
{
|
||||
HeapTuple typ_tuple;
|
||||
TypeTupleForm typ_struct;
|
||||
bool typbyval;
|
||||
int typlen;
|
||||
FmgrInfo finfo;
|
||||
func_ptr proc_fn;
|
||||
int pronargs;
|
||||
int nitems,
|
||||
i,
|
||||
result;
|
||||
int ndim,
|
||||
*dim;
|
||||
char *p;
|
||||
FmgrInfo finf; /*Tobias Gabele Jan 18 1999*/
|
||||
|
||||
/* Sanity checks */
|
||||
if ((array == (ArrayType *) NULL)
|
||||
@ -72,8 +72,11 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
|
||||
typbyval = typ_struct->typbyval;
|
||||
|
||||
/* Lookup the function entry point */
|
||||
fmgr_info(proc, &finfo);
|
||||
if ((finfo.fn_oid == 0) || (finfo.fn_nargs != 2))
|
||||
proc_fn = (func_ptr) NULL;
|
||||
fmgr_info(proc,&finf); /*Tobias Gabele Jan 18 1999*/
|
||||
proc_fn=finf.fn_addr; /*Tobias Gabele Jan 18 1999*/
|
||||
pronargs=finf.fn_nargs; /*Tobias Gabele Jan 18 1999*/
|
||||
if ((proc_fn == NULL) || (pronargs != 2))
|
||||
{
|
||||
elog(ERROR, "array_iterator: fmgr_info lookup failed for oid %d", proc);
|
||||
return (0);
|
||||
@ -89,42 +92,54 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
|
||||
switch (typlen)
|
||||
{
|
||||
case 1:
|
||||
result = (int) (*(finfo.fn_addr)) (*p, value);
|
||||
result = (int) (*proc_fn) (*p, value);
|
||||
break;
|
||||
case 2:
|
||||
result = (int) (*(finfo.fn_addr)) (*(int16 *) p, value);
|
||||
result = (int) (*proc_fn) (*(int16 *) p, value);
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
result = (int) (*(finfo.fn_addr)) (*(int32 *) p, value);
|
||||
result = (int) (*proc_fn) (*(int32 *) p, value);
|
||||
break;
|
||||
}
|
||||
p += typlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (int) (*(finfo.fn_addr)) (p, value);
|
||||
result = (int) (*proc_fn) (p, value);
|
||||
if (typlen > 0)
|
||||
{
|
||||
p += typlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
p += INTALIGN(*(int32 *) p);
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
if (!and)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (and)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (and && result)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -167,6 +182,47 @@ array_all_textregexeq(ArrayType *array, char *value)
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterator functions for type _char16. Note that the regexp
|
||||
* operators take the second argument of type text.
|
||||
*/
|
||||
|
||||
int32
|
||||
array_char16eq(ArrayType *array, char *value)
|
||||
{
|
||||
return array_iterator((Oid) 20, /* char16 */
|
||||
(Oid) 1275, /* char16eq */
|
||||
0, /* logical or */
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
int32
|
||||
array_all_char16eq(ArrayType *array, char *value)
|
||||
{
|
||||
return array_iterator((Oid) 20, /* char16 */
|
||||
(Oid) 1275, /* char16eq */
|
||||
1, /* logical and */
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
int32
|
||||
array_char16regexeq(ArrayType *array, char *value)
|
||||
{
|
||||
return array_iterator((Oid) 20, /* char16 */
|
||||
(Oid) 1288, /* char16regexeq */
|
||||
0, /* logical or */
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
int32
|
||||
array_all_char16regexeq(ArrayType *array, char *value)
|
||||
{
|
||||
return array_iterator((Oid) 20, /* char16 */
|
||||
(Oid) 1288, /* char16regexeq */
|
||||
1, /* logical and */
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterator functions for type _int4
|
||||
*/
|
||||
@ -279,12 +335,31 @@ array_all_int4le(ArrayType *array, int4 value)
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
/* new tobias gabele 1999 */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-indent-level: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
int32
|
||||
array_oideq(ArrayType *array, Oid value)
|
||||
{
|
||||
return array_iterator((Oid) 26, /* oid */
|
||||
(Oid) 184, /* oideq */
|
||||
0, /* logical or */
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
int32
|
||||
array_all_oidne(ArrayType *array, Oid value)
|
||||
{
|
||||
return array_iterator((Oid) 26, /* int4 */
|
||||
(Oid) 185, /* oidne */
|
||||
1, /* logical and */
|
||||
array, (Datum) value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file */
|
||||
|
Reference in New Issue
Block a user