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 Mithrilshadow · Aug 13, 2013 at 02:42 AM · database

SQLite: no such table

I am trying to integrate SQLite into unity. I can connect to the database, test code shows that I have an open connection to the right database. However when I try to look up data from a table I get the following error. I do have a 'test' Table and can query it from another program successfully. Any ideas on what I am doing wrong?

Please no comments about why I should use PlayerPrefs, XML, etc.... I choose SQLite because it meets my needs.

SqliteSyntaxException: no such table: test

Mono.Data.SqliteClient.SqliteCommand.GetNextStatement (IntPtr pzStart, System.IntPtr& pzTail, System.IntPtr& pStmt)

Mono.Data.SqliteClient.SqliteCommand.ExecuteReader (CommandBehavior behavior, Boolean want_results, System.Int32& rows_affected)

Mono.Data.SqliteClient.SqliteCommand.ExecuteReader (CommandBehavior behavior) Mono.Data.SqliteClient.SqliteCommand.ExecuteDbDataReader (CommandBehavior behavior) System.Data.Common.DbCommand.ExecuteReader () System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader () ItemDB.Awake () (at Assets/Scripts/Item/ItemDB.cs:20)

Here is the code:

 using UnityEngine;
 using System.Collections;
 using System.Data;
 using Mono.Data.SqliteClient;
 
 public class ItemDB : MonoBehaviour {
     private string _constr="URI=file:Item.db";
     private IDbConnection _dbc;
     private IDbCommand _dbcm;
     private IDataReader _dbr;
             
     void Awake()
     {
         _dbc = new SqliteConnection(_constr);
         _dbc.Open();
         _dbcm = _dbc.CreateCommand();
         _dbcm.CommandText="SELECT number,name FROM test";
         _dbr = _dbcm.ExecuteReader();
     }
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetKeyUp(KeyCode.F))
         {
             Debug.Log(_dbcm.CommandText);
         }
     }
 }
 
Comment
Add comment · Show 3
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 getyour411 · Aug 13, 2013 at 03:08 AM 1
Share

Do you have the specify schema owner before tablename, such as 'select 1,2 from myschema.test'?

avatar image Mithrilshadow · Aug 13, 2013 at 01:25 PM 0
Share

I am really new to this, I don't have a schema set, but I can set one up and try again. I'll post the results.

Update: Not sure if this is right but I updated the code on line 17 to:

         cmd = new SqliteCommand("SELECT * FRO$$anonymous$$ sqlite_master.item", con);
 

Same error, SqliteSyntaxException: no such table: sqlite_master.item

I think I don't have my database set-up right. I move the file location and it still tells me it makes an open connection. Ergo I am not actually connecting to my db ...

avatar image getyour411 · Aug 13, 2013 at 08:17 PM 0
Share

I'm thinking of adding SQLite to my project but have not done so yet, I did collect a few hyperlinks maybe one of these will provide an answer:

http://forum.unity3d.com/threads/28500-SQLite-Class-Easier-Database-Stuff/page2

http://forum.unity3d.com/threads/7866-Unity-and-Sqlite/page3

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GZB1992 · Jun 08, 2015 at 07:36 AM

