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

Commit625d4b3

Browse files
committed
Let initdb detect the date order of the lc_time locale and initialize the
datestyle parameter of the new cluster accordingly.
1 parentcd8f3ec commit625d4b3

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

‎doc/TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ SQL Commands
566566
Clients
567567
=======
568568

569-
* Have initdb set the input DateStyle (MDY or DMY) based on locale?
569+
*-Have initdb set the input DateStyle (MDY or DMY) based on locale
570570
* Have pg_ctl look at PGHOST in case it is a socket directory?
571571
* Allow pg_ctl to work properly with configuration files located outside
572572
the PGDATA directory

‎doc/src/sgml/config.sgml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.37 2005/11/17 22:14:50 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.38 2005/12/09 15:51:13 petere Exp $
33
-->
44
<chapter Id="runtime-config">
55
<title>Server Configuration</title>
@@ -32,7 +32,7 @@ $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.37 2005/11/17 22:14:50 tgl Exp $
3232
<para>
3333
One way to set these parameters is to edit the file
3434
<filename>postgresql.conf</><indexterm><primary>postgresql.conf</></>,
35-
which is normally kept in the data directory. (<command>initdb</>
35+
which is normally kept in the data directory. (<application>initdb</>
3636
installs a default copy there.) An example of what this file might look
3737
like is:
3838
<programlisting>
@@ -3300,7 +3300,10 @@ SELECT * FROM parent WHERE key = 2400;
33003300
keywords <literal>US</>, <literal>NonEuro</>, and
33013301
<literal>NonEuropean</> are synonyms for <literal>MDY</>. See
33023302
<xref linkend="datatype-datetime"> for more information. The
3303-
default is <literal>ISO, MDY</>.
3303+
built-in default is <literal>ISO, MDY</>, but
3304+
<application>initdb</application> will initialize the
3305+
configuration file with a setting that corresponds to the
3306+
behavior of the chosen <varname>lc_time</varname> locale.
33043307
</para>
33053308
</listitem>
33063309
</varlistentry>

‎src/bin/initdb/initdb.c

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
* Portions taken from FreeBSD.
4444
*
45-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.100 2005/11/22 18:17:28 momjian Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.101 2005/12/09 15:51:14 petere Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -57,11 +57,13 @@
5757
#ifdefHAVE_LANGINFO_H
5858
#include<langinfo.h>
5959
#endif
60+
#include<time.h>
6061

6162
#include"libpq/pqsignal.h"
6263
#include"mb/pg_wchar.h"
6364
#include"getaddrinfo.h"
6465
#include"getopt_long.h"
66+
#include"miscadmin.h"
6567

6668
#ifndefHAVE_INT_OPTRESET
6769
intoptreset;
@@ -186,6 +188,7 @@ static void make_postgres(void);
186188
staticvoidtrapsig(intsignum);
187189
staticvoidcheck_ok(void);
188190
staticchar*escape_quotes(constchar*src);
191+
staticintlocale_date_order(constchar*locale);
189192
staticboolchklocale(constchar*locale);
190193
staticvoidsetlocales(void);
191194
staticvoidusage(constchar*progname);
@@ -1195,6 +1198,20 @@ setup_config(void)
11951198
snprintf(repltok,sizeof(repltok),"lc_time = '%s'",lc_time);
11961199
conflines=replace_token(conflines,"#lc_time = 'C'",repltok);
11971200

1201+
switch (locale_date_order(lc_time)) {
1202+
caseDATEORDER_YMD:
1203+
strcpy(repltok,"datestyle = 'iso, ymd'");
1204+
break;
1205+
caseDATEORDER_DMY:
1206+
strcpy(repltok,"datestyle = 'iso, dmy'");
1207+
break;
1208+
caseDATEORDER_MDY:
1209+
default:
1210+
strcpy(repltok,"datestyle = 'iso, mdy'");
1211+
break;
1212+
}
1213+
conflines=replace_token(conflines,"#datestyle = 'iso, mdy'",repltok);
1214+
11981215
snprintf(path,sizeof(path),"%s/postgresql.conf",pg_data);
11991216

12001217
writefile(path,conflines);
@@ -2052,6 +2069,60 @@ escape_quotes(const char *src)
20522069
returnresult;
20532070
}
20542071

2072+
/*
2073+
* Determine likely date order from locale
2074+
*/
2075+
staticint
2076+
locale_date_order(constchar*locale)
2077+
{
2078+
structtmtesttime;
2079+
charbuf[128];
2080+
char*posD;
2081+
char*posM;
2082+
char*posY;
2083+
char*save;
2084+
size_tres;
2085+
intresult;
2086+
2087+
result=DATEORDER_MDY;/* default */
2088+
2089+
save=setlocale(LC_TIME,NULL);
2090+
if (!save)
2091+
returnresult;
2092+
save=xstrdup(save);
2093+
2094+
setlocale(LC_TIME,locale);
2095+
2096+
memset(&testtime,0,sizeof(testtime));
2097+
testtime.tm_mday=22;
2098+
testtime.tm_mon=10;/* November, should come out as "11" */
2099+
testtime.tm_year=133;/* 2033 */
2100+
2101+
res=strftime(buf,sizeof(buf),"%x",&testtime);
2102+
2103+
setlocale(LC_TIME,save);
2104+
free(save);
2105+
2106+
if (res==0)
2107+
returnresult;
2108+
2109+
posM=strstr(buf,"11");
2110+
posD=strstr(buf,"22");
2111+
posY=strstr(buf,"33");
2112+
2113+
if (!posM|| !posD|| !posY)
2114+
returnresult;
2115+
2116+
if (posY<posM&&posM<posD)
2117+
result=DATEORDER_YMD;
2118+
elseif (posD<posM)
2119+
result=DATEORDER_DMY;
2120+
else
2121+
result=DATEORDER_MDY;
2122+
2123+
returnresult;
2124+
}
2125+
20552126
/*
20562127
* check if given string is a valid locale specifier
20572128
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp