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

Commit3d4d1e1

Browse files
author
Thomas G. Lockhart
committed
Implement SQL92 binary and hexadecimal string decoding (b'10' and x'1F').
Check decoding of integer in x - y syntax (already done for most ints).
1 parent2fa3302 commit3d4d1e1

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

‎src/backend/parser/scan.l

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.28 1997/11/14 15:43:27 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.29 1997/11/17 16:31:39 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -71,6 +71,8 @@ char literal[MAX_PARSE_BUFFER];
7171
* There are exclusive states for quoted strings, extended comments,
7272
* and to eliminate parsing troubles for numeric strings.
7373
* Exclusive states:
74+
* <xb> binary numeric string - thomas 1997-11-16
75+
* <xh> hexadecimal numeric string - thomas 1997-11-16
7476
* <xc> extended C-style comments - tgl 1997-07-12
7577
* <xq> quoted strings - tgl 1997-07-30
7678
* <xm> numeric strings with embedded minus sign - tgl 1997-09-05
@@ -83,8 +85,10 @@ char literal[MAX_PARSE_BUFFER];
8385
*operator-like symbols. - thomas 1997-07-14
8486
*/
8587

88+
%xxb
8689
%xxc
8790
%xxd
91+
%xxh
8892
%xxq
8993
%xxm
9094

@@ -97,6 +101,16 @@ xqembedded"\\'"
97101
xqliteral[\\](.|\n)
98102
xqcat{quote}{space}*\n{space}*{quote}
99103

104+
xbstart[bB]{quote}
105+
xbstop{quote}
106+
xbinside[^']*
107+
xbcat{quote}{space}*\n{space}*{quote}
108+
109+
xhstart[xX]{quote}
110+
xhstop{quote}
111+
xhinside[^']*
112+
xhcat{quote}{space}*\n{space}*{quote}
113+
100114
dquote\"
101115
xdstart{dquote}
102116
xdstop{dquote}
@@ -162,6 +176,48 @@ other.
162176

163177
<xc>{xcinside}{/* ignore */ }
164178

179+
{xbstart}{
180+
BEGIN(xb);
181+
llen =0;
182+
*literal ='\0';
183+
}
184+
<xb>{xbstop}{
185+
char* endptr;
186+
187+
BEGIN(INITIAL);
188+
errno =0;
189+
yylval.ival =strtol((char *)literal,&endptr,2);
190+
if (*endptr !='\0' || errno == ERANGE)
191+
elog(WARN,"Bad binary integer input '%s'",literal);
192+
return (ICONST);
193+
}
194+
<xh>{xhinside}|
195+
<xb>{xbinside}{
196+
if ((llen+yyleng) > (MAX_PARSE_BUFFER -1))
197+
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
198+
memcpy(literal+llen, yytext, yyleng+1);
199+
llen += yyleng;
200+
}
201+
<xh>{xhcat}|
202+
<xb>{xbcat}{
203+
}
204+
205+
{xhstart}{
206+
BEGIN(xh);
207+
llen =0;
208+
*literal ='\0';
209+
}
210+
<xh>{xhstop}{
211+
char* endptr;
212+
213+
BEGIN(INITIAL);
214+
errno =0;
215+
yylval.ival =strtol((char *)literal,&endptr,16);
216+
if (*endptr !='\0' || errno == ERANGE)
217+
elog(WARN,"Bad hexadecimal integer input '%s'",literal);
218+
return (ICONST);
219+
}
220+
165221
{xqstart}{
166222
BEGIN(xq);
167223
llen =0;
@@ -250,12 +306,18 @@ other.
250306
}
251307

252308
{integer}/{space}*-{number}{
309+
char* endptr;
310+
253311
BEGIN(xm);
254-
yylval.ival =atoi((char*)yytext);
312+
errno =0;
313+
yylval.ival =strtol((char *)yytext,&endptr,10);
314+
if (*endptr !='\0' || errno == ERANGE)
315+
elog(WARN,"Bad integer input '%s'",yytext);
255316
return (ICONST);
256317
}
257318
{real}/{space}*-{number} {
258319
char* endptr;
320+
259321
BEGIN(xm);
260322
errno =0;
261323
yylval.dval =strtod(((char *)yytext),&endptr);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp