Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7311da9

Browse files
committed
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
1 parentcdbaec7 commit7311da9

File tree

3 files changed

+163
-34
lines changed

3 files changed

+163
-34
lines changed

‎contrib/array/array_iterator.c

Lines changed: 96 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
* elements of the array and the value and compute a result as
77
* the logical OR or AND of the iteration results.
88
*
9-
* Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
10-
*
11-
* This file is distributed under the GNU General Public License
12-
* either version 2, or (at your option) any later version.
9+
* Copyright (c) 1997, Massimo Dal Zotto <dz@cs.unitn.it>
10+
* ported to postgreSQL 6.3.2,added oid_functions, 18.1.1999,
11+
* Tobias Gabele <gabele@wiz.uni-kassel.de>
1312
*/
1413

1514
#include<ctype.h>
@@ -20,7 +19,7 @@
2019
#include"postgres.h"
2120
#include"miscadmin.h"
2221
#include"access/xact.h"
23-
#include"backend/fmgr.h"
22+
#include"fmgr.h"
2423
#include"catalog/pg_type.h"
2524
#include"utils/array.h"
2625
#include"utils/builtins.h"
@@ -29,20 +28,21 @@
2928

3029
#include"array_iterator.h"
3130

32-
staticint32
3331
array_iterator(Oidelemtype,Oidproc,intand,ArrayType*array,Datumvalue)
3432
{
3533
HeapTupletyp_tuple;
3634
TypeTupleFormtyp_struct;
3735
booltypbyval;
3836
inttyplen;
39-
FmgrInfofinfo;
37+
func_ptrproc_fn;
38+
intpronargs;
4039
intnitems,
4140
i,
4241
result;
4342
intndim,
4443
*dim;
4544
char*p;
45+
FmgrInfofinf;/*Tobias Gabele Jan 18 1999*/
4646

4747
/* Sanity checks */
4848
if ((array== (ArrayType*)NULL)
@@ -72,8 +72,11 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
7272
typbyval=typ_struct->typbyval;
7373

7474
/* Lookup the function entry point */
75-
fmgr_info(proc,&finfo);
76-
if ((finfo.fn_oid==0)|| (finfo.fn_nargs!=2))
75+
proc_fn= (func_ptr)NULL;
76+
fmgr_info(proc,&finf);/*Tobias Gabele Jan 18 1999*/
77+
proc_fn=finf.fn_addr;/*Tobias Gabele Jan 18 1999*/
78+
pronargs=finf.fn_nargs;/*Tobias Gabele Jan 18 1999*/
79+
if ((proc_fn==NULL)|| (pronargs!=2))
7780
{
7881
elog(ERROR,"array_iterator: fmgr_info lookup failed for oid %d",proc);
7982
return (0);
@@ -89,42 +92,54 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
8992
switch (typlen)
9093
{
9194
case1:
92-
result= (int) (*(finfo.fn_addr)) (*p,value);
95+
result= (int) (*proc_fn) (*p,value);
9396
break;
9497
case2:
95-
result= (int) (*(finfo.fn_addr)) (*(int16*)p,value);
98+
result= (int) (*proc_fn) (*(int16*)p,value);
9699
break;
97100
case3:
98101
case4:
99-
result= (int) (*(finfo.fn_addr)) (*(int32*)p,value);
102+
result= (int) (*proc_fn) (*(int32*)p,value);
100103
break;
101104
}
102105
p+=typlen;
103106
}
104107
else
105108
{
106-
result= (int) (*(finfo.fn_addr)) (p,value);
109+
result= (int) (*proc_fn) (p,value);
107110
if (typlen>0)
111+
{
108112
p+=typlen;
113+
}
109114
else
115+
{
110116
p+=INTALIGN(*(int32*)p);
117+
}
111118
}
112119
if (result)
113120
{
114121
if (!and)
122+
{
115123
return (1);
124+
}
116125
}
117126
else
118127
{
119128
if (and)
129+
{
120130
return (0);
131+
}
121132
}
122133
}
123134

124135
if (and&&result)
136+
{
125137
return (1);
138+
}
126139
else
140+
{
127141
return (0);
142+
}
128143
}
129144

130145
/*
@@ -167,6 +182,47 @@ array_all_textregexeq(ArrayType *array, char *value)
167182
array, (Datum)value);
168183
}
169184

185+
/*
186+
* Iterator functions for type _char16. Note that the regexp
187+
* operators take the second argument of type text.
188+
*/
189+
190+
int32
191+
array_char16eq(ArrayType*array,char*value)
192+
{
193+
returnarray_iterator((Oid)20,/* char16 */
194+
(Oid)1275,/* char16eq */
195+
0,/* logical or */
196+
array, (Datum)value);
197+
}
198+
199+
int32
200+
array_all_char16eq(ArrayType*array,char*value)
201+
{
202+
returnarray_iterator((Oid)20,/* char16 */
203+
(Oid)1275,/* char16eq */
204+
1,/* logical and */
205+
array, (Datum)value);
206+
}
207+
208+
int32
209+
array_char16regexeq(ArrayType*array,char*value)
210+
{
211+
returnarray_iterator((Oid)20,/* char16 */
212+
(Oid)1288,/* char16regexeq */
213+
0,/* logical or */
214+
array, (Datum)value);
215+
}
216+
217+
int32
218+
array_all_char16regexeq(ArrayType*array,char*value)
219+
{
220+
returnarray_iterator((Oid)20,/* char16 */
221+
(Oid)1288,/* char16regexeq */
222+
1,/* logical and */
223+
array, (Datum)value);
224+
}
225+
170226
/*
171227
* Iterator functions for type _int4
172228
*/
@@ -279,12 +335,31 @@ array_all_int4le(ArrayType *array, int4 value)
279335
array, (Datum)value);
280336
}
281337

