2

I need to create sqlite database in Unity (C#) for android project, but can not find required information or tutorials.

I am following this link http://answers.unity3d.com/questions/743400/database-sqlite-setup-for-unity.html

But I get this error:

 Failed to load 'Assets/Plugins/sqlite3.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386.    
 Mono.Data.Sqlite.SqliteConnection:Open()    
 Mono.Data.Sqlite.SqliteConnection:Open()

 Failed to load 'Assets/Plugins/sqlite3.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386.
 Mono.Data.Sqlite.SQLite3:Open(String, SQLiteOpenFlagsEnum, Int32, Boolean)
 Mono.Data.Sqlite.SQLite3:Open(String, SQLiteOpenFlagsEnum, Int32, Boolean)
 Mono.Data.Sqlite.SqliteConnection:Open()

 DllNotFoundException: Assets/Plugins/sqlite3.dll
 Mono.Data.Sqlite.SQLite3.Open (System.String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool)
 Mono.Data.Sqlite.SqliteConnection.Open ()

I am using Unity 5 (free version).

Are there any free plugins for sqlite database ?

Please provide me tutorials links if possible.

1
  • Since you mentioned C#, replaced unityscript tag with C#. Commented Apr 29, 2015 at 6:51

5 Answers 5

1

This Error occurs when you use 32bit binaries on 64bit system.After Searching lot over the internet i found 64bit binaries +An Example project is also added. You can download them here.

Sign up to request clarification or add additional context in comments.

Comments

1

This tutorial can help you for creating SQLite database in Unity using C#: https://medium.com/@rizasif92/sqlite-and-unity-how-to-do-it-right-31991712190.


You can download the required Plugins from this link, which already contains the libraries for SQLite.

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

Then for creating the database do the followings:

string dbConnectionString = "URI=file:" + Application.persistentDataPath + "/" + dbName + ".db";
IDbConnection dbConnection = new SqliteConnection(dbConnectionString);
dbConnection.Open();
IDbCommand dbCommand = dbConnection.CreateCommand();
dbCommand.CommandText = //write what you want here in SQLite syntax.

Then you need to execute the dbCommand.

for example for creating a new table:

dbCommand.CommandText = "CREATE TABLE IF NOT EXISTS " + tableName + " ( "
        KeyRequiredLevel + " INTEGER, " +
        KeyPrice + " INTEGER, " +
        KeyPriority + " INTEGER, " +
        KeyIsLoacl + " BOOLEAN, " +
        KeyPercentage + " DOUBLE, " +
        KeyImageURL + " TEXT, " +
        KeyIsActive + " BOOLEAN )" ;

dbCommand.ExecuteNonQuery();

Comments

0

The error said 'DllNotFoundException: Assets/Plugins/sqlite3.dll', have you put your sqlite3.dll file into Asset/Plugins folder? And you have to create this Plugins folder.

1 Comment

thanks for answering my questions, sqlite3.dll file already in Asset/Plugins folder.
0

Have you tried this one? Maybe this would help you: http://forum.unity3d.com/threads/unity-3d-android-sqlite-examples.114660/

2 Comments

thanks for answering my questions I follow the example given in that link , it also give the same erroe: Failed to load 'Assets/Plugins/sqlite3.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386.
You should use a version of sqlite3.dll according to your architecture. Maybe this link should help (it includes a x64 version of sqlite3.dll): forum.unity3d.com/threads/…
0

I would suggest trying to use a library designed for Unity. Personally this is what I have been doing to handle multi-platform SQLite handling. I would highly suggest this library/wrapper

SQLite made easy for Unity3d http://codecoding.github.io/SQLite4Unity3d

I am currently in the process of improving upon that and making it even more easy to work with. However this is probably a good starting point!

GOOD LUCK!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.