retrieving data from SQLite to UNITY

hi all…
here’s my problem…
i’m creating an encyclopedia for preschoolers on object around us.

i have the SQLite database and UNITY to run it.
but some how i cant get it to work.
i edited the code from here unifycommunity.com.

and here’s my code :

this code is for the GUI functions.

public var DatabaseName : String;

public var TableName : String ;
var db : dataRetrieve;

function Start(){

db = new dataRetrieve();

db.OpenDB(DatabaseName);

var tableName = TableName;

var resultArray = db.SearchResult( tableName, "Search", "'" + "search" + "%'"); 

print(resultArray[0]);

db.CloseDB();

}

var search: String = “”;

var DatabaseEntryStringWidth = 100;

var scrollPosition : Vector2;

var databaseData : ArrayList = new ArrayList();

function OnGUI(){
GUI.Box(Rect (25,25,Screen.width - 50, Screen.height - 50),“”);
GUILayout.BeginArea(Rect(50, 50, Screen.width - 100, Screen.height - 100));

GUILayout.BeginHorizontal();
 search = GUILayout.TextField(search, GUILayout.Width (DatabaseEntryStringWidth));
GUILayout.EndHorizontal();
			
	if(GUILayout.Button("SEARCH")){
		databaseData = SearchResult();
			}
    
GUILayout.BeginHorizontal();
	
	GUILayout.Label("Searched Result");
			
scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Height(100));
		for(var line : ArrayList in databaseData){
			
	GUILayout.BeginHorizontal();
						
	for(var s in line){
	GUILayout.Label(s.ToString(),GUILayout.Width(DatabaseEntryStringWidth));
					}
					
	GUILayout.EndHorizontal();
		
GUILayout.EndScrollView();
}   

GUILayout.EndArea();

}

function SearchResult(){
return db.SearchResult(TableName);
}

here’s the second code to read from the data.

import System.Data;

import Mono.Data.Sqlite;

class dbRetrieve{

private var connection : String;
private var dbcon : IDbConnection;
private var dbcmd : IDbCommand;
private var reader : IDataReader;

function OpenDB(p : String){
	connection = "URI = file" + p;
	dbcon = new SqliteConnection(connection);
	dbcon.Open();
}

function BasicQuery(q : String, r : boolean){
	
	dbcmd = dbcon.CreateCommand();
	dbcmd.CommandText = q;
	reader = dbcmd.ExecuteReader();
		if(r){
			return reader;
		}
	}
	

function SearchResult(tableName : String, Search : String, a : String){

var query : String;

query = "SELECT * FROM " + tableName + " WHERE " + Search + “LIKE” + “'” + a + “%';” ;

	dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query; 
    reader = dbcmd.ExecuteReader();
    var readArray = new Array();

    while(reader.Read()){ 
        readArray.Push(reader.GetString(0)); // Fill array with all matches
    }
    return readArray; // return matches
}
	
	function CloseDB(){
    reader.Close(); 
    reader = null; 
    dbcmd.Dispose(); 
    dbcmd = null; 
    dbcon.Close(); 
    dbcon = null; 
}

}

after compiling these scripts, an error stated that “GUI Error: You are pushing more GUIClips than you are popping.”

and i’m not sure what it is.

please help.

In this code snippet of yours:

GUILayout.BeginHorizontal();
search = GUILayout.TextField(search, GUILayout.Width (DatabaseEntryStringWidth));
GUILayout.EndHorizontal();

if(GUILayout.Button("SEARCH")){
  databaseData = SearchResult();
}

GUILayout.BeginHorizontal();

GUILayout.Label("Searched Result");
scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Height(100));

for(var line : ArrayList in databaseData){
  GUILayout.BeginHorizontal(); // <-- This is not being closed
  
  for(var s in line){
  GUILayout.Label(s.ToString(),GUILayout.Width(DatabaseEntryStringWidth));
}

GUILayout.EndHorizontal();

GUILayout.EndScrollView();

There’s an unbalanced number of BeginHorizontal() calls to EndHorizontal() calls.
Try adding an EndHorizontal() before closing the cloop :wink: