SOLVED insert some DATA into SQLITE Database using JavaScrip

Thanks GOD, my friend has helped me solve this problem.
So here is the solution below

import System.Data;
import Mono.Data.SqliteClient;

var stringToEdit = "Player1";
var userHasHitOk : boolean = false; 

function Update() { 
	
	if(Input.GetKeyDown("enter")) 
	{ 
		userHasHitOk = true; 
	} 
}
 
function insertQuery(userName : String)
{	
	var connectionString : String = "URI=file:SqliteTest.db";
	var dbconnection : IDbConnection = new SqliteConnection ( connectionString );
	dbconnection.Open();
	

	var dbcmd : IDbCommand = dbconnection.CreateCommand ();
	dbcmd.CommandText = "INSERT INTO name (name)  VALUES ('" + userName + "')"; // FIXED
	dbcmd.ExecuteNonQuery();
	// clean up  
	dbcmd.Dispose();
	dbcmd = null;
   dbconnection.Close();
}
	
function OnGUI () 
{ 	
	if (userHasHitOk) 
	{ 
		GUI.Label (Rect (10, 10, 100, 30), "Hello " + stringToEdit); 
		
		//Asign the stringToEdit variable into userName variable
		var userName : String = stringToEdit;
		insertQuery(userName);
	} 
	else 
	{ 
		GUI.Label (Rect (10, 10, 100, 30), "Enter Name:"); 
		stringToEdit = GUI.TextField (Rect (90, 10, 200, 25), stringToEdit, 40); 
	} 

}

For those (like me) who don’t absolutely know what this is for, could you show us a demo of this one?

Yes i understand that it’s for databases and stuff, but are you sending a message to the database by clicking on a button?

Hey iLoveChocolate, I was wondering if you could elaborate on how you were able to get your connection to work. I’m trying to connect to a .db file and getting the same error you were getting the other day.

DllNotFoundException: sqlite3
Mono.Data.SqliteClient.SqliteConnection.Open ()
dbAccess.Start () (at Assets\Scripts\dbAccess.js:162)

Like you said, copying the System.Data and Mono.Data.SqliteClient dlls to the assets folder didn’t resolve the problem. Here’s the code I’m using, it’s about as simple as I knew to make it.

import System.Data;
import Mono.Data.SqliteClient;

function Start () 
{

	var connectionString : String = "URI=file:test.db";
	
	var dbcon : IDbConnection = new SqliteConnection(connectionString);
	
	dbcon.Open();
	
	dbcon.Close();
	dbcon = null;

}

Thanks for any advice you can give.

Hi UNITY USERS

So the problem I had was

  1. I put the SQLITE dll and DB files in a different folder.
  • I put those files (SQLliteClient, DLLs) outside the ASSET folder.
  1. In my previouse CODE (with a problem)I typed this which produce an error

dbcmd.CommandText = “INSERT INTO name (name) VALUES (“userName”)”;// False

dbcmd.CommandText = “INSERT INTO name (name) VALUES ('” + userName + “')”; // CORRECT

The differences between those 2 code is in the first code I did not use the + sign.
And also, I should do this outsde a variable ‘" + userName + "’.

I should put a SINGLE QUOTE then a DOUBLE QUOTE,then a PLUS Sign and then the desired VARIABLE

eekkkkkkkk I hope that explained. If you still do not understand, I’ll try to explain it or perhaps send you the UNITY file

I have wrote an ARTICLE in my PC =D.

If you want it PLEASE GIVE ME YOU EMAIL address. Thank you

send link of your article dude

thanks
arun

See attached project, this uses SQLLite 3, and in it, the code creates a database for you, shows you how to do INSERT / UPDATE / DELETE / SELECT and includes all DLL’s and it is fully documented to help you understand some basic database functionality.

376654–13040–$sqllite_162.zip (893 KB)

thanks for your help…!!!

Regards
Arun

i used the same code which was given by ilovechocolate above , but its showing errors like

Assets/userScript.js(20,28): BCE0018: The name ‘IDbConnection’ does not denote a valid type (‘not found’). Did you mean ‘System.Runtime.InteropServices.ComTypes.ITypeComp’?

can you explain it???

the code above is for unity 2 / iphone 1.7 not U3

did any one try using Sqlite + android i dont find my data base after build
could any one help me?