* 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>
#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"
#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)
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);
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);
+ }
}
/*
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
*/
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 */
--- array_iterator.sql --
---
--- 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.
+-- SQL code to define the new array iterator functions and operators
--- Define the array functions *=, **=, *~ and **~ for type _text
+-- define the array operators *=, **=, *~ and **~ for type _text
--
create function array_texteq(_text, text) returns bool
as 'MODULE_PATHNAME'
rightarg=text,
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
as 'MODULE_PATHNAME'
as 'MODULE_PATHNAME'
language 'c';
--- Define the operators corresponding to the above functions
---
create operator *= (
leftarg=_int4,
rightarg=int4,
rightarg=int4,
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