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


C# SqliteConnection.ExecuteScalar方法代码示例

本文整理汇总了C#中Microsoft.Data.Sqlite.SqliteConnection.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.ExecuteScalar方法的具体用法?C# SqliteConnection.ExecuteScalar怎么用?C# SqliteConnection.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Data.Sqlite.SqliteConnection的用法示例。


在下文中一共展示了SqliteConnection.ExecuteScalar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Ctor_unsets_read_uncommitted_when_serializable

        public void Ctor_unsets_read_uncommitted_when_serializable()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                using (connection.BeginTransaction(IsolationLevel.Serializable))
                {
                    Assert.Equal(0L, connection.ExecuteScalar<long>("PRAGMA read_uncommitted;"));
                }
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:12,代码来源:SqliteTransactionTest.cs

示例2: Ctor_sets_read_uncommitted

        public void Ctor_sets_read_uncommitted()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:;Cache=Shared"))
            {
                connection.Open();

                using (connection.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    Assert.Equal(1L, connection.ExecuteScalar<long>("PRAGMA read_uncommitted;"));
                }
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:12,代码来源:SqliteTransactionTest.cs

示例3: Open_works_when_memory_shared

        public void Open_works_when_memory_shared()
        {
            var connectionString = "Data Source=people;Mode=Memory;Cache=Shared";

            using (var connection1 = new SqliteConnection(connectionString))
            {
                connection1.Open();

                connection1.ExecuteNonQuery(
                    "CREATE TABLE Person (Name TEXT);" +
                    "INSERT INTO Person VALUES ('Waldo');");

                using (var connection2 = new SqliteConnection(connectionString))
                {
                    connection2.Open();

                    var name = connection2.ExecuteScalar<string>("SELECT Name FROM Person;");
                    Assert.Equal("Waldo", name);
                }
            }
        }
开发者ID:leloulight,项目名称:Microsoft.Data.Sqlite,代码行数:21,代码来源:SqliteConnectionTest.cs

示例4: Open_works_when_readonly

        public void Open_works_when_readonly()
        {
            using (var connection = new SqliteConnection("Data Source=readonly.db"))
            {
                connection.Open();

                if (connection.ExecuteScalar<long>("SELECT COUNT(*) FROM sqlite_master WHERE name = 'Idomic';") == 0)
                {
                    connection.ExecuteNonQuery("CREATE TABLE Idomic (Word TEXT);");
                }
            }

            using (var connection = new SqliteConnection("Data Source=readonly.db;Mode=ReadOnly"))
            {
                connection.Open();

                var ex = Assert.Throws<SqliteException>(
                    () => connection.ExecuteNonQuery("INSERT INTO Idomic VALUES ('arimfexendrapuse');"));

                Assert.Equal(SQLITE_READONLY, ex.SqliteErrorCode);
            }
        }
开发者ID:leloulight,项目名称:Microsoft.Data.Sqlite,代码行数:22,代码来源:SqliteConnectionTest.cs

示例5: Dispose_works

        public void Dispose_works()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();
                CreateTestTable(connection);

                using (var transaction = connection.BeginTransaction())
                {
                    connection.ExecuteNonQuery("INSERT INTO TestTable VALUES (1);");

                    transaction.Dispose();

                    Assert.Null(connection.Transaction);
                    Assert.Null(transaction.Connection);
                }

                Assert.Equal(0L, connection.ExecuteScalar<long>("SELECT COUNT(*) FROM TestTable;"));
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:20,代码来源:SqliteTransactionTest.cs


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