delphi 中的平面文件

发布于 2024-11-04 01:52:15 字数 231 浏览 5 评论 0原文

在我的应用程序中,我想使用文件来存储数据。我不想使用数据库或明文文件,目标是保存双精度值和整数值以及字符串,只是为了标识记录的名称;我只是需要将数据保存在磁盘上以生成报告。文件甚至可以增长到千兆字节。您建议使用什么格式?二进制?如果是这样,您知道哪个 vcl 组件/库最好用?我的目标是创建一个应用程序来创建和更新文件,而另一个工具将“吃掉”这些文件 按需为用户生成精美的 pdf 报告。你怎么认为?有什么想法或建议吗?

提前致谢。

In my application I want to use files for storing data. I don't want to use database or clear text file, the goal is to save double and integer values along with string just to identify the name of the record ; I simple need to save data on disk for generating reports. File can grow even to gigabyte. What format you suggest to use? Binary? If so what vcl component/library you know which is good to use? My goal is to create an application which creates and updates the files while another tool will "eat" those file
producing nice pdf reports for user on demand. What do you think? Any idea or suggestion?

Thanks in advance.

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

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

发布评论

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

评论(5

把人绕傻吧 2024-11-11 01:52:15

如果您不想重新发明轮子,您可以从我们这边找到您的任务所需的所有开源工具:

  • Synopse Big Table 用于存储大量数据 - 特别参见 TSynBigTableRecord 类,用于存储无限数量的字段记录,包括索引,如果需要 - 它肯定会比任何其他常规 SQL DB 更快并且使用更少的磁盘大小
  • Synopse SQLite3 Framework 如果您更愿意使用标准 SQLite 引擎进行存储 - 它带有完整的客户端/服务器 ORM
  • 从代码报告,包括 pdf 文件生成

具有完整的源代码,可从 Delphi 6 到 XE 运行。

我刚刚更新了框架的文档。 600多页,详细介绍了每个类的方法,并新增了增强的总体介绍。请参阅 SAD 文档。

更新:如果您打算使用 SQLite,您应该首先猜测数据将如何存储、将创建哪些索引以及 SQL 查询如何加速您的请求。读取每个请求的所有文件内容是一个坏主意:您应该更好地构造数据,以便单个 SQL 查询能够返回扩展的结果。有时,对数据使用附加值(例如临时总和或均值)是个好主意。还可以考虑使用SQLite3的RTree虚拟表,专门用于加速访问最小/最大多维数据:它可能会加快您的请求速度。

If you don't want to reinvent the wheel, you may find all needed Open Source tools for your task from our side:

  • Synopse Big Table to store huge amount of data - see in particular the TSynBigTableRecord class to store an unlimited number of records with fields, including indexes if needed - it will definitively be faster and use less disk size than any other regular SQL DB
  • Synopse SQLite3 Framework if you would rather use a standard SQLite engine for the storage - it comes with a full Client/Server ORM
  • Reporting from code, including pdf file generation

With full Source code, working from Delphi 6 up to XE.

I've just updated the documentation of the framework. More than 600 pages, with details of every class method, and new enhanced general introduction. See the SAD document.

Update: If you plan to use SQLite, you should first guess how the data will be stored, which indexes are to be created, and how a SQL query may speed up your requests. It's a bad idea to read all file content for every request: you should better structure your data so that a single SQL query would be able to return the expended results. Sometimes, using additional values (like temporary sums or means) to the data is a good idea. Also consider using the RTree virtual table of SQLite3, which is dedicated to speed up access to double min/max multi-dimensional data: it may speed up a lot your requests.

把梦留给海 2024-11-11 01:52:15

您不想使用完整的 SQL 数据库,并且您认为纯文本文件太简单。

介于两者之间的点包括:

  1. 不是完整的 SQL 数据库,而是更多的键值存储,从技术上讲不会是平面文件,但它确实提供了一个“键+值”列表,即可通过单个主键快速搜索。比如BSDDB。它的名称中有字母 D 和 B。在您看来,这是否使它成为一个数据库?因为它不是关系型数据库,也不做SQL。它只是一种二进制键值(哈希表)blob 存储机制,使用易于理解的二进制文件格式。就我个人而言,我不会开始一个新项目并使用此类别中的任何内容。

  2. 推荐:使用 SQL 但不如独立 SQL 数据库服务器那么大。例如,您可以使用 SQLite 和 delphi 包装器。它经过充分测试,并在许多 C/C++ 和 Delphi 应用程序中使用,并且比您自己使用的任何东西都更值得信赖。它是一个非常轻量级的嵌入式数据库,受到许多人的信任。

  3. 推出您自己的 ISAM 或 VLIR,随着时间的推移,它最终将演变成您自己的内部 DBMS。涉及多个文件,并且有索引,因此您可以快速查找数据,而无需将所有内容加载到内存中。不推荐。

  4. 最扁平的扁平二进制固定记录长度文件。您最初在问题中提到了 power basic,它有一个称为“随机访问文件”的东西,然后您从问题中删除了它。 可能是您正在寻找的内容,尤其是将仅追加写入作为主要操作。推出您自己的 TurboPascal 时代“记录文件”。如果您使用“FILE OF RECORD”类型,则会达到 2GB 限制,并且 Unicode 会出现问题。因此,请改用 TStream,例如这个。二进制文件格式有很多打击,特别是因为随着时间的推移,很难在不破坏读取旧文件的能力的情况下增长和扩展二进制文件格式。这就是为什么我建议您从乍一看似乎有些过分的(SQLite)开始,而不是推出自己的二进制解决方案。

    更新 2:更新问题以提及 PDF 以及听起来像是报告系统要求的内容后,我认为您确实应该使用真实数据库,但也许一种小型且易于使用的文件,例如 firebird 或 interbase。)