282-
/*end of file */
338+
/*new tobias gabele 1999 */
283339

284-
/*
285-
* Local variables:
286-
* tab-width: 4
287-
* c-indent-level: 4
288-
* c-basic-offset: 4
289-
* End:
290-
*/
340+
341+
int32
342+
array_oideq(ArrayType*array,Oidvalue)
343+
{
344+
returnarray_iterator((Oid)26,/* oid */
345+
(Oid)184,/* oideq */
346+
0,/* logical or */
347+
array, (Datum)value);
348+
}
349+
350+
int32
351+
array_all_oidne(ArrayType*array,Oidvalue)
352+
{
353+
returnarray_iterator((Oid)26,/* int4 */
354+
(Oid)185,/* oidne */
355+
1,/* logical and */
356+
array, (Datum)value);
357+
}
358+
359+
360+
361+
362+
363+
364+
365+
/* end of file */

‎contrib/array/array_iterator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ int32array_int4lt(ArrayType *array, int4 value);
2424
int32array_all_int4lt(ArrayType*array,int4value);
2525
int32array_int4le(ArrayType*array,int4value);
2626
int32array_all_int4le(ArrayType*array,int4value);
27-
27+
int32array_oideq(ArrayType*array,Oidvalue);
28+
int32array_all_oidne(ArrayType*array,Oidvalue);
2829
#endif

‎contrib/array/array_iterator.sql.in

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
-- array_iterator.sql --
2-
--
3-
-- SQL code to define the array iterator functions and operators.
4-
--
5-
-- Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
6-
--
7-
-- This file is distributed under the GNU General Public License
8-
-- either version 2, or (at your option) any later version.
1+
-- SQL code to define the new array iterator functions and operators
92

10-
--Define the arrayfunctions *=, **=, *~ and **~ for type _text
3+
--define the arrayoperators *=, **=, *~ and **~ for type _text
114
--
125
create function array_texteq(_text, text) returns bool
136
as 'MODULE_PATHNAME'
@@ -45,7 +38,47 @@ create operator **~ (
4538
rightarg=text,
4639
procedure=array_all_textregexeq);
4740

48-
-- Define the array functions *=, **=, *> and **> for type _int4
41+
42+
-- define the array operators *=, **=, *~ and **~ for type _char16
43+
--
44+
create function array_char16eq(_char16, char16) returns bool
45+
as 'MODULE_PATHNAME'
46+
language 'c';
47+
48+
create function array_all_char16eq(_char16, char16) returns bool
49+
as 'MODULE_PATHNAME'
50+
language 'c';
51+
52+
create function array_char16regexeq(_char16, text) returns bool
53+
as 'MODULE_PATHNAME'
54+
language 'c';
55+
56+
create function array_all_char16regexeq(_char16, text) returns bool
57+
as 'MODULE_PATHNAME'
58+
language 'c';
59+
60+
create operator *= (
61+
leftarg=_char16,
62+
rightarg=char16,
63+
procedure=array_char16eq);
64+
65+
create operator **= (
66+
leftarg=_char16,
67+
rightarg=char16,
68+
procedure=array_all_char16eq);
69+
70+
create operator *~ (
71+
leftarg=_char16,
72+
rightarg=text,
73+
procedure=array_char16regexeq);
74+
75+
create operator **~ (
76+
leftarg=_char16,
77+
rightarg=text,
78+
procedure=array_all_char16regexeq);
79+
80+
81+
-- define the array operators *=, **=, *> and **> for type _int4
4982
--
5083
create function array_int4eq(_int4, int4) returns bool
5184
as 'MODULE_PATHNAME'
@@ -95,8 +128,6 @@ create function array_all_int4le(_int4, int4) returns bool
95128
as 'MODULE_PATHNAME'
96129
language 'c';
97130

98-
-- Define the operators corresponding to the above functions
99-
--
100131
create operator *= (
101132
leftarg=_int4,
102133
rightarg=int4,
@@ -157,4 +188,26 @@ create operator **<= (
157188
rightarg=int4,
158189
procedure=array_all_int4le);
159190

191+
-- define the array operators *=, **<> for type _oid (added tobias 1. 1999)
192+
--
193+
create function array_oideq(_oid, oid) returns bool
194+
as 'MODULE_PATHNAME'
195+
language 'c';
196+
197+
create function array_all_oidne(_oid, oid) returns bool
198+
as 'MODULE_PATHNAME'
199+
language 'c';
200+
201+
create operator *= (
202+
leftarg=_oid,
203+
rightarg=oid,
204+
procedure=array_oideq);
205+
206+
create operator **<> (
207+
leftarg=_oid,
208+
rightarg=oid,
209+
procedure=array_all_oidne);
210+
211+
212+
160213
-- end of file

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp