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