当前位置:网站首页>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 ~
边栏推荐
- Programmers dig "holes" to get rich: if they find a loophole, they will be rewarded 12.72 million yuan
- C# wpf 使用DockPanel实现截屏框
- Application of industrial conductive slip ring
- What can the points mall Games bring to businesses? How to build a points mall?
- Global and Chinese market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
- Unit testing with mongodb
- Cockroachdb: the resistant geo distributed SQL database paper reading notes
- Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
- Tar command
猜你喜欢

And search: the suspects (find the number of people related to the nth person)

Deeply understand the underlying implementation principle of countdownlatch in concurrent programming

LRU cache for leveldb source code analysis

C WPF uses dockpanel to realize screenshot box

小程序常用组件小结

Vmware workstation network card settings and three common network modes

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

Memtable for leveldb source code analysis

How to select conductive slip ring material

Redis database deployment and common commands
随机推荐
Like cloud functions
How to create a progress bar that changes color according to progress
0xc000007b应用程序无法正常启动解决方案(亲测有效)
Youqitong [vip] v3.7.2022.0106 official January 22 Edition
Spanner 论文小结
Global and Chinese markets of gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share
使用 Nocalhost 开发 Rainbond 上的微服务应用
[RootersCTF2019]babyWeb
Memtable for leveldb source code analysis
Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
Use and principle of wait notify
Web Security (x) what is OAuth 2.0?
Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
[ffmpeg] [reprint] image mosaic: picture in picture with wheat
Rainbow combines neuvector to practice container safety management
Use and principle of AQS related implementation classes
Receiving package install and uninstall events
What can the points mall Games bring to businesses? How to build a points mall?
C# wpf 使用DockPanel实现截屏框
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster