x


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.

more ▼

asked Mar 16, 2012 at 08:37 AM

zerox911 gravatar image

zerox911
235 54 50 50

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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 ;)

more ▼

answered Mar 16, 2012 at 02:21 PM

Cygon gravatar image

Cygon
16 12 8 10

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.

Mar 19, 2012 at 06:41 AM zerox911
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x415
x302
x132
x102
x87

asked: Mar 16, 2012 at 08:37 AM

Seen: 1594 times

Last Updated: Mar 19, 2012 at 07:01 AM