Unity Package Manager compatible wrapper for SQLite databases.
This package is a fork of the source repo (https://github.com/rizasif/sqlite-unity-plugin), reorganized into Package Manager structure and published to OpenUPM.
This plugin can be used to access SQLite database for Unity projects. Supports desktop, Android and iOS devices.
The package is available on the openupm registry. It's recommended to install it via openupm-cli.
openupm add com.pixelwizards.sqlite
Add this to your project manifest.json
"com.pixelwizards.sqlite": "https://github.com/PixelWizards/com.pixelwizards.sqlite.git",
This package is also available via the OpenUPM scoped registry: https://openupm.com/packages/com.pixelwizards.sqlite
- This has been tested for
>= 2018.3
Check out https://github.com/sqlitebrowser/sqlitebrowser for an SQLite desktop client / database browser for creating / managing databases
Getting Started
- Import the correct namespaces.
using UnityEngine;
using System.Data;
using Mono.Data.Sqlite;
using System.IO;
- Open your database connection; if the database name (My_Database) does not exist it will be created.
string connection = "URI=file:" + Application.persistentDataPath + "/" + "My_Database";
IDbConnection dbcon = new SqliteConnection(connection);
dbcon.Open();
- Finally create a query to access your database.
IDbCommand dbcmd;
IDataReader reader;
dbcmd = dbcon.CreateCommand();
string q_createTable =
"CREATE TABLE IF NOT EXISTS " + "my_table" + " (" +
"id" + " INTEGER PRIMARY KEY, " +
"val" + " INTEGER )";
dbcmd.CommandText = q_createTable;
reader = dbcmd.ExecuteReader();
There is a sample project that uses this package available here: https://github.com/PixelWizards/com.pixelwizards.sqlite-example
Read this article on medium for more details on using SQLite with Unity.