- Home /
The question is answered, right answer was accepted
Database (SQLite) Setup for Unity
Create new folder under Assets Folder Rename it Plugins .
Copy sqlite3.def and sqlite3.dll into Assets/Plugins in your unity project .You can download these files here http://www.sqlite.org/download.html for windows (Precompiled Binaries for Windows)
Download SQLite Browser http://sourceforge.net/projects/sqlitebrowser/ or http://sqliteadmin.orbmu2k.de/ download SQLite Administrator tool
Create Database in Assets folder in your unity project using SQLite Browser.
Copy System.Data.dll and Mono.Data.Sqlite.dll from **C:\Program Files (x86)\Unity \Editor\Data\Mono\lib\mono\2.0* and paste them in your Assets/Plugins* folder in your unity project.
Add these namespaces using Mono.Data.Sqlite; using System.Data; using System;
string conn= "URI=file:" + Application.dataPath + "/PickAndPlaceDatabase.s3db";
Replace PickAndPlaceDatabase.s3db with your database name
void Start () {
string conn = "URI=file:" + Application.dataPath + "/PickAndPlaceDatabase.s3db"; //Path to database.
IDbConnection dbconn;
dbconn = (IDbConnection) new SqliteConnection(conn);
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlQuery = "SELECT value,name, randomSequence " + "FROM PlaceSequence";
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
int value = reader.GetInt32(0);
string name = reader.GetString(1);
int rand = reader.GetInt32(2);
Debug.Log( "value= "+value+" name ="+name+" random ="+ rand);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
Further SQLite Help Visit : http://www.tutorialspoint.com/sqlite/
[1]: /storage/temp/28838-output.png
I have posted this ,to help others. I was searching some help form different resource youtube,google to setup database and at end i write this article to help others.
Ok, I'm going to close it as answered then, because otherwise it will keep on appearing as an active question :)
This looks more like a TIP/Tutorial.Why is this posted here? do you see an issue ?
thanks .. another thing sir how can i work it on android??
Did you find the answer of it ? I am also finding the solution how to work in android. If you have solved it then guide me.
Follow this Question
Related Questions
Alternative to storing data in DB's 2 Answers
Hiding the SQLite file 0 Answers
Sq lite Date base in unity 3d? 1 Answer
How to connect my Application to SQLite Database? 1 Answer
Implementing an offline Inventory that must sync with a server 0 Answers