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

Commitcda886f

Browse files
committed
SET var TO 'a=b'
^^ is supported by get_token now.(SET geqo TO 'on=XXX' works now).
1 parent541f185 commitcda886f

File tree

1 file changed

+127
-30
lines changed

1 file changed

+127
-30
lines changed

‎src/backend/tcop/variable.c

Lines changed: 127 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Routines for handling of 'SET var TO', 'SHOW var' and 'RESET var'
33
* statements.
44
*
5-
* $Id: variable.c,v 1.9 1997/05/20 10:31:42 vadim Exp $
5+
* $Id: variable.c,v 1.10 1997/06/02 11:00:57 vadim Exp $
66
*
77
*/
88

@@ -17,6 +17,7 @@
1717
externCost_cpu_page_wight_;
1818
externCost_cpu_index_page_wight_;
1919
externbool_use_geqo_;
20+
externint32_use_geqo_rels_;
2021
externbool_use_right_sided_plans_;
2122

2223
/*-----------------------------------------------------------------------*/
@@ -33,27 +34,92 @@ struct PGVariables PGVariables =
3334
};
3435

3536
/*-----------------------------------------------------------------------*/
36-
staticconstchar*get_token(char*buf,intsize,constchar*str)
37-
{
38-
if(!*str)
39-
returnNULL;
40-
41-
/* skip white space */
42-
while(*str&& (*str==' '||*str=='\t'))
43-
str++;
37+
staticconstchar*get_token(char**tok,char**val,constchar*str)
38+
{
39+
constchar*start;
40+
intlen=0;
4441

45-
/* copy until we hit white space or comma or end of string */
46-
while(*str&&*str!=' '&&*str!='\t'&&*str!=','&&size-->1)
47-
*buf++=*str++;
42+
*tok=*val=NULL;
4843

49-
*buf='\0';
44+
if ( !(*str) )
45+
returnNULL;
46+
47+
/* skip white spaces */
48+
while (*str==' '||*str=='\t' )
49+
str++;
50+
if (*str==','||*str=='=' )
51+
elog(WARN,"Syntax error near (%s): empty setting",str);
52+
if ( !(*str) )
53+
returnNULL;
5054

51-
/* skip white space and comma*/
52-
while(*str&& (*str==' '||*str=='\t'||*str==','))
53-
str++;
55+
start=str;
5456

55-
returnstr;
56-
}
57+
/*
58+
* count chars in token until we hit white space or comma
59+
* or '=' or end of string
60+
*/
61+
while (*str&&*str!=' '&&*str!='\t'
62+
&&*str!=','&&*str!='=' )
63+
{
64+
str++;
65+
len++;
66+
}
67+
68+
*tok= (char*)palloc (len+1);
69+
strncpy (*tok,start,len);
70+
(*tok)[len]='\0';
71+
72+
/* skip white spaces */
73+
while (*str==' '||*str=='\t' )
74+
str++;
75+
76+
if ( !(*str) )
77+
return (NULL);
78+
if (*str==',' )
79+
return (++str);
80+
81+
if (*str!='=' )
82+
elog(WARN,"Syntax error near (%s)",str);
83+
84+
str++;/* '=': get value */
85+
len=0;
86+
87+
/* skip white spaces */
88+
while (*str==' '||*str=='\t' )
89+
str++;
90+
91+
if (*str==','|| !(*str) )
92+
elog(WARN,"Syntax error near (=%s)",str);
93+
94+
start=str;
95+
96+
/*
97+
* count chars in token' value until we hit white space or comma
98+
* or end of string
99+
*/
100+
while (*str&&*str!=' '&&*str!='\t'&&*str!=',' )
101+
{
102+
str++;
103+
len++;
104+
}
105+
106+
*val= (char*)palloc (len+1);
107+
strncpy (*val,start,len);
108+
(*val)[len]='\0';
109+
110+
/* skip white spaces */
111+
while (*str==' '||*str=='\t' )
112+
str++;
113+
114+
if ( !(*str) )
115+
return (NULL);
116+
if (*str==',' )
117+
return (++str);
118+
119+
elog(WARN,"Syntax error near (%s)",str);
120+
121+
returnstr;
122+
}
57123

58124
/*-----------------------------------------------------------------------*/
59125
staticboolparse_null(constchar*value)
@@ -73,22 +139,48 @@ static bool reset_null(const char *value)
73139

74140
staticboolparse_geqo (constchar*value)
75141
{
76-
77-
if (strcasecmp (value,"on")==0 )
142+
constchar*rest;
143+
char*tok,*val;
144+
145+
rest=get_token (&tok,&val,value);
146+
if (tok==NULL )
147+
elog(WARN,"Value undefined");
148+
149+
if (rest )
150+
elog(WARN,"Unacceptable data (%s)",rest);
151+
152+
if (strcasecmp (tok,"on")==0 )
153+
{
154+
int32geqo_rels=_use_geqo_rels_;
155+
156+
if (val!=NULL )
157+
{
158+
geqo_rels=pg_atoi (val,sizeof(int32),'\0');
159+
if (geqo_rels <=1 )
160+
elog(WARN,"Bad value for # of relations (%s)",val);
161+
pfree (val);
162+
}
78163
_use_geqo_= true;
79-
elseif (strcasecmp (value,"off")==0 )
164+
_use_geqo_rels_=geqo_rels;
165+
}
166+
elseif (strcasecmp (tok,"off")==0 )
167+
{
168+
if (val!=NULL )
169+
elog(WARN,"Unacceptable data (%s)",val);
80170
_use_geqo_= false;
171+
}
81172
else
82-
elog(WARN,"Bad value for GEQO (%s)",value);
173+
elog(WARN,"Bad value for GEQO (%s)",value);
83174

175+
pfree (tok);
84176
return TRUE;
85177
}
86178

87179
staticboolshow_geqo ()
88180
{
89181

90182
if (_use_geqo_ )
91-
elog (NOTICE,"GEQO is ON");
183+
elog (NOTICE,"GEQO is ON begining with %d relations",_use_geqo_rels_);
92184
else
93185
elog (NOTICE,"GEQO is OFF");
94186
return TRUE;
@@ -102,6 +194,7 @@ static bool reset_geqo ()
102194
#else
103195
_use_geqo_= false;
104196
#endif
197+
_use_geqo_rels_=GEQO_RELS;
105198
return TRUE;
106199
}
107200

@@ -184,12 +277,15 @@ static bool reset_cost_index ()
184277
}
185278

186279
staticboolparse_date(constchar*value)
187-
{
188-
chartok[32];
280+
{
281+
char*tok,*val;
189282
intdcnt=0,ecnt=0;
190283

191-
while((value=get_token(tok,sizeof(tok),value))!=0)
192-
{
284+
while((value=get_token(&tok,&val,value))!=0)
285+
{
286+
if (val!=NULL )
287+
elog(WARN,"Syntax error near (%s)",val);
288+
193289
/* Ugh. Somebody ought to write a table driven version -- mjl */
194290

195291
if(!strcasecmp(tok,"iso"))
@@ -228,13 +324,14 @@ static bool parse_date(const char *value)
228324
{
229325
elog(WARN,"Bad value for date style (%s)",tok);
230326
}
231-
}
327+
pfree (tok);
328+
}
232329

233330
if(dcnt>1||ecnt>1)
234331
elog(NOTICE,"Conflicting settings for date");
235-
332+
236333
return TRUE;
237-
}
334+
}
238335

239336
staticboolshow_date()
240337
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp