有没有办法在SQLite中存储一个(唯一的)数据元素?

时间:2022-06-01 21:39:03

I need to use SQLite database file as a file for storing information, and I want to store the version of the file in the SQLite database file.

我需要使用SQLite数据库文件作为存储信息的文件,我想将该文件的版本存储在SQLite数据库文件中。

How can I do this? I mean, how to store unique (only one) data in SQLite? I don't want to use store the info by making table for this, as the version info is just one number.

我怎样才能做到这一点?我的意思是,如何在SQLite中存储唯一(仅一个)数据?我不想通过为此创建表来存储信息,因为版本信息只是一个数字。

1 个解决方案

#1


12  

For SQLite, which is an embedded database, after all, there's nothing wrong with using a single table for holding a unique value like this.

毕竟,对于SQLite来说,这是一个嵌入式数据库,使用单个表来保存这样的唯一值没有任何问题。

sqlite> CREATE TABLE AppVersion (version);
sqlite> INSERT INTO AppVersion VALUES('1.0');
sqlite> SELECT * FROM AppVersion;
1.0
sqlite> UPDATE AppVersion SET version='1.1';
sqlite> SELECT * FROM AppVersion;
1.1

It's an embedded database. You expect good performance when you use it, not perfect performance. A single extra table (holding only a single row ever) shouldn't make any difference to any reasonable application.

这是一个嵌入式数据库。您希望在使用它时获得良好的性能,而不是完美的性能。一个额外的表(只保留一行)不应对任何合理的应用程序产生任何影响。

#1


12  

For SQLite, which is an embedded database, after all, there's nothing wrong with using a single table for holding a unique value like this.

毕竟,对于SQLite来说,这是一个嵌入式数据库,使用单个表来保存这样的唯一值没有任何问题。

sqlite> CREATE TABLE AppVersion (version);
sqlite> INSERT INTO AppVersion VALUES('1.0');
sqlite> SELECT * FROM AppVersion;
1.0
sqlite> UPDATE AppVersion SET version='1.1';
sqlite> SELECT * FROM AppVersion;
1.1

It's an embedded database. You expect good performance when you use it, not perfect performance. A single extra table (holding only a single row ever) shouldn't make any difference to any reasonable application.

这是一个嵌入式数据库。您希望在使用它时获得良好的性能,而不是完美的性能。一个额外的表(只保留一行)不应对任何合理的应用程序产生任何影响。