Skip to content

kerembaydogan/UnitySQLite

 
 

Repository files navigation

Welcome to com.gameframe.sqlite 👋

Version Twitter: coryleach

SQLite Package for Unity

Quick Package Install

Using UnityPackageManager for Unity 2019.3 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.1",
    ...
  },
}

Using UnityPackageManager for Unity 2019.1 or 2019.2

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.0",
    ...
  },
}

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 readme-md-generator

About

SQLite Package for Unity

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%