ok... so... I jsut fixed this same error in my project... the problem was in the filepath i was passing as parameter... use this:

 (!C#!)
     public void OpenDB ()
         {
             Debug.Log("Call to open BD:" + DbName);
             // check if file exists in Application.DataPath
             string filepath = Application.dataPath+ "/StreamingAssets/" + DbName;
             if(!File.Exists(filepath))
             {
                 Debug.LogWarning("Arquive \"" + filepath + "\" doenst exist. tring to create from \"" + filepath);
                 // if it doesn't ->
                 // open StreamingAssets directory and load the db -> 
                 WWW loadDB = new WWW("jar:file://" + filepath);
                 while(!loadDB.isDone) {}
                 // then save to Application.persistentDataPath
                 File.WriteAllBytes(filepath, loadDB.bytes);
             }
             
             //open db connection
             connection = "URI=file:" + filepath;
             Debug.Log("Stabilishing connection to: " + connection);
             dbConnection = new SqliteConnection(connection);
             dbConnection.Open();
         }


the secret is in the use of application.datapath, which usually returns ""C:/Users/username/projectname/Assets/StreamingAssets/database.db.

I hope this helps... it helped me...

Comment
Add comment · Show 4 · 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 sadowlight123 · Apr 22, 2017 at 07:22 AM 0
Share

hello how are you ? i have a small problem ... i have written this code and it works really good on windows , but not on android on android the last thing that the debugging text gives me is step 6 so that is where it is stopping my guess is that maybe it is going through a infinite while loop how can i solve this issues?

using UnityEngine; using System; using System.IO; using System.Collections; using System.Data; using System.Text; using $$anonymous$$ono.Data.SqliteClient; using UnityEngine.UI;

public class dbAccess : $$anonymous$$onoBehaviour { private string connection; private IDbConnection dbcon; private IDbConnection dbConnection; private IDbCommand dbcmd; private IDataReader reader; private StringBuilder builder; public Text debuggingthis; // Use this for initialization void Start () {

 }
  public void OpenDBtwo()
 {
     debuggingthis.text = "step1";
     Debug.Log("Call to open BD: GameDatabase.db"  );
     debuggingthis.text = "step2";
     // check if file exists in Application.DataPath
     string filepath = Application.dataPath + "/Strea$$anonymous$$gAssets/GameDatabase.db";
     debuggingthis.text = "step3";
     if (!File.Exists(filepath))
     {
         debuggingthis.text = "step14";
         Debug.LogWarning("Arquive \"" + filepath + "\" doenst exist. tring to create from \"" + filepath);
         // if it doesn't ->
         // open Strea$$anonymous$$gAssets directory and load the db -> 
         debuggingthis.text = "step5";
         WWW loadDB = new WWW("jar:file://" + filepath);
         debuggingthis.text = "step6";
         /*------reached this point on mobile-------*/
         while (!loadDB.isDone) { }
         // then save to Application.persistentDataPath
         File.WriteAllBytes(filepath, loadDB.bytes);
         debuggingthis.text = "step7";
     }

     debuggingthis.text = "step8";
     //open db connection
     connection = "URI=file:" + filepath;
     debuggingthis.text = "step9";
     Debug.Log("Stabilishing connection to: " + connection);
     debuggingthis.text = "step10";
     dbConnection = new SqliteConnection(connection);
     debuggingthis.text = "step11";
     dbConnection.Open();
     debuggingthis.text = "step12";
 }

avatar image Bunny83 sadowlight123 · Apr 22, 2017 at 10:23 AM 0
Share

Do not hijack other questions. If you have a question you should post it as question.

To understand your problem you should carefully read the docs on Strea$$anonymous$$gAssets, especially the special section about android. The strea$$anonymous$$g assets are readonly on android and can only be accessed with the WWW class.

The usual solution is to copy the file from the strea$$anonymous$$g assets location to an actual file location in the persistant data path on first launch.

avatar image sadowlight123 Bunny83 · Apr 22, 2017 at 11:46 AM 0
Share

Dear Bunny83 , I apologies ... I really needed an answer asap so I had to post a comment asking for help ... I tried asking questions on my own but I got not any replies so far . However , a big big thanks for the hint that you dropped for me . Could I have more of your help on my questions please? I will follow

http://answers.unity3d.com/questions/1343845/sql-lite-database-for-andoid-in-unity.html#comment-1343946 http://answers.unity3d.com/questions/1343982/sqllite-android-and-unity.html#comment-1343985

Show more comments

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

19 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 avatar image avatar image

Related Questions

How to connect to oracle databases for webplayers 0 Answers

Develope Cloud & Vuforia application 1 Answer

Read/Write attachments from MS AccessDB 0 Answers

Players online counter 1 Answer

how to make the build in android which can access the local database sqlite 0 Answers


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