You don't want to use a full SQL database, and you think that a plain text file is too simple.

Points in between those include:

  1. Something that isn't a full SQL database, but more of a key-value store, would technically not be a flat file, but it does provide a single "key+value" list, that is quickly searchable on a single primary key. Such as BSDDB. It has the letter D and B in the name. Does that make it a database, in your view? Because it's not a relational database, and doesn't do SQL. It's just a binary key-value (hashtable) blob storage mechanism, using a well-understood binary file format. Personally, I wouldn't start a new project and use anything in this category.

  2. Recommended: Something that uses SQL but isn't as large as standalone SQL database servers. For example, you could use SQLite and a delphi wrapper. It is well tested, and used in lots of C/C++ and Delphi applications, and can be trusted more than anything you could roll yourself. It is a very light embedded database, and is trusted by many.

  3. Roll your own ISAM, or VLIR, which will eventually morph over time into your own in-house DBMS. There are multiple files involved, and there are indexes, so you can look up data fast without loading everything into memory. Not recommended.

  4. The most flat of flat binary fixed-record-length files. You mentioned originally in your question, power basic which has something called Random Access files, and then you deleted that from your question. Probably what you are looking for, especially for append-only write as the primary operation. Roll your own TurboPascal era "file of record". If you use the "FILE OF RECORD" type, you hit the 2gb limit, and there are problems with Unicode. So use TStream instead, like this. Binary file formats have a lot of strikes against them, especially since it is difficult to grow and expand your binary file format over time, without breaking your ability to read old files. This is a key reason why I would recommend you start out with what might at first seem like overkill (SQLite) instead of rolling your own binary solution.

    (Update 2: After updating the question to mention PDFs and what sounds like a reporting-system requirement, I think you really should be using a real database but perhaps a small and easy to use one, like firebird, or interbase.)

欢烬 2024-11-11 01:52:15

我建议使用TClientDataSet,并由生成程序使用它的SaveToFile() / SaveToStream()方法,以及LoadFromFile() / LoadFromStream() > 将“消耗”数据的程序的方法。这样,您仍然可以在不连接到任何外部数据库的情况下创建索引记录,同时将交换数据保留在单个文件中。

I would suggest using TClientDataSet, and use it's SaveToFile() / SaveToStream() methods by the generating program, and LoadFromFile() / LoadFromStream() methods for the program that will "consume" the data. That way, you can still make indexed records without connecting to any external database, all while keeping the interchange data in a single file.

青巷忧颜 2024-11-11 01:52:15
  1. 定义API以与您的平面文件一起使用,以便API可以通过单独的数据层以多种方式实现。
  2. 使用标准嵌入式 SQL 数据库(例如 SQLite 或 Firebird)实现 API。
  3. 只有当标准解决方案有问题时才想到自己的解决方案。
  1. Define API to work with your flat file, so that the API can be implemented by a separate data layer in many ways.
  2. Implement the API using standard embedded SQL database (ex SQLite or Firebird).
  3. Only if there is something wrong with the standard solution think of your own.
墨洒年华 2024-11-11 01:52:15

我使用 KBMMemtable - 请参阅 http://www.components4developers.com/ - 快速、可靠、一直围绕长时间 - 支持二进制和 CSV 流进出文件,以及索引、过滤器和许多其他好东西 - TClientDataSet 不能很好地处理大型数据集。

I use KBMMemtable - see http://www.components4developers.com/ - fast, reliable, been around a long time - supports binary and CSV streaming in and out of files, as well indexing, filters, and lots of other goodies - TClientDataSet will not do well with large datasets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文