ODBC 如何存储可变长度的字符串数组?

发布于 2024-09-03 16:44:06 字数 276 浏览 0 评论 0原文

YANQ(又一个n00b问题)。

我已经成功地设计了我的数据库,定义了表和表。列。我什至有访问数据库的代码,耶!

现在,我在“MySql 周末速成班”中还没有学到一点。

假设我想存储“笔记”之类的东西,它是 TStringList 之类的东西。每次我向数据库提交一组新数据时,字符串列表可能是不同数量的字符串。

我应该如何最好地处理这个问题?我是否应该在写入时将字符串连接成一个,并在读回时将它们拆分?这样我就只需要一个 TEXT 列。

或者有更好的方法吗?

Y.A.N.Q. (yet another n00b question).

I have managed to design my db, defining tables & columns. I have even got code to access the db, yay!

Now, one bit that I haven't yet gotten to in the "MySql weekend crash course".

Let's say that I want to store something like "notes" which is a TStringList sort of thing. A list of strings which might be a different number of strings every time I submit a new set of data to the db.

How should I best handle that? Should I just concatenate the strings into one when writing and split them when reading back out? That way I would only need one TEXT column.

Or is there a preferred way?

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

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

发布评论

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

评论(1

久光 2024-09-10 16:44:06

这取决于您的应用程序。一种选择是拥有两个表,Notebook 和 Note,以及 1-many< /a> 他们之间的关系。所以一本笔记本可以有很多笔记。每个注释都包含一个字符串,可能还有创建日期,或者用于排序的其他内容。当然,笔记本实际上可以是任何桌子。

编辑:是的,我认为你走在正确的轨道上。它可能是:

Notebook:
  id INTEGER PRIMARY KEY AUTO_INCREMENT

Note:
  id INTEGER PRIMARY KEY AUTO_INCREMENT
  notebook_id INTEGER
  note_text VARCHAR(1024)

您可以重命名并向每个字段添加字段。例如,笔记本可以是任何需要附加注释的东西(例如项目),并且它可以具有其他项目属性(例如截止日期)。如果您希望能够通过 ID 以外的方式订购它们,请注意可以有一个日期。

It depends on your application.. One option is having two tables, Notebook and Note, and a 1-many relationship between them. So one notebook can have many notes. Each note consists of a string, and maybe a date created, or something else to use for ordering. Of course, Notebook could really be any table.

EDIT: Yes, I think you're on the right track. It could be:

Notebook:
  id INTEGER PRIMARY KEY AUTO_INCREMENT

Note:
  id INTEGER PRIMARY KEY AUTO_INCREMENT
  notebook_id INTEGER
  note_text VARCHAR(1024)

You could rename and add fields to each. For example, Notebook could be anything that needs notes attached (e.g. Project), and it could have other project attributes (e.g. a deadline). Note could have a date if you want to be able to order them other than by id.

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