SQLite Package
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
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",
...
},
}
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();
👤 Cory Leach
- Twitter: @coryleach
- Github: @coryleach
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by Gameframe.Packages