SQLiteUnityKit extension library

2 minute read

A library based on SQLiteUnityKit

――It is one of the many modifications of SQLite Unity Kit.
Repository (GitHub)

Feature

――I made it possible to use Japanese.
–Added support for transaction processing.
–Added support for bind variables.
–Prevented overwriting the existing DB. (However, it does not merge.)
–Low-level processes such as open, close, and resource release are hidden, and only processes with a high level of abstraction are exposed.
――I tried to catch exceptions internally as much as possible and keep moving while avoiding unreleased resources.

Premise

environment

  • Unity 2019.4.10f1 (LTS)
  • Unity 2018.4.26f1 (LTS)
  • Unity 2017.4 (LTS)
  • SQlite 3.33.0
  • C# 6
    –You are using string interpolation.
    –If necessary, set Scripting Runtime Version to 4.x in Player Settings.

SQLite
–SQLite is a standalone database management system that can use a subset of SQL.
–Compatible with Windows, MacOS, Android, iOS, etc.
-Official site

SQLiteUnityKit
–SQLiteUnityKit is a framework for using SQLite from Unity.
Repository (GitHub)

Introduction and overview

–Introduce ʻAssets` from the repository into your project.

Overview

  • Assets/Plugins/sqlite3/
    –SQLite plugin for each platform. (iOS is supported on the OS side.)
  • Assets/Scripts/
    • SQLiteUnity.cs
      –This is a required part.
    • “SQLiteUnityUtility.cs”
      –Extension utility class. as you like.
      –Pseudo binding can be used even in transactions.
    • “Test.cs”
      –Demo script.
  • Assets/Prefabs/Console.prefab
    –This is a demo prefab.
  • Assets/Scenes/SQLite_Test.unity
    –This is a demo scene.

Update to the latest plugin

-Please get the latest version from Download official website and install it in ʻAssets / Plugins`.
–For Android, please refer to This article (Qiita).

Basic usage

–Database
- public class SQLite : IDisposable
–New generation (initialization query) (If you already have it, just use it, if you have the original, copy it and use it)
- public SQLite (string dbName, string query = null)
–Execute a simple sentence
- public void ExecuteNonQuery (string query, SQLiteRow param = null)
–Execute a simple sentence and return the result
- public SQLiteTable ExecuteQuery (string query, SQLiteRow param = null)
–Execute in order while replacing variables in simple sentences
- public void ExecuteNonQuery (string query, SQLiteTable param)
–The same SQL statement is repeatedly executed with different parameters.
–Execute compound sentences at once and rewind if there is an error
- public bool TransactionQueries<T> (T query) where T : IEnumerable<string>
- public bool TransactionQueries (string query)
–The difference is whether you pass multiple lines as an array or list, or as a single string.
―― BEGIN, COMMIT are added at the beginning and end.
–Matrix data
- public class SQLiteTable
–The data returned by the query, which is a set of column definitions and row data.
–Row data / bind parameters
- public class SQLiteRow : Dictionary<string, object>
–One row of data, a set of column data. Also used when passing bind parameters.
–Extended binding (for transactions)
- public static string SQLiteBind (this string query, SQLiteRow param)
–String-based binding done outside of sqlite.

Other

――We welcome your suggestions, suggestions, or questions.
――I don’t understand common sense, so if you make a mistake, I would appreciate it if you could give me some advice.
――For more detailed usage, I would like to write a usage example.