9
9
* Portions Copyright (c) 1994, Regents of the University of California
10
10
*
11
11
* IDENTIFICATION
12
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.12 2000/11/16 21:43:28 petere Exp $
12
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.13 2000/11/18 16:18:41 petere Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
50
50
Datum
51
51
zpbit_in (PG_FUNCTION_ARGS )
52
52
{
53
- char * s = PG_GETARG_CSTRING (0 );
53
+ char * input_string = PG_GETARG_CSTRING (0 );
54
54
#ifdef NOT_USED
55
55
Oid typelem = PG_GETARG_OID (1 );
56
56
#endif
@@ -67,17 +67,27 @@ zpbit_in(PG_FUNCTION_ARGS)
67
67
bits8 x = 0 ;
68
68
69
69
/* Check that the first character is a b or an x */
70
- if (s [0 ] == 'b' || s [0 ] == 'B' )
70
+ if (input_string [0 ] == 'b' || input_string [0 ] == 'B' )
71
+ {
71
72
bit_not_hex = true;
72
- else if (s [0 ] == 'x' || s [0 ] == 'X' )
73
+ sp = input_string + 1 ;
74
+ }
75
+ else if (input_string [0 ] == 'x' || input_string [0 ] == 'X' )
76
+ {
73
77
bit_not_hex = false;
78
+ sp = input_string + 1 ;
79
+ }
74
80
else
75
81
{
76
- elog (ERROR , "zpbit_in: %s is not a valid bitstring" , s );
77
- bit_not_hex = false; /* keep compiler quiet */
82
+ /*
83
+ * Otherwise it's binary. This allows things like cast('1001'
84
+ * as bit) to work transparently.
85
+ */
86
+ bit_not_hex = true;
87
+ sp = input_string ;
78
88
}
79
89
80
- slen = strlen (s ) - 1 ;
90
+ slen = strlen (sp ) ;
81
91
/* Determine bitlength from input string */
82
92
if (bit_not_hex )
83
93
bitlen = slen ;
@@ -104,7 +114,6 @@ zpbit_in(PG_FUNCTION_ARGS)
104
114
VARATT_SIZEP (result ) = len ;
105
115
VARBITLEN (result ) = atttypmod ;
106
116
107
- sp = s + 1 ;
108
117
r = VARBITS (result );
109
118
if (bit_not_hex )
110
119
{
@@ -283,7 +292,7 @@ _zpbit(PG_FUNCTION_ARGS)
283
292
Datum
284
293
varbit_in (PG_FUNCTION_ARGS )
285
294
{
286
- char * s = PG_GETARG_CSTRING (0 );
295
+ char * input_string = PG_GETARG_CSTRING (0 );
287
296
#ifdef NOT_USED
288
297
Oid typelem = PG_GETARG_OID (1 );
289
298
#endif
@@ -300,17 +309,23 @@ varbit_in(PG_FUNCTION_ARGS)
300
309
bits8 x = 0 ;
301
310
302
311
/* Check that the first character is a b or an x */
303
- if (s [0 ] == 'b' || s [0 ] == 'B' )
312
+ if (input_string [0 ] == 'b' || input_string [0 ] == 'B' )
313
+ {
304
314
bit_not_hex = true;
305
- else if (s [0 ] == 'x' || s [0 ] == 'X' )
315
+ sp = input_string + 1 ;
316
+ }
317
+ else if (input_string [0 ] == 'x' || input_string [0 ] == 'X' )
318
+ {
306
319
bit_not_hex = false;
320
+ sp = input_string + 1 ;
321
+ }
307
322
else
308
323
{
309
- elog ( ERROR , "varbit_in: %s is not a valid bitstring" , s ) ;
310
- bit_not_hex = false; /* keep compiler quiet */
324
+ bit_not_hex = true ;
325
+ sp = input_string ;
311
326
}
312
327
313
- slen = strlen (s ) - 1 ;
328
+ slen = strlen (sp ) ;
314
329
/* Determine bitlength from input string */
315
330
if (bit_not_hex )
316
331
bitlen = slen ;
@@ -337,7 +352,6 @@ varbit_in(PG_FUNCTION_ARGS)
337
352
VARATT_SIZEP (result ) = len ;
338
353
VARBITLEN (result ) = Min (bitlen , atttypmod );
339
354
340
- sp = s + 1 ;
341
355
r = VARBITS (result );
342
356
if (bit_not_hex )
343
357
{
@@ -418,10 +432,9 @@ varbit_out(PG_FUNCTION_ARGS)
418
432
len ;
419
433
420
434
len = VARBITLEN (s );
421
- result = (char * ) palloc (len + 2 );
435
+ result = (char * ) palloc (len + 1 );
422
436
sp = VARBITS (s );
423
437
r = result ;
424
- * r ++ = 'B' ;
425
438
for (i = 0 ; i < len - BITS_PER_BYTE ; i += BITS_PER_BYTE , sp ++ )
426
439
{
427
440
x = * sp ;
@@ -1224,8 +1237,10 @@ bitposition(PG_FUNCTION_ARGS)
1224
1237
if (p == VARBITEND (arg )) {
1225
1238
mask2 = end_mask << (BITS_PER_BYTE - is );
1226
1239
is_match = mask2 == 0 ;
1240
+ #if 0
1227
1241
elog (NOTICE ,"S. %d %d em=%2x sm=%2x r=%d" ,
1228
1242
i ,is ,end_mask ,mask2 ,is_match );
1243
+ #endif
1229
1244
break ;
1230
1245
}
1231
1246
cmp = * s << (BITS_PER_BYTE - is );
0 commit comments