Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to store a one (unique) data element in SQLite?

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.

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.

like image 502
prosseek Avatar asked Jun 10 '10 00:06

prosseek


People also ask

How do I create a unique field in SQLite?

Introduction to SQLite UNIQUE constraint To define a UNIQUE constraint, you use the UNIQUE keyword followed by one or more columns. You can define a UNIQUE constraint at the column or the table level. Only at the table level, you can define a UNIQUE constraint across multiple columns.

What is Blob SQLite?

A blob is a SQLite datatype representing a sequence of bytes. It can be zero or more bytes in size. SQLite blobs have an absolute maximum size of 2GB and a default maximum size of 1GB. An alternate approach to using blobs is to store the data in files and store the filename in the database.

Can I store an array in SQLite?

SQLite arrays are not directly supported as a data type for columns in SQLite databases. In relational databases generally, an array is used to store rows with different key columns as an array dimension that means more than one key for a particular key. But in SQLite we cannot directly implement arrays in SQLite.


1 Answers

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> 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.

like image 175
Mark Rushakoff Avatar answered Oct 23 '22 06:10

Mark Rushakoff