统一Sqlite Android问题
我一直在尝试在Unity android上使用sqlite db 首先我试过了 ,它在编辑器中运行良好 但无法为android构建 我得到了这个统一Sqlite Android问题,android,sqlite,unity3d,unityscript,Android,Sqlite,Unity3d,Unityscript,我一直在尝试在Unity android上使用sqlite db 首先我试过了 ,它在编辑器中运行良好 但无法为android构建 我得到了这个错误:“SystemException:'System.Net.Sockets'仅在Unity Android Pro中受支持。从程序集'Mono.Data.Tds'引用。” 然后我将Unity free升级为pro 现在我可以为android设备构建unity项目, 但数据库功能不起作用 然后我试着把所有的例子都附在下面的线程上, 但在编辑器中,所有
错误:“SystemException:'System.Net.Sockets'仅在Unity Android Pro中受支持。从程序集'Mono.Data.Tds'引用。”
然后我将Unity free升级为pro
现在我可以为android设备构建unity项目,
但数据库功能不起作用
然后我试着把所有的例子都附在下面的线程上,
但在编辑器中,所有这些都可以正常工作,但在设备中没有数据库功能
我们正在工作
如何解决此问题?添加此参考
可下载
您的
Plugins/Android
目录中有sqlite3.so
文件?@Lesori,是的sqlite3.so。我现在已经解决了:)。你从哪里得到的sqlite3.so?
using Mono.Data.Sqlite;
using System;
using System.Data;
using System.IO;
using UnityEngine.UI;
IDbConnection dbconn;
IDbCommand dbcmd;
private IDataReader reader;
string filepath = Application.persistentDataPath + "/" + DatabaseName;
// If not found on android will create Tables and database
Debug.LogWarning("File \"" + filepath + "\" does not exist. Attempting to create from \"" +
Application.dataPath + "!/assets/Employers");
// #UNITY_ANDROID
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/Employers.s3db");
while (!loadDB.isDone) { }
// then save to Application.persistentDataPath
File.WriteAllBytes(filepath, loadDB.bytes);
conn = "URI=file:" + filepath;
Debug.Log("Stablishing connection to: " + conn);
dbconn = new SqliteConnection(conn);
dbconn.Open();
Table Name (Staff) Have ID is PRIMARY KEY , Name, Address
string query;
query = "CREATE TABLE Staff (ID INTEGER PRIMARY KEY AUTOINCREMENT, Name varchar(100), Address varchar(200))";
try
{
dbcmd = dbconn.CreateCommand(); // create empty command
dbcmd.CommandText = query; // fill the command
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
}
catch (Exception e)
{
Debug.Log(e);
}
To Select Sqlite
string Name_readers, Address_readers;
using (dbconn = new SqliteConnection(conn))
{
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlQuery = "SELECT Name, Address " + "FROM Staff";// table name
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
Name_readers = reader.GetString(0);
Address_readers = reader.GetString(1);
Debug.Log(" name =" + Name_readers + "Address=" + Address_readers);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close(); ```.