复制 DBF/MDX 文件时出错

发布于 2024-10-16 07:27:43 字数 733 浏览 0 评论 0原文

我使用以下代码将 dbf/mdx 文件从一个文件夹复制到另一个文件夹:

procedure TfrmMain.MyCopyFile(S1, S2: string);
begin
   if not FileExists(S2) then
      CopyFile(PCHAR(S1), PCHAR(S2), true)
   else
      if Application.MessageBox(PCHAR('Overwrite existing file ' + S2 + '?'), 'File exists in folder',MB_YESNO + MB_DEFBUTTON1) = IDYES
          then CopyFile(PCHAR(S1), PCHAR(S2), false)
end;

当表名称保持不变时,代码可以正常工作。

如果我更改表的名称:

    MyCopyFile(CurPath + '\orders.dbf', NewPath + '\ordly.dbf');
    MyCopyFile(CurPath + '\orders.mdx', NewPath + '\ordly.mdx');

当我尝试打开 ordly.dbf 时,我收到一条错误消息:

表/索引头损坏。
文件:C:\DATA\2011\ORDLY.MDX

I use the following code to copy dbf/mdx files from one folder to another:

procedure TfrmMain.MyCopyFile(S1, S2: string);
begin
   if not FileExists(S2) then
      CopyFile(PCHAR(S1), PCHAR(S2), true)
   else
      if Application.MessageBox(PCHAR('Overwrite existing file ' + S2 + '?'), 'File exists in folder',MB_YESNO + MB_DEFBUTTON1) = IDYES
          then CopyFile(PCHAR(S1), PCHAR(S2), false)
end;

The code works fine when table name stays the same.

If I change the name of the table:

    MyCopyFile(CurPath + '\orders.dbf', NewPath + '\ordly.dbf');
    MyCopyFile(CurPath + '\orders.mdx', NewPath + '\ordly.mdx');

When I try to open ordly.dbf I get an error message:

Corrupt table/index header.
File: C:\DATA\2011\ORDLY.MDX

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2024-10-23 07:27:43

问题是由于 mdx 格式存储在关联的数据文件的名称(表名称)中。因为当您重命名 mdx 文件时,索引仍然指向数据文件的名称。

检查此链接以查看 mdx 文件的结构。

多个索引文件 (*.mdx) 的结构

 0 | Version number      *1|  ^
   |-----------------------|  |
 1 | Date of creation      |  |
 2 |      YYMMDD           |  |
 3 |                       |  |
   |-----------------------|  |
 4 | Data file name        | File
 5 | (no extension)        | Header
   :                       :  |
   :                       :  |
19 |                       |  |
   |-----------------------|  |
20 | Block size            |  |
   |                       |  |
   |-----------------------|  |
22 | Block size adder N    |  |
   |                       |  |
   |-----------------------|  |
24 | Production index flag |  |
   |-----------------------|  |
25 | No. of entries in tag |  | *2
   |-----------------------|  |
26 | Length of tag         |  | *3
   |-----------------------|  |
27 | (Reserved)            |  |
   |-----------------------|  |
28 | No.of tags in use     |  |
   |                       |  |
   |-----------------------|  |
30 | (Reserved)            |  |
   |                       |  |
   |-----------------------|  |
32 | No.of pages in tagfile|  |
   |                       |  |
   |                       |  |
35 |                       |  |
   |-----------------------|  |
36 | Pointer to first free |  |
   | page                  |  |
   |                       |  |
39 |                       |  |
   |-----------------------|  |
40 | No.of block available |  |
   |                       |  |
   |                       |  |
43 |                       |  |
   |-----------------------|  |
44 | Date of last update   |  |
   |      YYMMDD           |  |
46 |                       |  |
   |-----------------------|  |
47 | (Reserved)            |  |
   |-----------------------|  |
48 | (Garbage)             |  |
   :                       :  |
   :                       :  |
   |                       |  |        ___|=======================|
543|                       | _V___    / 0 | Tag header page no.   |
   |-----------------------|  |      /    |                       |
544| Tag table entries     | Tag    /     |                       |
   |                       | Table |    3 |                       |
   :.......................:  |    |      |-----------------------| Tag
   :                       :  |    |    4 | Tag name              | table
   :.......................:  |    |      :                       :
   :                       :  |   /       :                       :
   :                       :  |  /        |                       |
   :.......................:__|_/      14 |                       |
   :                       :  |           |-----------------------|
   :                       :  |        15 | Key format         *4 |
   :                       :  |           |-----------------------|
   :.......................:__|_       16 | Forward tag thread (<)|
   :                       :  | \         |-----------------------|
   :                       :  |  \     17 | Forward tag thread (>)|
   :                       :  |   \       |-----------------------|
   :                       :  |    |   18 | Backward tag thread *5|
   |                       |  |    |      |-----------------------|
   |                       |  |    |   19 | (Reserved)            |
