Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sqlite database doesn't work on Unity games build to Android Devices

Discussion in 'Android' started by ricardohenrique996, Jan 30, 2016.

  1. ricardohenrique996

    ricardohenrique996

    Joined:
    Dec 30, 2015
    Posts:
    5
    I'm using the Sqlite as Unity Game database and works on Unity Editor, but when I build to Android Devices the Game can't access the database, what can I do to make the script works also on Android Devices ?

    Programs/Versions used:
    - Unity 5.3.1f1
    - Sqlite Precompiled Binaries for Windows 64 (sqlite-dll-win64-x64-3100200.zip
    (688.01 KiB))

    Folder Structure:

    -- Assets/Database/MyDataBase.db
    -- Assets/Scripts/PerguntaScript.cs
    -- Assets/Plugins/Mono.Data.Sqlite.dll
    -- Assets/Plugins/sqlite3.def
    -- Assets/Plugins/sqlite3.dll
    -- Assets/Plugins/System.Data.dll

    PerguntaScript.cs (Script that access the Sqlite database)

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    using System;
    using System.Data;
    using Mono.Data.Sqlite;

    public class PerguntaScript : MonoBehaviour {

    private string connectionString;

    void Start () {
    connectionString = "URI=file:" + Application.dataPath + "/Database/DoencasDB.db";
    }

    private void GetPergunta(){
    using(IDbConnection dbConnection = new SqliteConnection(connectionString)){
    dbConnection.Open();

    using(IDbCommand dbCommand = dbConnection.CreateCommand()){
    string sqlQuery = "SELECT * FROM " + sqliteTabelasPerguntas[sqliteIndexTabelaPergunta] + " WHERE doenca_id=@id LIMIT 1";
    dbCommand.Parameters.Add(new SqliteParameter("@Id", doencaId));
    dbCommand.CommandText = sqlQuery;

    using(IDataReader reader = dbCommand.ExecuteReader()){
    while(reader.Read()){
    pergunta = reader.GetString(1);
    alternativasId[0] = reader.GetInt32(3);
    alternativasId[1] = reader.GetInt32(4);
    alternativasId[2] = reader.GetInt32(5);
    alternativasId[3] = reader.GetInt32(6);
    alternativaCorretaId = reader.GetInt32(7);
    }
    dbConnection.Close();
    reader.Close();
    }
    }
    }
    }​
     
    Last edited: Jan 30, 2016
  2. TimGS

    TimGS

    Joined:
    Apr 24, 2014
    Posts:
    70
  3. bibalexwalid

    bibalexwalid

    Joined:
    Mar 28, 2019
    Posts:
    2
    Tutorial SQLite Unity3d 2018 or hegher( Android , Windows Phone , Windows , IOS, WINRT )
    How to Connection Database Sqlite how to Create Table , Select , Insert , Update , Delete , Search

    How to read data from on unity Solving all error in unity for assembly reference:
    1- error "The type or namespace name Data' does not exist in the namespace 'Mono'. Are you missing an assembly reference?"
    2- and error "The type or namespace name MONO' does not exist in the namespace Data'. Are you missing an assembly reference?"
    - using Mono.Data.Sqlite;
    - using System;
    - using System.Data;
    - using System.IO;
    - using UnityEngine.UI;

    learning how:
    * SQLite Admin to create database and tables .......
    * SQLite DLL to support unity .s3db extension and compile on unity for windows 32bit or 64bit.

    Github example : https://github.com/walidabazo

    Video