mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-30 17:11:15 +02: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:
parent
cdbaec771c
commit
7311da9ec4
@ -6,10 +6,9 @@
|
|||||||
* elements of the array and the value and compute a result as
|
* elements of the array and the value and compute a result as
|
||||||
* the logical OR or AND of the iteration results.
|
* the logical OR or AND of the iteration results.
|
||||||
*
|
*
|
||||||
* Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
|
* Copyright (c) 1997, Massimo Dal Zotto <dz@cs.unitn.it>
|
||||||
*
|
* ported to postgreSQL 6.3.2,added oid_functions, 18.1.1999,
|
||||||
* This file is distributed under the GNU General Public License
|
* Tobias Gabele <gabele@wiz.uni-kassel.de>
|
||||||
* either version 2, or (at your option) any later version.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -20,7 +19,7 @@
|
|||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "access/xact.h"
|
#include "access/xact.h"
|
||||||
#include "backend/fmgr.h"
|
#include "fmgr.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "utils/array.h"
|
#include "utils/array.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
@ -29,20 +28,21 @@
|
|||||||
|
|
||||||
#include "array_iterator.h"
|
#include "array_iterator.h"
|
||||||
|
|
||||||
static int32
|
|
||||||
array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
|
array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
|
||||||
{
|
{
|
||||||
HeapTuple typ_tuple;
|
HeapTuple typ_tuple;
|
||||||
TypeTupleForm typ_struct;
|
TypeTupleForm typ_struct;
|
||||||
bool typbyval;
|
bool typbyval;
|
||||||
int typlen;
|
int typlen;
|
||||||
FmgrInfo finfo;
|
func_ptr proc_fn;
|
||||||
|
int pronargs;
|
||||||
int nitems,
|
int nitems,
|
||||||
i,
|
i,
|
||||||
result;
|
result;
|
||||||
int ndim,
|
int ndim,
|
||||||
*dim;
|
*dim;
|
||||||
char *p;
|
char *p;
|
||||||
|
FmgrInfo finf; /*Tobias Gabele Jan 18 1999*/
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
if ((array == (ArrayType *) NULL)
|
if ((array == (ArrayType *) NULL)
|
||||||
@ -72,8 +72,11 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
|
|||||||
typbyval = typ_struct->typbyval;
|
typbyval = typ_struct->typbyval;
|
||||||
|
|
||||||
/* Lookup the function entry point */
|
/* Lookup the function entry point */
|
||||||
fmgr_info(proc, &finfo);
|
proc_fn = (func_ptr) NULL;
|
||||||
if ((finfo.fn_oid == 0) || (finfo.fn_nargs != 2))
|
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);
|
elog(ERROR, "array_iterator: fmgr_info lookup failed for oid %d", proc);
|
||||||
return (0);
|
return (0);
|
||||||
@ -89,42 +92,54 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
|
|||||||
switch (typlen)
|
switch (typlen)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
result = (int) (*(finfo.fn_addr)) (*p, value);
|
result = (int) (*proc_fn) (*p, value);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
result = (int) (*(finfo.fn_addr)) (*(int16 *) p, value);
|
result = (int) (*proc_fn) (*(int16 *) p, value);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
case 4:
|
case 4:
|
||||||
result = (int) (*(finfo.fn_addr)) (*(int32 *) p, value);
|
result = (int) (*proc_fn) (*(int32 *) p, value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p += typlen;
|
p += typlen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = (int) (*(finfo.fn_addr)) (p, value);
|
result = (int) (*proc_fn) (p, value);
|
||||||
if (typlen > 0)
|
if (typlen > 0)
|
||||||
|
{
|
||||||
p += typlen;
|
p += typlen;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
p += INTALIGN(*(int32 *) p);
|
p += INTALIGN(*(int32 *) p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
if (!and)
|
if (!and)
|
||||||
|
{
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (and)
|
if (and)
|
||||||
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (and && result)
|
if (and && result)
|
||||||
|
{
|
||||||
return (1);
|
return (1);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -167,6 +182,47 @@ array_all_textregexeq(ArrayType *array, char *value)
|
|||||||
array, (Datum) 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
|
* Iterator functions for type _int4
|
||||||
*/
|
*/
|
||||||
@ -279,12 +335,31 @@ array_all_int4le(ArrayType *array, int4 value)
|
|||||||
array, (Datum) value);
|
array, (Datum) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end of file */
|
/* new tobias gabele 1999 */
|
||||||
|
|
||||||
/*
|
|
||||||
* Local variables:
|
int32
|
||||||
* tab-width: 4
|
array_oideq(ArrayType *array, Oid value)
|
||||||
* c-indent-level: 4
|
{
|
||||||
* c-basic-offset: 4
|
return array_iterator((Oid) 26, /* oid */
|
||||||
* End:
|
(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 */
|
||||||
|
@ -24,5 +24,6 @@ int32 array_int4lt(ArrayType *array, int4 value);
|
|||||||
int32 array_all_int4lt(ArrayType *array, int4 value);
|
int32 array_all_int4lt(ArrayType *array, int4 value);
|
||||||
int32 array_int4le(ArrayType *array, int4 value);
|
int32 array_int4le(ArrayType *array, int4 value);
|
||||||
int32 array_all_int4le(ArrayType *array, int4 value);
|
int32 array_all_int4le(ArrayType *array, int4 value);
|
||||||
|
int32 array_oideq(ArrayType *array, Oid value);
|
||||||
|
int32 array_all_oidne(ArrayType *array, Oid value);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
-- array_iterator.sql --
|
-- SQL code to define the new array iterator functions and operators
|
||||||
--
|
|
||||||
-- SQL code to define the array iterator functions and operators.
|
|
||||||
--
|
|
||||||
-- 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.
|
|
||||||
|
|
||||||
-- Define the array functions *=, **=, *~ and **~ for type _text
|
-- define the array operators *=, **=, *~ and **~ for type _text
|
||||||
--
|
--
|
||||||
create function array_texteq(_text, text) returns bool
|
create function array_texteq(_text, text) returns bool
|
||||||
as 'MODULE_PATHNAME'
|
as 'MODULE_PATHNAME'
|
||||||
@ -45,7 +38,47 @@ create operator **~ (
|
|||||||
rightarg=text,
|
rightarg=text,
|
||||||
procedure=array_all_textregexeq);
|
procedure=array_all_textregexeq);
|
||||||
|
|
||||||
-- Define the array functions *=, **=, *> and **> for type _int4
|
|
||||||
|
-- define the array operators *=, **=, *~ and **~ for type _char16
|
||||||
|
--
|
||||||
|
create function array_char16eq(_char16, char16) returns bool
|
||||||
|
as 'MODULE_PATHNAME'
|
||||||
|
language 'c';
|
||||||
|
|
||||||
|
create function array_all_char16eq(_char16, char16) returns bool
|
||||||
|
as 'MODULE_PATHNAME'
|
||||||
|
language 'c';
|
||||||
|
|
||||||
|
create function array_char16regexeq(_char16, text) returns bool
|
||||||
|
as 'MODULE_PATHNAME'
|
||||||
|
language 'c';
|
||||||
|
|
||||||
|
create function array_all_char16regexeq(_char16, text) returns bool
|
||||||
|
as 'MODULE_PATHNAME'
|
||||||
|
language 'c';
|
||||||
|
|
||||||
|
create operator *= (
|
||||||
|
leftarg=_char16,
|
||||||
|
rightarg=char16,
|
||||||
|
procedure=array_char16eq);
|
||||||
|
|
||||||
|
create operator **= (
|
||||||
|
leftarg=_char16,
|
||||||
|
rightarg=char16,
|
||||||
|
procedure=array_all_char16eq);
|
||||||
|
|
||||||
|
create operator *~ (
|
||||||
|
leftarg=_char16,
|
||||||
|
rightarg=text,
|
||||||
|
procedure=array_char16regexeq);
|
||||||
|
|
||||||
|
create operator **~ (
|
||||||
|
leftarg=_char16,
|
||||||
|
rightarg=text,
|
||||||
|
procedure=array_all_char16regexeq);
|
||||||
|
|
||||||
|
|
||||||
|
-- define the array operators *=, **=, *> and **> for type _int4
|
||||||
--
|
--
|
||||||
create function array_int4eq(_int4, int4) returns bool
|
create function array_int4eq(_int4, int4) returns bool
|
||||||
as 'MODULE_PATHNAME'
|
as 'MODULE_PATHNAME'
|
||||||
@ -95,8 +128,6 @@ create function array_all_int4le(_int4, int4) returns bool
|
|||||||
as 'MODULE_PATHNAME'
|
as 'MODULE_PATHNAME'
|
||||||
language 'c';
|
language 'c';
|
||||||
|
|
||||||
-- Define the operators corresponding to the above functions
|
|
||||||
--
|
|
||||||
create operator *= (
|
create operator *= (
|
||||||
leftarg=_int4,
|
leftarg=_int4,
|
||||||
rightarg=int4,
|
rightarg=int4,
|
||||||
@ -157,4 +188,26 @@ create operator **<= (
|
|||||||
rightarg=int4,
|
rightarg=int4,
|
||||||
procedure=array_all_int4le);
|
procedure=array_all_int4le);
|
||||||
|
|
||||||
|
-- define the array operators *=, **<> for type _oid (added tobias 1. 1999)
|
||||||
|
--
|
||||||
|
create function array_oideq(_oid, oid) returns bool
|
||||||
|
as 'MODULE_PATHNAME'
|
||||||
|
language 'c';
|
||||||
|
|
||||||
|
create function array_all_oidne(_oid, oid) returns bool
|
||||||
|
as 'MODULE_PATHNAME'
|
||||||
|
language 'c';
|
||||||
|
|
||||||
|
create operator *= (
|
||||||
|
leftarg=_oid,
|
||||||
|
rightarg=oid,
|
||||||
|
procedure=array_oideq);
|
||||||
|
|
||||||
|
create operator **<> (
|
||||||
|
leftarg=_oid,
|
||||||
|
rightarg=oid,
|
||||||
|
procedure=array_all_oidne);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- end of file
|
-- end of file
|
||||||
|
Loading…
Reference in New Issue
Block a user