如何更改 Interbase 现有数据库的字符集
我们有一个数据库,我们的客户端是用Delphi 2007编写的。使用最新的Interbase 2009。该数据库很旧,我相信它是在 2002 年左右创建的,现在超过 25 GB。最近我发现在 IBConsole
upper('åäö')
中生成 'åäö'。应该是“ÅäÖ”。这是英文字母中缺失的瑞典字符。
我搜索了该主题并找到了这个链接。 重要的部分是:
如何更改默认字符 一组现有数据库?有 没有受支持的方法来执行此操作。你 应该重新创建数据库 元数据。
本博客由 Craig Stuntz 于 2004 年 6 月 29 日撰写,我希望 Interbase 从那时起就不断发展,并且有一种方法可以轻松更改 Interbase 2009 的字符集。如果不可能的话可以从 gbk 备份文件中完成吗?最后一个选项是创建一个具有正确字符集的全新数据库,并以某种方式从旧数据库中提取数据。
所以我有两个问题。
- 更改字符集的最简单方法是什么?
- 我应该选择什么字符集 upper('åäö') = 'ÅäÖ'
编辑: 正如克雷格所说,除了复制识别字符集的数据之外,没有真正的方法。所以我选择另一种方式。
vName := AnsiUpperCase(Nametosearch);
MakeCharLowercase(vName, 'åäö');
// Then use vName when search in database.
procedure TDuplicateDeptForm.MakeCharLowercase(var aName: String; aCharSet: String);
var
vIndex, i: Integer;
vChar: String;
begin
for i := 1 to Length(aCharSet) do
begin
vChar := AnsiUpperCase(aCharSet[i]);
repeat
vIndex := AnsiPos(vChar, aName);
if vIndex > 0 then
aName[vIndex] := AnsiLowerCase(vChar)[1];
until vIndex = 0;
end;
end;
在这种情况下,这只是将瑞典语字符转换回小写,因为这是我从 Interbase 获得的结果。也许不是最好的解决方案,但我认为它有效。
We have a database and our client is written with Delphi 2007. The latest Interbase 2009 is used. The database is old, I believe it was created around 2002 and is now over 25 GB. Recently I discovered that in IBConsole
upper('åäö')
generate 'åäö'. It should be 'ÅÄÖ'. This is swedish characters that are missing in the English alphabet.
I searched about the subject and found this link.
The important part is:
How Can I Change the Default Character
Set of an Existing Database? There is
no supported way to do this. You
should recreate the database from
metadata.
This blog was written 2004-06-29 by Craig Stuntz, My hope is that Interbase has evolved since that and there is a way to change the characterset for Interbase 2009 with little effort. If not possible can it be done from a gbk backup file ? The last option is to create a completely new database with the right characterset and somehow pump data from the old one.
So I have 2 questions.
- What is the easiest way to change characterset ?
- What characterset should I choose to have upper('åäö') = 'ÅÄÖ'
EDIT: As Craig said there is no real way except copy the data that are aware the charset. So I choose another way.
vName := AnsiUpperCase(Nametosearch);
MakeCharLowercase(vName, 'åäö');
// Then use vName when search in database.
procedure TDuplicateDeptForm.MakeCharLowercase(var aName: String; aCharSet: String);
var
vIndex, i: Integer;
vChar: String;
begin
for i := 1 to Length(aCharSet) do
begin
vChar := AnsiUpperCase(aCharSet[i]);
repeat
vIndex := AnsiPos(vChar, aName);
if vIndex > 0 then
aName[vIndex] := AnsiLowerCase(vChar)[1];
until vIndex = 0;
end;
end;
This simply convert back Swedish characters in this case back to lowercase as this is the result I get from Interbase. Maybe not the nicest solution but I think it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个名为 FBClone 的免费命令行工具实用程序:
它能够通过更改字符集来重新创建数据库。
该项目使用UIB组件,因此可以使用Interbase或Firebird。
http://code.google.com/p/fbclone/
There is a free command line tool utility named FBClone:
It is able to recreate your database changing the character set.
The project use UIB components, so it is able to use Interbase or Firebird.
http://code.google.com/p/fbclone/
对于瑞典语,请使用 ISO-8859-1 或 UNICODE。我不熟悉在 IB 2009 中更改现有数据库中默认字符集的任何新方法。当您考虑所涉及的内容时,您会发现无论如何您都会重新创建数据库;您将更改数据库中所有文本的存储格式!
提取数据的最简单方法可能是专用数据泵,例如 DB Workbench 中的数据泵。为此,您需要“专业”版本,但可以免费试用以查看它是否有效。再次强调,您可能无法直接复制数据;你必须以一种字符集感知的方式来完成它。这就是为什么您应该始终从欧洲人那里购买数据库管理工具。 :)
For Swedish use ISO-8859-1 or UNICODE. I am not familiar with any new way to change the default charset in existing DBs in IB 2009. When you think about what's involved you'll see you'd be recreating the DB anyway; you'd be changing the storage format of all text in the DB!
Easiest way to pump the data is probably a dedicated data pump like the one in DB Workbench. You need the "Pro" edition for this, but there's a free trial to see if it works. Again, consider that you may not be able to just directly copy data; you'll have to do it in a charset-aware way. This is why you should always buy your DB management tool from a European person. :)