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 alonsoGarrote · Sep 15, 2013 at 01:53 AM · androiddatabasesqlitequery

problem retrieving data from SQLite to Android

Hi everybody!!, this is my first post,

Im working on a University project: Augmented reality app for guidance inside Museum rooms,

Im using Vuforia SDK + Unity3D(3.5.5) indie + SQLite database

I used:[http://wiki.unity3d.com/index.php?title=SQLite][1]

I could make it work on Unity indie Android! I made a edited C# version of both dbAccess.js and ScriptThatUsesTheDatabase.js

I CAN retrieve data using ReadFullTable(string tableName) from dbAccess.cs through ScriptuseDB.cs but I CANT retrieve data using SingleSelectWhere( ) - dont know why(this is the problem).

when i touch the GUI.Button("Titulo") it is supposed to call dbAccess.SingleSelectWhere() BUT nothing shows up and all three buttons disappear and ScrollView...What can I do?, here's the code:

ScriptuseDB.cs:

 using UnityEngine;
 using System.Collections;
 
 public class ScriptUsaDB : MonoBehaviour {
 public string DatabaseName = "TestDB.sqdb";
 public string TableName = "TestTable";
 
     DBAccess db    = new DBAccess();
 
     void Start () {
         db.OpenDB (DatabaseName);
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     //var databaseData : ArrayList = new ArrayList();
     ArrayList databaseData = new ArrayList();
     Vector2 scrollPosition;
     int DatabaseEntryStringWidth = 100;
     
     void OnGUI(){    
     GUI.Box(new Rect (25,25,Screen.width - 50, Screen.height - 50),""); 
     GUILayout.BeginArea(new Rect(50, 50, Screen.width - 100, Screen.height - 100));    
         GUILayout.BeginHorizontal();
             if (GUILayout.Button ("Leer BD"))//here all OK, it shows all data from table     
                 databaseData = ReadFullTable();
             if (GUILayout.Button("Limpiar"))
                 databaseData.Clear();
             if (GUILayout.Button("Titulo"))//when I touched this ALL GUI.Layout disappear!(the GUI.Box remains though)
                 databaseData = SingleSelect();
         GUILayout.EndHorizontal();
         
         GUILayout.Label("Contenidos de la tabla de prueba");
         
         scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(400));
             //foreach (string day in week)
             foreach (ArrayList line  in databaseData){
                     GUILayout.BeginHorizontal();
                     foreach(var s in line){
                         GUILayout.Label(s.ToString(), GUILayout.Width(DatabaseEntryStringWidth));
                     }
                     GUILayout.EndHorizontal();
             }
          GUILayout.EndScrollView();
         
         
     GUILayout.EndArea();
     }
     
     ArrayList ReadFullTable(){
     return db.ReadFullTable(TableName);    
     }
     
     ArrayList SingleSelect(){
     return db.SingleSelectWhere(TableName,"Titulo","Cultura","=","'Chavin'");//CAMBIO1: agregamos ' ' para el string luego del =
         //ORDER BY ProductName DESC;
     }
     
 }

Here is dbAccess function:

 public ArrayList SingleSelectWhere(string tableName, string itemToSelect, string wCol, string wPar, string wValue){ // Selects a single Item
 string query;
 query = "SELECT " + itemToSelect + " FROM " + tableName;// + " WHERE " + wCol + wPar + wValue;CAMBIO: limitamos el query para pruebas
 dbcmd = dbcon.CreateCommand();
 dbcmd.CommandText = query; 
 reader = dbcmd.ExecuteReader();
 var readArray = new ArrayList();//CAMBIO2: Cambiamos Arraylist por var de acuerdo a ReadFullTable
 while(reader.Read()){ 
 readArray.Add(reader.GetString(0)); // Llenamos el arreglo con los datos //CAMBIO1:probamos cambiar reader.GetString(0) por .GetValue(0).
 }
 return readArray; // devuelve los datos
 }

I tried to solve this but I cant, PLEASE any help? Thank You, [1]: http://wiki.unity3d.com/index.php?title=SQLite

Comment
Add comment · Show 4
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 JamieSinn · Sep 16, 2013 at 04:53 PM 0
Share

Do you get any errors? The SQL statment seems fine other than you are not using half of it. Why is part of it commented out?

avatar image alonsoGarrote · Sep 16, 2013 at 05:36 PM 0
Share

Hi, when I touch the "Titulo" Button, all GUILayout goes away(all three buttons, scroll), only the GUI.box stays there. I Cut the query to make things simplier so I could catch the error.... I tried changing reader.GetString(0) for reader.GetValue(), but no success , do you know where can I find a workable example on select query on c#"?

avatar image zhuchun · Sep 17, 2013 at 02:15 AM 0
Share

As you're not using coroutine, suggest you put codes in try-catch and debug.log its exception, this may help you find error easier. Especially for SingleSelectWhere(), try to make sure if it returns correctly, if so, then it's not reader's problem.

BTW, our DB helper usually return reader directly, so it's decoupled and can be debug/reuse easily.

What's more, if you're trying to build a better UI, suggest leave native GUI system alone and try NGUI ins$$anonymous$$d.

avatar image alonsoGarrote · Sep 17, 2013 at 06:21 PM 0
Share

Thank for your comments zhuchun, Yeah, I was about to use try-catch but got the answers sooner. I cant use NGUI by now because its a college project, so its better if I do all I can on my own.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JamieSinn · Sep 16, 2013 at 09:32 PM

My github has pretty close to it, https://github.com/JamieSinn/MySQLDatabaseInserterConsole have fun there. Note. there are some issues with it, but again, it is just a temporary thing.

Comment
Add comment · Show 2 · 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 alonsoGarrote · Sep 17, 2013 at 06:25 PM 0
Share

JamieSinn, thank you for sharing this, I'll take into account :)

avatar image JamieSinn · Sep 18, 2013 at 12:26 AM 0
Share

No problem, Could you please mark your post as answer?

avatar image
1

Answer by alonsoGarrote · Sep 17, 2013 at 02:18 PM

FOUND THE ANSWER!! 1. I change the path to StandAlone MAC, so I could see the Console messages 2. I got the error "Cannot cast from source type to destination type." 3. Check that line - foreach (ArrayList line in databaseData){- 4. IF I use SingleSelectWhere function it doesnt return Arraylist(THATS THE ERROR) 5. Change ArrayList line for string line. 6. Now it works.

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 zhuchun · Sep 17, 2013 at 02:19 PM 0
Share

congrats :)

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SqliteException: Unable to open the database file - Ready-made DB Provided To Access 0 Answers

Unity 4 Android Game cannot access SQLite DB (C# Script) 1 Answer

SQLite Transaction Update Problem on Android 0 Answers

Sqlite3.dll not found on specific Android devices 2 Answers

SqlLite , android and unity 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