- Home /
 
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 http://www.unifycommunity.com/wiki/index.php?title=SQLite.
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.
Answer by Cygon · Mar 16, 2012 at 02:21 PM
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 ;)
at the part where u commented , i removed the call.. but still i get the same error. and i did the same when i end the call like u said. well still the same error occurred. and my GUI's are misplaced.
well have to do some more checking.. thanks anyway.. appreciate it.
Your answer
 
             Follow this Question
Related Questions
SQLite Transaction Update Problem on Android 0 Answers
Error... sqlite3_next_stmt 0 Answers
Retrieving data from Sqlite database using Mono.Data.Sqlite 0 Answers
SQLite: updating integer with the value 1 to integer = integer + 1 results in 3 instead of 2 1 Answer
Unity/C# - Is it possible to connect an Azure (cloud) database, to a Unity game, via EnityFramework? 1 Answer