当前位置:网站首页>Unity uses SQLite
Unity uses SQLite
2022-07-01 22:09:00 【Game programming】
I think the Internet is full of quotes sqlite3.dll,Mono.Data.Sqlite.dll,System.Data.dll, such as Setup Database (SQLite) for Unity
Or some third-party import methods unity-3rdparty-sqlite-net
Or import through a third-party package management tool Unity3D introduction : How to manage Unity In the project NuGet package ? Use of third parties NuGet Package manager ——NuGetForUnity
But I found that Unity About Sqlite The library of Unity.VisualScripting.Dependencies.Sqlite.SQLiteConnection , Information has Unity.VisualScripting.Dependencies.Sqlite.SQLiteConnection
So I made a simple addition, deletion, modification and check demo,Unity.VisualScripting.Dependencies.Sqlite.SQLiteConnection Sure Use it directly , It can be done. Yes Sqlite The operation of
Here's the key code
Create table
using (var db = new SQLiteConnection(databasePath, SQLiteOpenFlags.ReadWrite)){ var count = db.CreateTable<UserInfo>(); count = db.CreateTable<RandomEvent>();}Add data
using (var db = new SQLiteConnection(databasePath, SQLiteOpenFlags.ReadWrite)){ var count = db.Insert(new UserInfo() { Name = "test1Name", Sex = SexEnum.Woman, Birthday = new DateTime(1990, 10, 2) }, typeof(UserInfo)); List<UserInfo> users = new List<UserInfo>(); users.Add(new UserInfo() { Name = "test2Name", Sex = SexEnum.Man, Birthday = new DateTime(2000, 10, 2) }); users.Add(new UserInfo() { Name = "test3Name", Sex = SexEnum.Woman, Birthday = new DateTime(2004, 10, 2) }); count = db.InsertAll(users, typeof(UserInfo));}Modifying data
using (var db = new SQLiteConnection(databasePath, SQLiteOpenFlags.ReadWrite)){ var count = db.Update(new UserInfo() { Id = 3, Name = "test1Name-Update", Sex = SexEnum.Woman, Birthday = new DateTime(1990, 10, 2) }, typeof(UserInfo));}Delete data
using (var db = new SQLiteConnection(databasePath, SQLiteOpenFlags.ReadWrite)){ string sql = "select Id,Name,Sex,Birthday from UserInfo where Id =3"; var data = new object[] { "Id", "Name", "Sex", "Birthday" }; var deleteData = db.Query(new TableMapping(typeof(UserInfo)), sql, data).FirstOrDefault(); if (deleteData != null) { var count = db.Delete(deleteData); } var count2 = db.Delete<UserInfo>(4);}Query data
using (var db = new SQLiteConnection(databasePath, SQLiteOpenFlags.ReadWrite)){ string sql = "select Id,Question,[Order] from RandomEvent"; var data = new object[] { "Id", "Question", "[Order]" }; var datas = db.Query(new TableMapping(typeof(RandomEvent)), sql, data); //enum not work :( //var datas2 = db.Find<UserInfo>(user => user.Name.Contains("test")); var datas2 = db.Find<RandomEvent>(randomEvent => randomEvent.Question.Contains("q")); var data3 = db.Get<UserInfo>(1);}Data sheets need to be declared
[Table(name: nameof(RandomEvent))]public class RandomEvent{ [PrimaryKey, AutoIncrement] public int Id { get; set; } public string Question { get; set; } public int Order { get; set; }}[Table(name: nameof(UserInfo))]public class UserInfo{ [PrimaryKey, AutoIncrement] public int Id { get; set; } public string Name { get; set; } public SexEnum Sex { get; set; } public DateTime Birthday { get; set; }}Sample code
TestSqliteScript
After opening the project , stay TestSqliteCanvas Can be executed under
If there is something inappropriate , You can pack another layer by yourself ~
author :zLulus
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- Electron学习(三)之简单交互操作
- Unity 使用Sqlite
- Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
- 【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
- 从20s优化到500ms,我用了这三招
- pytest合集(2)— pytest運行方式
- 新版图解网络PDF即将发布
- 【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
- leetcode刷题:栈与队列05(逆波兰表达式求值)
猜你喜欢
随机推荐
require与import的区别和使用
CNN convolution neural network principle explanation + image recognition application (with source code) [easy to understand]
Internet of things RFID, etc
Significance and measures of security encryption of industrial control equipment
个人炒股怎样开户?安全吗。
MySQL数据库驱动(JDBC Driver)jar包下载
Kuberntes云原生实战一 高可用部署架构
最近公共祖先离线做法(tarjan)
Basic operation of binary tree
matlab遍历图像、字符串数组等基本操作
burpsuite简单抓包教程[通俗易懂]
能升职加薪?PMP证书含金量浅析
从20s优化到500ms,我用了这三招
分离字符串中的字母和数字并使得字母在前数组在后
pytest合集(2)— pytest運行方式
从20s优化到500ms,我用了这三招
杰理之、产线装配环节【篇】
最近公共祖先(LCA)在线做法
GCC编译
杰理之、产线装配环节【篇】









