当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.ExecuteAsync方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:alexf2,项目名称:ReactiveWebServerProto,代码行数:8,代码来源:GuestBookSqlLiteProvider.cs

示例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;
        }
开发者ID:alexf2,项目名称:ReactiveWebServerProto,代码行数:23,代码来源:GuestBookSqlLiteProvider.cs

示例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;
        }
开发者ID:alexf2,项目名称:ReactiveWebServerProto,代码行数:15,代码来源:GuestBookSqlLiteProvider.cs

示例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);
     }
 }
开发者ID:alexf2,项目名称:ReactiveWebServerProto,代码行数:8,代码来源:GuestBookSqlLiteProvider.cs


注:本文中的System.Data.SQLite.SQLiteConnection.ExecuteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。