Giter Site home page Giter Site logo

sqlite-unity-plugin's Introduction

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.

sqlite-unity-plugin's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlite-unity-plugin's Issues

Unable to read database on x86 build.

I implemented your plugin in my unity game. I am using x86 build of my game.
It shows error:
EntryPointNotFoundException: sqlite3_key

Mono.Data.Sqlite.SQLite3.SetPassword (System.Byte[] passwordBytes) (at <99f7d8f9a65b4d91ae5b1d55c424866f>:0)
Mono.Data.Sqlite.SqliteConnection.Open () (at <99f7d8f9a65b4d91ae5b1d55c424866f>:0)

It works fine in x64 build but messes up in x86. Why is this issue happening? How do I fix it?

Here is an implementation of plugin in c#:

string connection = "URI=file:C:/files/serial.db;Version=3;Password=samplepassword";

                IDbConnection dbcon = new SqliteConnection(connection);
               
                dbcon.Open();
                IDbCommand cmnd_read = dbcon.CreateCommand();
                IDataReader reader;
                string query = "SELECT * FROM KeyId";
                cmnd_read.CommandText = query;
                reader = cmnd_read.ExecuteReader();
                while (reader.Read())
                {
                    Debug.Log (reader[0].ToString());
                    textfileData = reader[0].ToString();
                }
               
                dbcon.Close();

Updates?

This works great thank you, but I assume these files will need refreshing at some point? If so where can I manually get the latest files as this project doesn't seem to be up to date?

Error cs0433

I am going through the walkthrough on medium.com but I run into this error when I build the solution:

CS0433: The type 'IDbConnection' exists in both 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

I have found similar issues brought up elsewhere, but my issue is just different enough that I can't translate the solutions to work for my problem. Also, I'm fairly new to Unity so any help is greatly appreciated.

sqlite3LockAndPrepare ios crash

I use the plugin for both android and ios build. I have no crashes on android but i have crashes on ios as you can see on attached screenshot.

ac95eac5-0164-412a-a3d0-473a4fc7d375

Android ARM 64

Hello,

The package is missing sqlite compatible with android arm-64 as Google set it as a requirement now to build 64bits native apps.

I tried adding a libesqlite3.so 64 bits that I found online but it did not work.

Please advise.

error CS1703 on Unity 2018.3.9f1

When i import the plugin folder into my assets Folder i've got 4 instances of this error:

error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:------------\Assets\Plugins\System.Data.dll' and 'C:\Program Files\Unity\Hub\Editor\2018.3.9f1\Editor\Data\MonoBleedingEdge\lib\mono\4.7.1-api\System.Data.dll'. Remove one of the duplicate references.

Unity Version 2018.3.9f1 but i found this problem in 2018.3.7f1 as well...

Not working on Android

Hey I don't know if I am doing this correctly. Can someone check it, because I am unable to read my sqlite file on Android. It work on Windows. I know for the windows editor we need to add URI=file:, but I wasn't sure if we do that for android as well. PS. I haven't tested it on iOS yet, so if iOS is also wrong, please let me know. Thanks!


if (Application.platform == RuntimePlatform.WindowsEditor) connection = "URI=file:" + Application.dataPath + "/StreamingAssets/Save File.db";
if (Application.platform == RuntimePlatform.Android) connection = "jar:file://" + Application.dataPath + "!/assets/Save File.db";
if (Application.platform == RuntimePlatform.IPhonePlayer) connection = Application.dataPath + "/Raw/Save File.db";

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.