Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zerox911 · Mar 16, 2012 at 08:37 AM · databasechildrendictionarysqlitefor

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zerox911 · Mar 19, 2012 at 06:41 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges