• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SQLite plugin for Unity3D Android and iOS build

sqlite-unity-plugin

This plugin can be used to access sqlite database for unity projects in android and iOS devices.

Copy paste the Plugins folder in the Assets folder of your project (or copy paste the contents into your existsing Plugins folder) and follow the points below to access your database in c#.

  1. Import the correct namespaces.
using UnityEngine;
using System.Data;
using Mono.Data.Sqlite;
using System.IO;
  1. 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();
  1. 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();

Sample

A Unity implementation of this plugin can be found here.

Tutorial

Read this artcle on medium for more details.