当前位置:网站首页>Unity uses SQLite
Unity uses SQLite
2022-07-01 05:29:00 【zLulus】
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 ~
边栏推荐
- Global and Chinese market of digital badge 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
- Daily question -leetcode1175- permutation of prime numbers - Mathematics
- Actual combat: basic use of Redux
- Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection
- Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
- Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
- Use and principle of wait notify
- Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
- Rust hello-word
猜你喜欢

如何创建一个根据进度改变颜色的进度条

Actual combat: gateway api-2022.2.13

How to hide browser network IP address and modify IP internet access?

Use and principle of AQS related implementation classes

And search: the suspects (find the number of people related to the nth person)
![Is there any good website or software for learning programming? [introduction to programming]?](/img/ae/68a5880f313c307880ac80bd200530.jpg)
Is there any good website or software for learning programming? [introduction to programming]?

Use and principle of wait notify

智慧运维:基于 BIM 技术的可视化管理系统

导电滑环使用的注意事项

Set集合详细讲解
随机推荐
Design and application of immutable classes
3D建模与处理软件简介 刘利刚 中国科技大学
Set集合详细讲解
Global and Chinese market of solder wire 2022-2028: Research Report on technology, participants, trends, market size and share
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
Daily question -leetcode1175- permutation of prime numbers - Mathematics
Leetcode522- longest special sequence ii- hash table - String - double pointer
LevelDB源码分析之LRU Cache
More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv. so‘.
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Use and principle of reentrantlock
Global and Chinese market of digital badge 2022-2028: Research Report on technology, participants, trends, market size and share
Intelligent operation and maintenance: visual management system based on BIM Technology
JDBC常见面试题
Flowable source code comment (XXXIX) task listener
Go learning notes (5) basic types and declarations (4)
复制宝贝提示材质不能为空,如何解决?
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
How to start learning editing? Detailed analysis of zero basis
Is there any good website or software for learning programming? [introduction to programming]?