M*N|                       |__V__  |      |-----------------------|
   |=======================|  ^    |   20 | Key type           *6 |
  0| Pointer to root page  |  |    |      |-----------------------|
   |                       |  |    |   21 | (Reserved)            |
   |                       |  |    |      :                       :
  3|                       |  |    |      :                       :
   |-----------------------|  |    |   31 |                       |
  4| File size in pages    | Tag   |      |-----------------------|
   |                       | header|   32 | (Garbage)             |
   |                       |  |    |      :                       :
  7|                       |  |    |      |                       |
   |-----------------------|  |     \  N  |                       |
  8| Key format         *7 |  |      \____|=======================|
   |-----------------------|  |
  9| Key type           *8 |  |
   |-----------------------|  |
 10| (Reserved)            |  |
   |                       |  |
   |-----------------------|  |
 12| Index key length   *9 |  |
   |                       |  |
   |-----------------------|  |
 14| Max.no.of keys/page   |  |
   |                       |  |
   |-----------------------|  |
 16| Secondary key type *10|  |
   |                       |  |
   |-----------------------|  |
 18| Index key item length |  |
   |                       |  |
   |-----------------------|  |
 20| (Reserved)            |  |
   |                       |  |
   |                       |  |
   |-----------------------|  |
 23| Unique flag           |  |
   |-----------------------|  |
   |                       |  |
   :                       :  |
   :                       :__V__
N*M|=======================|

the problem is due to the mdx format stores inside the name of the data file associated (table name). because that when you rename a mdxfile the index still points to the old name of data file.

check this link to see the structure of the mdx file.

The Structure of Multiple Index files (*.mdx)

 0 | Version number      *1|  ^
   |-----------------------|  |
 1 | Date of creation      |  |
 2 |      YYMMDD           |  |
 3 |                       |  |
   |-----------------------|  |
 4 | Data file name        | File
 5 | (no extension)        | Header
   :                       :  |
   :                       :  |
19 |                       |  |
   |-----------------------|  |
20 | Block size            |  |
   |                       |  |
   |-----------------------|  |
22 | Block size adder N    |  |
   |                       |  |
   |-----------------------|  |
24 | Production index flag |  |
   |-----------------------|  |
25 | No. of entries in tag |  | *2
   |-----------------------|  |
26 | Length of tag         |  | *3
   |-----------------------|  |
27 | (Reserved)            |  |
   |-----------------------|  |
28 | No.of tags in use     |  |
   |                       |  |
   |-----------------------|  |
30 | (Reserved)            |  |
   |                       |  |
   |-----------------------|  |
32 | No.of pages in tagfile|  |
   |                       |  |
   |                       |  |
35 |                       |  |
   |-----------------------|  |
36 | Pointer to first free |  |
   | page                  |  |
   |                       |  |
39 |                       |  |
   |-----------------------|  |
40 | No.of block available |  |
   |                       |  |
   |                       |  |
43 |                       |  |
   |-----------------------|  |
44 | Date of last update   |  |
   |      YYMMDD           |  |
46 |                       |  |
   |-----------------------|  |
47 | (Reserved)            |  |
   |-----------------------|  |
48 | (Garbage)             |  |
   :                       :  |
   :                       :  |
   |                       |  |        ___|=======================|
543|                       | _V___    / 0 | Tag header page no.   |
   |-----------------------|  |      /    |                       |
544| Tag table entries     | Tag    /     |                       |
   |                       | Table |    3 |                       |
   :.......................:  |    |      |-----------------------| Tag
   :                       :  |    |    4 | Tag name              | table
   :.......................:  |    |      :                       :
   :                       :  |   /       :                       :
   :                       :  |  /        |                       |
   :.......................:__|_/      14 |                       |
   :                       :  |           |-----------------------|
   :                       :  |        15 | Key format         *4 |
   :                       :  |           |-----------------------|
   :.......................:__|_       16 | Forward tag thread (<)|
   :                       :  | \         |-----------------------|
   :                       :  |  \     17 | Forward tag thread (>)|
   :                       :  |   \       |-----------------------|
   :                       :  |    |   18 | Backward tag thread *5|
   |                       |  |    |      |-----------------------|
   |                       |  |    |   19 | (Reserved)            |
M*N|                       |__V__  |      |-----------------------|
   |=======================|  ^    |   20 | Key type           *6 |
  0| Pointer to root page  |  |    |      |-----------------------|
   |                       |  |    |   21 | (Reserved)            |
   |                       |  |    |      :                       :
  3|                       |  |    |      :                       :
   |-----------------------|  |    |   31 |                       |
  4| File size in pages    | Tag   |      |-----------------------|
   |                       | header|   32 | (Garbage)             |
   |                       |  |    |      :                       :
  7|                       |  |    |      |                       |
   |-----------------------|  |     \  N  |                       |
  8| Key format         *7 |  |      \____|=======================|
   |-----------------------|  |
  9| Key type           *8 |  |
   |-----------------------|  |
 10| (Reserved)            |  |
   |                       |  |
   |-----------------------|  |
 12| Index key length   *9 |  |
   |                       |  |
   |-----------------------|  |
 14| Max.no.of keys/page   |  |
   |                       |  |
   |-----------------------|  |
 16| Secondary key type *10|  |
   |                       |  |
   |-----------------------|  |
 18| Index key item length |  |
   |                       |  |
   |-----------------------|  |
 20| (Reserved)            |  |
   |                       |  |
   |                       |  |
   |-----------------------|  |
 23| Unique flag           |  |
   |-----------------------|  |
   |                       |  |
   :                       :  |
   :                       :__V__
N*M|=======================|
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文