| wwashington |
2004-8-13 07:26 | |
PostgreSQL 8.0 beta working
patch(下载)
论坛不支持 zip
附件,需要的朋友到这个地址下载,欢迎提出批评指正意见. http://wwashington.51.net/software/patches/pg80d_dif.zip
-----------------------------------------------------------------------------
Subject:
如何解决中文环境下 PostgreSQL 8.0 beta 的 token 和 timezone 问题 Author :
Wwashington@smth bbs Release: 2004/08/13
[前言] PostgreSQL
是最强大的开放源码数据库,目前的 7.5 dev 突然变成 8.0 beta 了。既然是 beta
版肯定存在不少问题,导致使用不便甚至无法安装。我这篇文档是针对最近的 2004/08/12 版
postgresql-snapshot.tar.gz 制作的,其他版本请大家自行研究,但基本原理不变。
[下载]
http://mirrors.isc.org/pub/postgresql/dev/postgresql-snapshot.tar.gz
[注意]
目前已经发现 MinGW 的 gcc 3.4.0 会引起 postgres.exe 在 psql 终端使用 \dp 时报错,建议采用
gcc 3.3.3 或更低版本编译 postgresql 8.0 beta。感谢 ChinaUnix 论坛上 bitbird
的建议。
Part A. 故障描述
1) FATAL: syntax error in
file "E:/Unix/Sys/Pgsql/data/postgresql.conf" line 261, near
token "s"
2) WARNING: could not find a match for
Windows timezone "中国标准时间"
Part B. 故障分析
1) initdb -U
postgres -D "E:/Unix/Sys/Pgsql/data" -L "E:/Unix/Sys/Pgsql/share"
--noclean 使用这个脚本初始化,发现 near token "s" 错误,不删除错误配置,发现问题在
Chinese_People's,配置文件里的 'Chinese_People's Republic of China.936' 应该是
'Chinese_People\'s Republic of China.936',第二个 '
号不是结束符,却过早的结束了整个字串,所以要加上转义符 \ 号。
2) initdb -U postgres -D
"E:/Unix/Sys/Pgsql/data" -L "E:/Unix/Sys/Pgsql/share"
--locale=C 对于第一个问题,可以用上面的办法初始化,但是又出现了第二个问题,也就是 timezone
无法匹配
Part C. 故障解决
1) 经研究,token 问题是因为
src/bin/initdb/initdb.c 里面缺少了语法分析。现在我已完成真正支持多语言的补丁,工作原理是预先扫描
lc_messages、lc_monetary、lc_numeric、lc_time 的 string
里是否含有单引号(即'号),如果有则在前面增加反斜杠(即\号)。这个\号的存在原因是 conf 文件采用的是 Unix
风格的正则表达式(sed、perl 的语法基础)。
------->;
/* * check
if given string is a valid locale detecting * whether contains a
' symbol by Wwashington @ Smth * (I will take responsibility for
it :-) */ static bool cfglocale(const char
*locale) { bool
ret;
char
loc_temp[128]; int
len, i,
j;
ret = false; j=0; len =
strlen(locale);
for (i=0;i<len;i++)
{ if (locale[i]=='\'')
{ ret=true;
loc_temp[j++]='\\';
}
loc_temp[j++]=locale[i];
}
/* should we exit here?
*/ if (ret)
sprintf(locale,"%s",
loc_temp);
return
ret; }
------->;
if
(cfglocale(lc_messages))
fprintf(stderr, _("checking\npostgresql.conf: parameter updated
-->; lc_messages\n"));
if
(cfglocale(lc_monetary))
fprintf(stderr, _("postgresql.conf: parameter updated -->;
lc_monetary\n"));
if (cfglocale(lc_numeric))
fprintf(stderr,
_("postgresql.conf: parameter updated -->;
lc_numeric\n"));
if
(cfglocale(lc_time))
fprintf(stderr, _("postgresql.conf: parameter updated -->;
lc_time\n"));
2) 经研究,timezone 问题是因为 src/timezone/pgtz.c 按英文处理
locale 的名称,但是系统自动检测的是中文信息,所以必须增加一个针对本地语言的扫描,把发生错误的 locale
做一个合适的对应。我已经写好一个完整的函数,但是只包含中文的情况,因为我手头没有其他语种的系统,但是只要能看懂这个补丁,将来在任何语言环境发生
timezone 错误都可以迅速的修正了。
------->;
/* * check if
given Windows timezone is a valid locale * to meet the English
catalog by Wwashington @ Smth * (I will take responsibility for
it :-) */ static bool scanzone(const char
*locale) { bool
ret;
ret = false;
if (strcmp(locale, "中国标准时间")==0
) {
ret=true;
sprintf((char
*)locale, "China Standard Time");
}
return ret; }
------->;
memset(tzname, 0, sizeof(tzname));
strftime(tzname, sizeof(tzname)-1, "%Z", tm);
scanzone(tzname);
Part D. 补丁使用
1) 补丁的制作,把原文件所在目录改名为
src_old,新文件所在目录改名为 src_new
diff -Nur
src_old/bin/initdb/initdb.c src_new/bin/initdb/initdb.c >;
initdb.dif diff -Nur src_old/timezone/pgtz.c
src_new/timezone/pgtz.c
>; pgtz.dif
2) 补丁的应用,首先要把 snapshot 展开到
/src/sql (在 /etc/fstab 里定义 /src),然后把对应的补丁文件拷贝到原文件所在的目录,然后就可以用 patch
命令来打补丁了。
alias cdp='cd
/src/sql/postgresql-snapshot'
cdp cd
src/bin/initdb/ patch --verb < initdb.dif
cdp cd
src/timezone/ patch --verb < pgtz.dif |
| wwashington |
2004-8-13 07:48 | |
PostgreSQL 8.0 beta working
patch(下载)
完整版在下面,用法同 laser
的文档.因空间关系,只保留三天,下周一删除. http://wwashington.51.net/software/patches/Pgsql-80b1.rar |
| wwashington |
2004-8-16 02:22 | |
PostgreSQL 8.0 beta working
patch(下载)
[quote][i]原帖由 "wwashington"
发表:[/i] 完整版在下面,用法同 laser
的文档.因空间关系,只保留三天,下周一删除. http://wwashington.51.net/software/patches/Pgsql-80b1.rar ...... 呵呵,根据朋友的建议,多保留一周.没办法,我买的空间小啊. [/quote] 呵呵,我已经把
snap0825 的 binary 放上去了。空间还够,继续保留。 |
| wwashington |
2004-9-1 03:27 | |
PostgreSQL 8.0 beta working
patch(下载)
http://www.hagander.net/pgsql/win32snap/ http://www.hagander.net/pgsql/win32snap/postgres_win32_7.5_devel.zip
除了
laser 和我做的版本,上面的网站也有 win32 binary 下载。 但是跟 laser 的一样,hagander
的版本也是有 token 和 timezone 问题,只要你用 initdb 不带参数以及 set TZ=xx
不对就会发生问题。
如果用 hagander 的版本,我试过了应该这样用。其他环境变量如 PGHOME、PGDATA
照旧,按 laser 的文档或我的文档。
1) set TZ=PRC 2) initdb
--locale=C |
| wwashington |
2004-9-4 05:09 | |
PostgreSQL 8.0 beta working
patch(下载)
向大家报告一个好消息,已经把补丁发给 PostgreSQL
开发组了。 希望老外不嫌弃咱们中国人的土智慧,在正式版里集成这个补丁。 |
| wwashington |
2004-10-8 03:43 | |
PostgreSQL 8.0 beta working
patch(下载)
发件人 : Bruce Momjian
<pgman@xxx>; 发送 : 2004年10月8日 0:52:37 收件人
: Zhong Jacky <jackyzhongxp@xxx>; 抄送
: pgsql-bugs@postgresql.org 主题 : Re:
[BUGS] pgsql 8.0 beta1 patch for token and timezone
| | |
收件箱
I have reviewed your
patch. I found that the first patch was
definitely needed. Your code adds escapes for single
quotes in locale names placed in postgresql.conf. I
also added code to escape a literal backslash
as well. I re-factored your code and applied the
attached patch.
Your second patch to pgtz.c is not needed
anymore because we have a more general solution added on
September 1:
/* *
Localized Windows versions return localized names for the
* timezone. Scan the registry to find the English
name, * and then try matching against
our table again. */
memset(localtzname, 0, sizeof(localtzname)); if
(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time
Zones",
0,
KEY_READ,
&rootKey) !=
ERROR_SUCCESS)
Thanks.
---------------------------------------------------------------------------
Zhong
Jacky wrote: >; Hi pgsql-bugs, >; >;
I'm a Chinese and I am using WinXp Chs to compile pgsql 8.0 beta
1 >; in the MinGW environment. I found 2 bugs and fix them,
maybe you can >; merge the patch into the offical release,
thanks. >; >; Part A) Below is the two
bugs occur when we run initdb under WinXp Chs. >;
>; 1) FATAL: syntax error in file
"E:/Unix/Sys/Pgsql/data/postgresql.conf" >; >; line
261, near token "s" >; >;
Reason: the string 'Chinese_People's Republic of China.936' should
be >; 'Chinese_People\'s Republic of China.936', otherwise
token mismatch. Plese >; remember the regular expression like
sed and awk under Unix. >; >;
Patch: I wrote a function to detect ' in string and insert a \
symbol >; >; 2) WARNING: could
not find a match for Windows timezone "??????" >;
>; Reason: "??????" is the string
stands for "China Standard >; Time", >; which shows in
Chinese language. >; >;
Patch: use a scanzone() function to find and convert timezone to
the >; English string in win32_tzmap[]. I can fix only Chinese
because I only have >; WinXp Chs operating system, people can
fix others in similar way. >; >; Part B)
You can visit these 2 websites for more detail and get
patch. >; 1)
http://blog.csdn.net/chaoyuebetter/archive/2004/08/13/73785.aspx >;
2)
http://www.smth.edu.cn/bbsgcon.php?board=NewSoftware&num=2547 >;
>; Part C) The patch is based on snap0812, but
can work on snap0825, etc. >; >; Regards, >;
Jacky |
| wwashington |
2004-10-8 03:45 | |
PostgreSQL 8.0 beta working
patch(下载)
发件人 : Tom Lane <tgl@xxx>;
发送 : 2004年10月8日 1:17:56 收件人 : Bruce
Momjian <pgman@xxx>; 抄送 : Zhong Jacky
<jackyzhongxp@xxx>;, pgsql-bugs@postgresql.org 主题
: Re: [BUGS] pgsql 8.0 beta1 patch for token and
timezone | | |
收件箱
Bruce Momjian
<pgman@candle.pha.pa.us>; writes: >; + /* >;
+ * Escape any single quotes or backslashes in
locale >; + */ >; + static void >; +
escape_locale(char **locale) >; + { >; +
int
len = strlen(*locale), >; +
i, j; >; +
char
*loc_temp = xmalloc(len * 2); >; +
>; + for (i
= 0, j = 0; i < len; i++) >; +
{ >; +
if ((*locale)[i] == '\'' || (*locale)[i] == '\\') >; +
loc_temp[j++] = '\\'; >; +
loc_temp[j++] =
(*locale)[i]; >; + } >; +
*locale = loc_temp; >; +
}
Surely this is quite broken. You need to xmalloc
one more byte and add a '\0'.
regards, tom
lane |
| wwashington |
2004-10-8 03:46 | |
PostgreSQL 8.0 beta working
patch(下载)
发件人 : Bruce Momjian
<pgman@xxx>; 发送 : 2004年10月8日 1:29:11 收件人
: Tom Lane <tgl@xxx>; 抄送 : Zhong
Jacky <jackyzhongxp@xxx>;, pgsql-bugs@postgresql.org 主题
: Re: [BUGS] pgsql 8.0 beta1 patch for token and timezone
| | |
收件箱
OK,
fixed.
---------------------------------------------------------------------------
Tom
Lane wrote: >; Bruce Momjian <pgman@candle.pha.pa.us>;
writes: >; >; + /* >; >; + * Escape any
single quotes or backslashes in locale >; >;
+ */ >; >; + static void >; >; +
escape_locale(char **locale) >; >; + { >; >; +
int
len =
strlen(*locale), >; >; +
i, j; >; >; +
char
*loc_temp = xmalloc(len * 2); >; >; +
>; >; + for (i = 0, j =
0; i < len; i++) >; >; +
{ >; >; +
if ((*locale)[i] == '\'' || (*locale)[i] == '\\') >;
>; +
loc_temp[j++] = '\\'; >; >; +
loc_temp[j++] = (*locale)[i]; >; >; +
} >; >; + *locale =
loc_temp; >; >; + } >; >; Surely this is quite
broken. You need to xmalloc one more byte and >;
add a '\0'. >; >;
regards, tom
lane >; >; ---------------------------(end of
broadcast)--------------------------- |
|
|
PostgreSQL 8.0 beta working
patch(下载)
牛人! |
| wwashington |
2004-10-8 04:43 | |
PostgreSQL 8.0 beta working
patch(下载)
Sam 老兄果酱了,为人民服务是快乐的。爱生活,爱
ChinaUnix。 |
Copyright ©
2001-2005 ChinaUnix.net All Rights Reserved
联系我们:
感谢所有关心和支持过ChinaUnix的朋友们 京ICP证041476号 |