当前位置:网站首页>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 .
边栏推荐
- An operation tool used by we media professionals who earn 1w+ a month
- Talking from mlperf: how to lead the next wave of AI accelerator
- Difference and use between require and import
- Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
- “丝路正青春 风采看福建”在闽外籍青年短视频大赛火热征集作品中
- vscode的使用
- 最近公共祖先(LCA)在线做法
- Case of camera opening by tour
- leetcode刷题:栈与队列05(逆波兰表达式求值)
- Test cancellation 1
猜你喜欢
随机推荐
Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc
EMC-电路保护器件-防浪涌及冲击电流用
Using closures to switch toggle by clicking a button
上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
【单体】流辰信息I-BPSv3服务器推荐配置
AirServer2022最新版功能介绍及下载
JS how to get a list of elements in a collection object
杰理之蓝牙耳机品控和生产技巧【篇】
cmake工程化相关
pytest合集(2)— pytest运行方式
Spark面试题
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
基于LSTM模型实现新闻分类
同花顺股票开户选哪个券商好手机开户是安全么?
杰理之、产线装配环节【篇】
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
MQ学习笔记
Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
4. 对象映射 - Mapping.Mapstercover







