当前位置:网站首页>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 .
边栏推荐
猜你喜欢
![[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!](/img/27/4bd0de716f5cb360d54f140dc8e9c1.png)
[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!

微软、哥伦比亚大学|GODEL:目标导向对话的大规模预训练

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

东哥套现,大佬隐退?

最近公共祖先(LCA)在线做法

Aidl basic use

JS how to get a list of elements in a collection object

【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程

编程英语生词笔记本

MySQL系列之事务日志Redo log学习笔记
随机推荐
PCB plug hole technology~
杰理之烧录上层版物料需要【篇】
Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
BC35&BC95 ONENET MQTT(旧)
Flume面试题
PWN攻防世界cgpwn2
从20s优化到500ms,我用了这三招
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
ngnix基础知识
mysql 学习笔记-优化之SQL优化
latex如何打空格
【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
MySQL series transaction log redo log learning notes
股票手机开户哪个app好,安全性较高的
leetcode刷题:栈与队列01(用栈实现队列)
都能看懂的LIS(最长上升子序列)问题[通俗易懂]
MySQL数据库驱动(JDBC Driver)jar包下载
杰理之蓝牙耳机品控和生产技巧【篇】
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
php反射型xss,反射型XSS测试及修复