8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.38 2000/08/01 18:29:35 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.39 2000/11/21 03:23:19 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -43,7 +43,7 @@ oidvectorin(PG_FUNCTION_ARGS)
43
43
break ;
44
44
while (* oidString && isspace ((int ) * oidString ))
45
45
oidString ++ ;
46
- while (* oidString && ! isspace ((int ) * oidString ))
46
+ while (* oidString && isdigit ((int ) * oidString ))
47
47
oidString ++ ;
48
48
}
49
49
while (* oidString && isspace ((int ) * oidString ))
@@ -79,7 +79,7 @@ oidvectorout(PG_FUNCTION_ARGS)
79
79
{
80
80
if (num != 0 )
81
81
* rp ++ = ' ' ;
82
- pg_ltoa (( int32 ) oidArray [num ], rp );
82
+ sprintf ( rp , "%u" , oidArray [num ]);
83
83
while (* ++ rp != '\0' )
84
84
;
85
85
}
@@ -91,18 +91,43 @@ Datum
91
91
oidin (PG_FUNCTION_ARGS )
92
92
{
93
93
char * s = PG_GETARG_CSTRING (0 );
94
+ unsigned long cvt ;
95
+ char * endptr ;
96
+ Oid result ;
94
97
95
- /* XXX should use an unsigned-int conversion here */
96
- return DirectFunctionCall1 (int4in , CStringGetDatum (s ));
98
+ errno = 0 ;
99
+
100
+ cvt = strtoul (s , & endptr , 10 );
101
+
102
+ /*
103
+ * strtoul() normally only sets ERANGE. On some systems it also
104
+ * may set EINVAL, which simply means it couldn't parse the
105
+ * input string. This is handled by the second "if" consistent
106
+ * across platforms.
107
+ */
108
+ if (errno && errno != EINVAL )
109
+ elog (ERROR , "oidin: error reading \"%s\": %m" , s );
110
+ if (endptr && * endptr )
111
+ elog (ERROR , "oidin: error in \"%s\": can't parse \"%s\"" , s , endptr );
112
+
113
+ /*
114
+ * Cope with possibility that unsigned long is wider than Oid.
115
+ */
116
+ result = (Oid ) cvt ;
117
+ if ((unsigned long ) result != cvt )
118
+ elog (ERROR , "oidin: error reading \"%s\": value too large" , s );
119
+
120
+ return ObjectIdGetDatum (result );
97
121
}
98
122
99
123
Datum
100
124
oidout (PG_FUNCTION_ARGS )
101
125
{
102
126
Oid o = PG_GETARG_OID (0 );
127
+ char * result = (char * ) palloc (12 );
103
128
104
- /* XXX should use an unsigned-int conversion here */
105
- return DirectFunctionCall1 ( int4out , ObjectIdGetDatum ( o ) );
129
+ snprintf ( result , 12 , "%u" , o );
130
+ PG_RETURN_CSTRING ( result );
106
131
}
107
132
108
133
/*****************************************************************************
@@ -127,6 +152,42 @@ oidne(PG_FUNCTION_ARGS)
127
152
PG_RETURN_BOOL (arg1 != arg2 );
128
153
}
129
154
155
+ Datum
156
+ oidlt (PG_FUNCTION_ARGS )
157
+ {
158
+ Oid arg1 = PG_GETARG_OID (0 );
159
+ Oid arg2 = PG_GETARG_OID (1 );
160
+
161
+ PG_RETURN_BOOL (arg1 < arg2 );
162
+ }
163
+
164
+ Datum
165
+ oidle (PG_FUNCTION_ARGS )
166
+ {
167
+ Oid arg1 = PG_GETARG_OID (0 );
168
+ Oid arg2 = PG_GETARG_OID (1 );
169
+
170
+ PG_RETURN_BOOL (arg1 <= arg2 );
171
+ }
172
+
173
+ Datum
174
+ oidge (PG_FUNCTION_ARGS )
175
+ {
176
+ Oid arg1 = PG_GETARG_OID (0 );
177
+ Oid arg2 = PG_GETARG_OID (1 );
178
+
179
+ PG_RETURN_BOOL (arg1 >= arg2 );
180
+ }
181
+
182
+ Datum
183
+ oidgt (PG_FUNCTION_ARGS )
184
+ {
185
+ Oid arg1 = PG_GETARG_OID (0 );
186
+ Oid arg2 = PG_GETARG_OID (1 );
187
+
188
+ PG_RETURN_BOOL (arg1 > arg2 );
189
+ }
190
+
130
191
Datum
131
192
oidvectoreq (PG_FUNCTION_ARGS )
132
193
{
@@ -197,26 +258,6 @@ oidvectorgt(PG_FUNCTION_ARGS)
197
258
PG_RETURN_BOOL (false);
198
259
}
199
260
200
- Datum
201
- oideqint4 (PG_FUNCTION_ARGS )
202
- {
203
- Oid arg1 = PG_GETARG_OID (0 );
204
- int32 arg2 = PG_GETARG_INT32 (1 );
205
-
206
- /* oid is unsigned, but int4 is signed */
207
- PG_RETURN_BOOL (arg2 >= 0 && arg1 == arg2 );
208
- }
209
-
210
- Datum
211
- int4eqoid (PG_FUNCTION_ARGS )
212
- {
213
- int32 arg1 = PG_GETARG_INT32 (0 );
214
- Oid arg2 = PG_GETARG_OID (1 );
215
-
216
- /* oid is unsigned, but int4 is signed */
217
- PG_RETURN_BOOL (arg1 >= 0 && arg1 == arg2 );
218
- }
219
-
220
261
Datum
221
262
oid_text (PG_FUNCTION_ARGS )
222
263
{
0 commit comments