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
170
votes
9 answers

Is there AUTO INCREMENT in SQLite?

I am trying to create a table with an auto-incrementing primary key in Sqlite3. I am not sure if this is really possible, but I am hoping to only have to designate the other fields. For example: CREATE TABLE people (id integer primary key auto…
ewok
  • 20,148
  • 51
  • 149
  • 254
170
votes
4 answers

Is an index needed for a primary key in SQLite?

When an integer column is marked as a primary key in an SQLite table, should an index be explicitly created for it as well? SQLite does not appear to automatically create an index for a primary key column, but perhaps it indexes it anyway, given its…
Marek Jedliński
  • 7,088
  • 11
  • 47
  • 57
170
votes
9 answers

Copying data from one SQLite database to another

I have 2 SQLite databases with common data but with different purposes and I wanted to avoid reinserting data, so I was wondering if it was possible to copy a whole table from one database to another?
Leonardo Marques
  • 3,721
  • 7
  • 36
  • 50
168
votes
12 answers

Android search with Fragments

Does somebody know of a tutorial or an example of how to implement the standard Android search interface with Fragments? In other words, is it possible to put a standard search with a SearchManager in a Fragment?
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
167
votes
6 answers

How can I add the sqlite3 module to Python?

Can someone tell me how to install the sqlite3 module alongside the most recent version of Python? I am using a Macbook, and on the command line, I tried: pip install sqlite but an error pops up.
Jin-Dominique
  • 3,043
  • 6
  • 19
  • 28
165
votes
3 answers

Sqlite LIMIT / OFFSET query

I have simple question with Sqlite. What is the difference between this: Select * from Animals LIMIT 100 OFFSET 50 and Select * from Animals LIMIT 100,50
Pablo
  • 1,651
  • 2
  • 11
  • 3
162
votes
7 answers

Select random row from a sqlite table

I have a sqlite table with the following schema: CREATE TABLE foo (bar VARCHAR) I'm using this table as storage for a list of strings. How do I select a random row from this table?
Alex_coder
  • 2,308
  • 2
  • 18
  • 15
161
votes
11 answers

Import CSV to SQLite

I'm trying to import a csv file to an SQLite table. Example csv: 1,2 5,6 2,7 Example command: sqlite> create table foo(a, b); sqlite> .separator , sqlite> .import test.csv foo Error: test.csv line 1: expected 2 columns of data but found 4 I'm not…
Molly Walters
  • 1,631
  • 3
  • 13
  • 7
160
votes
13 answers

How to delete SQLite database from Android programmatically

I would like to delete the database file from the Android file system programatically? Can I have a shell script launch adb which in turns runs a shell script in the Android space to do the database deletion? Can I get this done from within a JUnit…
Jim
  • 1,821
  • 2
  • 13
  • 7
160
votes
3 answers

How to use SQL Order By statement to sort results case insensitive?

I have a SQLite database that I am trying to sort by Alphabetical order. The problem is, SQLite doesn't seem to consider A=a during sorting, thus I get results like this: A B C T a b c g I want to get: A a b B C c g T What special SQL thing needs…
CodeFusionMobile
  • 14,812
  • 25
  • 102
  • 140
160
votes
6 answers

SQLite Reset Primary Key Field

I have a few tables in SQLite and I am trying to figure out how to reset the auto-incremented database field. I read that DELETE FROM tablename should delete everything and reset the auto-incremement field back to 0, but when I do this it just…
Nathan
  • 5,059
  • 16
  • 48
  • 61
158
votes
20 answers

SQLite in Android How to update a specific row

I've been trying to update a specific row for a while now, and it seems that there are two ways to do this. From what I've read and tried, you can just use the: execSQL(String sql) method or the: update(String table, ContentValues values, String…
EGHDK
  • 17,818
  • 45
  • 129
  • 204
155
votes
2 answers

SQLite string contains other string query

How do I do this? For example, if my column is "cats,dogs,birds" and I want to get any rows where column contains cats?
Joren
  • 9,623
  • 19
  • 63
  • 104
155
votes
6 answers

How to backup sqlite database?

What's the proper way to do it? Do I just copy the .sq3 file? What if there are users on the site and file is being written while it's being copied?
thelolcat
  • 10,995
  • 21
  • 60
  • 102
154
votes
2 answers

How do you rename a table in SQLite 3.0?

How do you rename a table in SQLite 3.0?
readonly
  • 343,444
  • 107
  • 203
  • 205