

Games in mobile applications make heavy use of SQLite for storing their game status and then sync to a backend server periodically/based on a user trigger. Let's consider a real-world use case-games. import sqlite3Īn Example Tic-Tac-Toe Game Using Python and SQLite Now, let's connect to this database using our Python script and try to read these tables. pragma table_info is a function that gives more information about the table (i.e. tables gives me information about all of the tables.schema gives the information about a specific table. There are a ton of helper functions that SQLite provides to learn more about tables and the schema. We can see the records by doing a simple select * statement. Insert into testing values(101, 'Name2') insert into testing values(100, 'Name1') create table testing(id int, name text) Īnd then insert some rows into the table. Let's create a table for testing purposes. Creating Sample Tables and Running Basic Queries We can do so by using sqlite3 /path/to/file. Notice that I have connected directly to the database that I used from the Python script. The command line can be invoked by typing the command sqlite3.
#SQLITE FOR MAC OUTPUT DOWNLOAD#
For other platforms, we can download the CLI and other tools from the SQLite website itself.
#SQLITE FOR MAC OUTPUT MAC OS#
SQLite (version 3) comes pre-installed on Mac OS operating systems. Connecting to an SQLite Database from the Command Line Since it is an application library, there is no server and the database comes up and goes down with the connection initiated by the application running behind it. Configuring and Managing an SQLite DatabaseĪs we just saw, there is no configuration required to get our database set up. db is also optional-SQLite will just create a binary file with the name we provide it with. Keep in mind that the directory data needs to be created beforehand. This will create the sqlite.db file inside the data folder. We can customize the location of this file by just connecting to the database with its path. As we will see later, this file will be re-used whenever the application is started.

Once you run the above application, a sqlite.db file is automatically created at the project root level. Isn't this a breeze when compared to setting up a full-blown RDBMS? Where Are SQLite Databases Stored? The database is now created and we can create tables and insert data now. Let's go ahead and import Sqlite3 and then create our database: import sqlite3
#SQLITE FOR MAC OUTPUT INSTALL#
Sqlite3 comes packaged with Python by default and there is no need to install any additional libraries.
