本文整理汇总了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;"));
}
}
}
示例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;"));
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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;"));
}
}