Questions tagged [sqlite]

SQLite is an open-source software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world.

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.

SQLite is a relational database management system contained in a small (~350 KB) C programming library. In contrast to other database management systems, SQLite is not a separate process that is accessed from the client application, but an integral part of it.

SQLite is ACID-compliant and implements most of the SQL standard, using a dynamically and weakly typed SQL syntax that does not guarantee the domain integrity.

Making an MRE for SQLite questions on StackOverflow

Providing a minimal reproducible example for an SQLite-related question is most usefully and conveniently done by showing a few lines in SQLite syntax (i.e. some create table ... and insert ... which makes a tailored toy database with appropriate structure and sample data). Also consider making a db fiddle and sharing the link (there are multiple free such services out there; see, for example, this and this).

This way, potential answerers can easily recreate the database you used for demonstrating the problem and quickly and efficiently provide solution proposals that are supported by test runs and test output. Showing pictures of database viewers or table representations (even in ASCII art) does not provide the same benefits.

When seeking assistance with an SQL query, structure your query accordingly (see tips for asking a good SQL question).

If you already have created a database for demonstration purposes, consider using the .dump command of the SQLite commandline tool. It will automatically give you the lines for exactly recreating the database.

Getting familiar with the commandline tool also is a good way of avoiding all potential errors in whatever programming language is used to handle the database. With the commandline tool, you can inspect and analyse data and structure directly.

Mobile Apps

SQlite is commonly used to store data on Android, iOS, and Windows Phone apps since it has a simple implementation, easy to adapt, and quite fast.

Design

Unlike client-server database management systems, the SQLite engine has no standalone processes with which the application program communicates. Instead, the SQLite library is linked in and thus becomes an integral part of the application program.

The application program uses SQLite's functionality through simple function calls, which reduce latency in database access: function calls within a single process are more efficient than inter-process communication. SQLite stores the entire database as a single cross-platform file on a host machine.

References

Books

94030 questions
154
votes
13 answers

SQLite error 'attempt to write a readonly database' during insert?

I have a SQLite database that I am using for a website. The problem is that when I try to INSERT INTO it, I get a PDOException SQLSTATE[HY000]: General error: 8 attempt to write a readonly database I SSH'd into the server and checked permissions,…
Austin Hyde
  • 26,347
  • 28
  • 96
  • 129
153
votes
29 answers

OperationalError: database is locked

I have made some repetitive operations in my application (testing it), and suddenly I’m getting a weird error: OperationalError: database is locked I've restarted the server, but the error persists. What can it be all about?
dana
  • 5,168
  • 20
  • 75
  • 116
151
votes
11 answers

Sqlite: CURRENT_TIMESTAMP is in GMT, not the timezone of the machine

I have a sqlite (v3) table with this column definition: "timestamp" DATETIME DEFAULT CURRENT_TIMESTAMP The server that this database lives on is in the CST time zone. When I insert into my table without including the timestamp column, sqlite…
BrianH
  • 7,932
  • 10
  • 50
  • 71
151
votes
14 answers

Change SQLite database mode to read-write

How can I change an SQLite database from read-only to read-write? When I executed the update statement, I always got: SQL error: attempt to write a readonly database The SQLite file is a writeable file on the filesystem.
user143482
  • 2,341
  • 3
  • 15
  • 7
150
votes
7 answers

Is there type Long in SQLite?

I want to create a table with the column type Long instead of Integer. Is it possible?
Alex K
  • 5,092
  • 15
  • 50
  • 77
150
votes
19 answers

Importing a CSV file into a sqlite3 database table using Python

I have a CSV file and I want to bulk-import this file into my sqlite3 database using Python. the command is ".import .....". but it seems that it cannot work like this. Can anyone give me an example of how to do it in sqlite3? I am using windows…
Hossein
  • 40,161
  • 57
  • 141
  • 175
149
votes
6 answers

Execute SQLite script

I start up sqlite3 version 3.7.7, unix 11.4.2 using this command: sqlite3 auction.db where auction.db has not already been created. sqlite> auction.db < create.sql; gives me this error: near "auction": syntax error How can I run the script?
Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
148
votes
3 answers

How to create ENUM type in SQLite?

I need to convert a table from MySQL to SQLite, but I can't figure out how to convert an enum field, because I can't find ENUM type in SQLite. The aforementioned field is pType in the following table: CREATE TABLE `prices` ( `id` INT(11) NOT…
onedevteam.com
  • 3,838
  • 10
  • 41
  • 74
147
votes
12 answers

Difference between 2 dates in SQLite

How do I get the difference in days between 2 dates in SQLite? I have already tried something like this: SELECT Date('now') - DateCreated FROM Payment It returns 0 every time.
Johan
145
votes
5 answers

Get generated id after insert

I'm using the SQLite with Android, and I want to know the best way to get the generated id of the row I inserted. A solution I think makes a search after include, but it doesn't look the best way.
Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
144
votes
4 answers

SQLite select where empty?

In SQLite, how can I select records where some_column is empty? Empty counts as both NULL and "".
Timo Huovinen
  • 53,325
  • 33
  • 152
  • 143
144
votes
3 answers

Set default value of an integer column in SQLite

I am creating an SQLite database. db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_WORKED + " INTEGER, " + KEY_NOTE + " INTEGER);"); Is…
Born Again
  • 2,139
  • 4
  • 25
  • 27
143
votes
14 answers

SQLite DateTime comparison

I can't seem to get reliable results from the query against a sqlite database using a datetime string as a comparison as so: select * from table_1 where mydate >= '1/1/2009' and mydate <= '5/5/2009' how should I handle datetime comparisons to…
Brad
  • 20,302
  • 36
  • 84
  • 102
142
votes
4 answers

String concatenation does not work in SQLite

I am trying to execute a SQlite replace function, but use another field in the function. select locationname + '

' from location; In this snip, the result is a list of 0s. I would have expected a string with the text from locationname and the…

Ian Vink
  • 66,960
  • 104
  • 341
  • 555
141
votes
20 answers

How do I use regex in a SQLite query?

I'd like to use a regular expression in sqlite, but I don't know how. My table has got a column with strings like this: "3,12,13,14,19,28,32" Now if I type "where x LIKE '3'" I also get the rows which contain values like 13 or 32, but I'd like to…
cody
  • 6,389
  • 15
  • 52
  • 77