coryleach / UnitySQLite

SQLite Package for Unity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gameframe.SQLite 👋

Codacy Badge GitHub release (latest by date including pre-releases) openupm GitHub

twitter

SQLite Package

Quick Package Install

Using UnityPackageManager (for Unity 2019.3 or later)

Open the package manager window (menu: Window > Package Manager)
Select "Add package from git URL...", fill in the pop-up with the following link:
https://github.com/coryleach/UnitySQLite.git#1.0.2

Using UnityPackageManager (for Unity 2019.1 or later)

Find the manifest.json file in the Packages folder of your project and edit it to look like this:

{
  "dependencies": {
    "com.gameframe.sqlite": "https://github.com/coryleach/UnitySQLite.git#1.0.2",
    ...
  },
}

Usage

using Mono.Data.SqliteClient;

// Create database
string path = Application.persistentDataPath + "/" + "My_Test_Database";
string connection = "URI=file:" + path;

// Open connection
IDbConnection dbcon = new SqliteConnection(connection);
dbcon.Open();

// Create table
IDbCommand dbcmd;
dbcmd = dbcon.CreateCommand();
string q_createTable = "CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY, val INTEGER )";

dbcmd.CommandText = q_createTable;
dbcmd.ExecuteReader();

// Insert values in table
IDbCommand cmnd = dbcon.CreateCommand();
cmnd.CommandText = "INSERT INTO my_table (id, val) VALUES (0, 5)";
cmnd.ExecuteNonQuery();

// Read and print all values in table
IDbCommand cmnd_read = dbcon.CreateCommand();
IDataReader reader;
string query ="SELECT * FROM my_table";
cmnd_read.CommandText = query;
reader = cmnd_read.ExecuteReader();

while (reader.Read())
{
    Debug.Log("id: " + reader[0].ToString());
    Debug.Log("val: " + reader[1].ToString());
}

// Close connection
dbcon.Close();

Author

👤 Cory Leach

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by Gameframe.Packages

About

SQLite Package for Unity

License:MIT License


Languages

Language:C# 100.0%