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

Commit0f5651a

Browse files
committed
Have boolean pset values checked against typical boolean values, rather
than only 'off'.
1 parent053948a commit0f5651a

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

‎src/bin/psql/variables.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.28 2008/01/01 19:45:56 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.29 2008/05/07 02:33:52 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -48,21 +48,48 @@ GetVariable(VariableSpace space, const char *name)
4848
returnNULL;
4949
}
5050

51+
/*
52+
* Try to interpret value as boolean value. Valid values are: true,
53+
* false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
54+
*/
5155
bool
52-
ParseVariableBool(constchar*val)
56+
ParseVariableBool(constchar*value)
5357
{
54-
if (val==NULL)
58+
size_tlen;
59+
60+
if (value==NULL)
5561
return false;/* not set -> assume "off" */
56-
if (pg_strcasecmp(val,"off")==0)
57-
return false;/* accept "off" or "OFF" as true */
5862

59-
/*
60-
* for backwards compatibility, anything except "off" or "OFF" is taken as
61-
* "true"
62-
*/
63+
len=strlen(value);
64+
65+
if (pg_strncasecmp(value,"true",len)==0)
66+
return true;
67+
elseif (pg_strncasecmp(value,"false",len)==0)
68+
return false;
69+
elseif (pg_strncasecmp(value,"yes",len)==0)
70+
return true;
71+
elseif (pg_strncasecmp(value,"no",len)==0)
72+
return false;
73+
/* 'o' is not unique enough */
74+
elseif (pg_strncasecmp(value,"on", (len>2 ?len :2))==0)
75+
return true;
76+
elseif (pg_strncasecmp(value,"off", (len>2 ?len :2))==0)
77+
return false;
78+
elseif (pg_strcasecmp(value,"1")==0)
79+
return true;
80+
elseif (pg_strcasecmp(value,"0")==0)
81+
return false;
82+
else
83+
{
84+
/* NULL is treated as false, so a non-matching value is 'true' */
85+
psql_error("unrecognized boolean value; assuming \"on\".\n");
86+
return true;
87+
}
88+
/* suppress compiler warning */
6389
return true;
6490
}
6591

92+
6693
/*
6794
* Read numeric variable, or defaultval if it is not set, or faultval if its
6895
* value is not a valid numeric string. If allowtrail is false, this will

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp