当前位置:网站首页>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 .
边栏推荐
- 收到一封CTO来信,邀约面试机器学习工程师
- 物联网rfid等
- Flume面试题
- Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
- Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
- 二叉树的基本操作
- AIDL基本使用
- 月入1W+的自媒体达人都会用到的运营工具
- Application of real estate management based on 3D GIS
- 【单体】流辰信息I-BPSv3服务器推荐配置
猜你喜欢
"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
微软、哥伦比亚大学|GODEL:目标导向对话的大规模预训练
MySQL系列之事务日志Redo log学习笔记
基于LSTM模型实现新闻分类
List announced | outstanding intellectual property service team in China in 2021
【Opencv450】HOG+SVM 与Hog+cascade进行行人检测
leetcode刷题:栈与队列07(滑动窗口最大值)
Spark面试题
Training on the device with MIT | 256Kb memory
[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
随机推荐
PHP 读取ini或env类型配置
I received a letter from CTO inviting me to interview machine learning engineer
编程英语生词笔记本
杰理之烧录都使用 VBAT 供电,供电电压 4.2V【篇】
PMP与NPDP之间的区别是什么?
手动实现function isInstanceOf(child,Parent)
杰理之关于长按开机检测抬起问题【篇】
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
Test cancellation 1
Classify boost libraries by function
Fundamentals - IO intensive computing and CPU intensive computing
【单体】流辰信息I-BPSv3服务器推荐配置
【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
人才近悦远来,望城区夯实“强省会”智力底座
收到一封CTO来信,邀约面试机器学习工程师
ngnix基础知识
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
【深度学习】利用深度学习监控女朋友的微信聊天?
Application of real estate management based on 3D GIS
打出三位数的所有水仙花数「建议收藏」