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

Commit84aa797

Browse files
committed
Allow uuid_in() to parse a wider variety of variant input formats for the UUID
data type. This patch takes the approach of allowing an optional hyphen aftereach group of four hex digits.Author: Robert Haas <robertmhaas@gmail.com>
1 parent48cbe59 commit84aa797

File tree

2 files changed

+31
-37
lines changed

2 files changed

+31
-37
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.230 2008/10/14 17:12:32 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.231 2008/11/03 22:14:40 petere Exp $ -->
22

33
<chapter id="datatype">
44
<title id="datatype-title">Data Types</title>
@@ -3550,11 +3550,14 @@ a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
35503550
<productname>PostgreSQL</productname> also accepts the following
35513551
alternative forms for input:
35523552
use of upper-case digits, the standard format surrounded by
3553-
braces, and omitting the hyphens. Examples are:
3553+
braces, omitting some or all hyphens, adding a hyphen after any
3554+
group of four digits. Examples are:
35543555
<programlisting>
35553556
A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11
35563557
{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}
35573558
a0eebc999c0b4ef8bb6d6bb9bd380a11
3559+
a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11
3560+
{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}
35583561
</programlisting>
35593562
Output is always in the standard form.
35603563
</para>

‎src/backend/utils/adt/uuid.c

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2007-2008, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/utils/adt/uuid.c,v 1.7 2008/01/01 20:31:21 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/utils/adt/uuid.c,v 1.8 2008/11/03 22:14:40 petere Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -74,60 +74,51 @@ uuid_out(PG_FUNCTION_ARGS)
7474
}
7575

7676
/*
77-
* We allow UUIDsin three input formats: 8x-4x-4x-4x-12x,
78-
*{8x-4x-4x-4x-12x}, and 32x, where "nx" means nhexadecimal digits
79-
* (only the firstformatis used for output). We convert the first
80-
*two formats intothelatter format before further processing.
77+
* We allow UUIDsas a series of 32 hexadecimal digits with an optional dash
78+
*after each group of 4hexadecimal digits, and optionally surrounded by {}.
79+
* (The canonicalformat8x-4x-4x-4x-12x, where "nx" means n hexadecimal
80+
*digits, istheonly one used for output.)
8181
*/
8282
staticvoid
8383
string_to_uuid(constchar*source,pg_uuid_t*uuid)
8484
{
85-
charhex_buf[32];/* not NUL terminated */
86-
inti;
87-
intsrc_len;
88-
89-
src_len=strlen(source);
90-
if (src_len!=32&&src_len!=36&&src_len!=38)
91-
gotosyntax_error;
85+
constchar*src=source;
86+
inti,braces=0;
9287

93-
if (src_len==32)
94-
memcpy(hex_buf,source,src_len);
95-
else
88+
if (src[0]=='{')
9689
{
97-
constchar*str=source;
98-
99-
if (src_len==38)
100-
{
101-
if (str[0]!='{'||str[37]!='}')
102-
gotosyntax_error;
103-
104-
str++;/* skip the first character */
105-
}
106-
107-
if (str[8]!='-'||str[13]!='-'||
108-
str[18]!='-'||str[23]!='-')
109-
gotosyntax_error;
110-
111-
memcpy(hex_buf,str,8);
112-
memcpy(hex_buf+8,str+9,4);
113-
memcpy(hex_buf+12,str+14,4);
114-
memcpy(hex_buf+16,str+19,4);
115-
memcpy(hex_buf+20,str+24,12);
90+
++src;
91+
braces=1;
11692
}
11793

11894
for (i=0;i<UUID_LEN;i++)
11995
{
12096
charstr_buf[3];
12197

122-
memcpy(str_buf,&hex_buf[i*2],2);
98+
if (src[0]=='\0'||src[1]=='\0')
99+
gotosyntax_error;
100+
memcpy(str_buf,src,2);
123101
if (!isxdigit((unsignedchar)str_buf[0])||
124102
!isxdigit((unsignedchar)str_buf[1]))
125103
gotosyntax_error;
126104

127105
str_buf[2]='\0';
128106
uuid->data[i]= (unsignedchar)strtoul(str_buf,NULL,16);
107+
src+=2;
108+
if (src[0]=='-'&& (i %2)==1&&i<UUID_LEN-1)
109+
src++;
129110
}
130111

112+
if (braces)
113+
{
114+
if (*src!='}')
115+
gotosyntax_error;
116+
++src;
117+
}
118+
119+
if (*src!='\0')
120+
gotosyntax_error;
121+
131122
return;
132123

133124
syntax_error:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp