如何连接到数据库中的sqlite构建?

时间:2013-04-12 08:25:44

标签: sqlite unity3d

在Unity3d中,有两种方法可以在构建中包含文件: 1.通过声明成员变量公开对资产的引用,然后在检查器中分配它 2.将资源放在“Resources”文件夹中,然后通过Resources.Load加载它们 http://docs.unity3d.com/Documentation/ScriptReference/Resources.html

我选择了第二种变体。 myDB.bytes我在TextAsset中加载。 TextAsset db = Resources.Load(“myDB”);

现在我想使用sqlite API连接到这个数据库。但我只能使用文件名连接到文件,或在内存中创建新的数据库。如何使用现有的TextAsset实例将其作为sqlite数据库使用?

3 个答案:

答案 0 :(得分:0)

这可能会有所帮助。您需要导入数据包。

http://answers.unity3d.com/questions/188334/unity-sql-database.html

答案 1 :(得分:0)

我有一个解决方案。 将Application.dataPath中的TextAsset保存为数据库,并使用文件路径。

FileStream fs = File.Open(Application.dataPath + "/db.bytes", FileMode.Create);
BinaryWriter binary = new BinaryWriter(fs);
binary.Write(dbTextAsset.bytes);
fs.Close();

sqlite3_open(Application.dataPath + "/db.bytes".....

答案 2 :(得分:0)

由于这是Google提供的热门搜索结果之一:

将数据库放在 Assets / StreamingAssets 文件夹中。

使用 Application.streamingAssetsPath

引用它
database_path = "URI=file:" + Application.streamingAssetsPath + "/" + database_name;
using (var connection = new SqliteConnection (database_path)) {
            connection.Open();
            //...
}

参考:https://docs.unity3d.com/Manual/StreamingAssets.html

您还可以查看https://ornithoptergames.com/how-to-set-up-sqlite-for-unity/,了解有关如何从脚本访问数据库的信息。

相关问题