本文整理汇总了C#中System.Data.SQLite.SQLiteConnection.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.ExecuteAsync方法的具体用法?C# SQLiteConnection.ExecuteAsync怎么用?C# SQLiteConnection.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SQLite.SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.ExecuteAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clear
public async Task Clear()
{
using (var conn = new SQLiteConnection(_connectionString))
{
await conn.OpenAsync().ConfigureAwait(false);
await conn.ExecuteAsync("delete from [User]").ConfigureAwait(false);
}
}
示例2: AddMessage
public async Task<UserMessage> AddMessage(string userLogin, string text)
{
var res = new UserMessage() {Text = text, UserLogin = userLogin, Created = DateTime.UtcNow};
using (var conn = new SQLiteConnection(_connectionString))
{
await conn.OpenAsync().ConfigureAwait(false);
int count = await conn.ExecuteAsync(
"insert or ignore into [Message] (Text, Created, UserId) select @text as Text, @created as Created, UserId from [User] where [Login] = @userLogin",
new {text, created = res.Created, userLogin}).ConfigureAwait(false);
if (count == 0)
{
int userId =
await
conn.ExecuteScalarAsync<int>(
"insert into [User] (Login, Created) values(@userLogin, @created); SELECT last_insert_rowid() FROM [User]",
new {userLogin, created = res.Created}).ConfigureAwait(false);
await conn.ExecuteAsync("insert into [Message] (Text, Created, UserId) values(@text, @created, @userId)", new { text, created = res.Created, userId}).ConfigureAwait(false);
}
}
return res;
}
示例3: AddUser
public async Task<UserInfo> AddUser(string userLogin, string displayName)
{
var res = new UserInfo() {UserLogin = userLogin, DisplayName = displayName, Created = DateTime.UtcNow};
using (var conn = new SQLiteConnection(_connectionString))
{
await conn.OpenAsync().ConfigureAwait(false);
int count = await conn.ExecuteAsync("insert or ignore into [User] (Login, Display, Created) values(@userLogin, @displayName, @created)",
new {userLogin, displayName, created = res.Created }).ConfigureAwait(false);
if (count == 0)
throw new Exception($"The user '{userLogin}' already exists");
}
return res;
}
示例4: RemoveUser
public async Task<int> RemoveUser(string userLogin)
{
using (var conn = new SQLiteConnection(_connectionString))
{
await conn.OpenAsync().ConfigureAwait(false);
return await conn.ExecuteAsync("delete from [User] where [Login] = @userLogin", new {userLogin}).ConfigureAwait(false);
}
}