本文整理汇总了C#中Microsoft.Data.Sqlite.SqliteConnection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.BeginTransaction方法的具体用法?C# SqliteConnection.BeginTransaction怎么用?C# SqliteConnection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Data.Sqlite.SqliteConnection
的用法示例。
在下文中一共展示了SqliteConnection.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Ctor_throws_when_invalid_isolation_level
public void Ctor_throws_when_invalid_isolation_level()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
var ex = Assert.Throws<ArgumentException>(() => connection.BeginTransaction(IsolationLevel.Snapshot));
Assert.Equal(Strings.FormatInvalidIsolationLevel(IsolationLevel.Snapshot), ex.Message);
}
}
示例2: CreateShared
private SqliteTestStore CreateShared(Action initializeDatabase)
{
CreateShared(typeof(SqliteTestStore).Name + _name, initializeDatabase);
_connection = new SqliteConnection(CreateConnectionString(_name));
_connection.Open();
_transaction = _connection.BeginTransaction();
return this;
}
示例3: 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;"));
}
}
}
示例4: 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;"));
}
}
}
示例5: IsolationLevel_throws_when_completed
public void IsolationLevel_throws_when_completed()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
var transaction = connection.BeginTransaction();
transaction.Dispose();
var ex = Assert.Throws<InvalidOperationException>(() => transaction.IsolationLevel);
Assert.Equal(Strings.TransactionCompleted, ex.Message);
}
}
示例6: Ctor_throws_when_invalid_isolation_level_without_cache
public void Ctor_throws_when_invalid_isolation_level_without_cache()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
var ex = Assert.Throws<ArgumentException>(() => connection.BeginTransaction(IsolationLevel.ReadUncommitted));
Assert.Equal(Strings.FormatInvalidIsolationLevelForUnsharedCache(IsolationLevel.ReadUncommitted), ex.Message);
}
using (var connection = new SqliteConnection("Data Source=:memory:;Cache=Shared"))
{
connection.Open();
connection.BeginTransaction(IsolationLevel.ReadUncommitted);
}
}
示例7: Ctor_sets_values
public void Ctor_sets_values()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
var command = new SqliteCommand("SELECT 1;", connection, transaction);
Assert.Equal("SELECT 1;", command.CommandText);
Assert.Same(connection, command.Connection);
Assert.Same(transaction, command.Transaction);
}
}
}
示例8: BeginTransaction_throws_when_closed
public void BeginTransaction_throws_when_closed()
{
var connection = new SqliteConnection();
var ex = Assert.Throws<InvalidOperationException>(() => connection.BeginTransaction());
Assert.Equal(Strings.FormatCallRequiresOpenConnection("BeginTransaction"), ex.Message);
}
示例9: CreateCommand_returns_command
public void CreateCommand_returns_command()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
var command = connection.CreateCommand();
Assert.NotNull(command);
Assert.Same(connection, command.Connection);
Assert.Same(transaction, command.Transaction);
}
}
}
示例10: ExecuteReader_throws_when_transaction_mismatched
public void ExecuteReader_throws_when_transaction_mismatched()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
var command = connection.CreateCommand();
command.CommandText = "SELECT 1;";
connection.Open();
using (var otherConnection = new SqliteConnection("Data Source=:memory:"))
{
otherConnection.Open();
using (var transction = otherConnection.BeginTransaction())
{
command.Transaction = transction;
var ex = Assert.Throws<InvalidOperationException>(() => command.ExecuteReader());
Assert.Equal(Strings.TransactionConnectionMismatch, ex.Message);
}
}
}
}
示例11: IsolationLevel_is_infered_when_unspecified
public void IsolationLevel_is_infered_when_unspecified()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
connection.ExecuteNonQuery("PRAGMA read_uncommitted = 1;");
using (var transaction = connection.BeginTransaction())
{
Assert.Equal(IsolationLevel.ReadUncommitted, transaction.IsolationLevel);
}
}
}
示例12: Dispose_can_be_called_more_than_once
public void Dispose_can_be_called_more_than_once()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
var transaction = connection.BeginTransaction();
transaction.Dispose();
transaction.Dispose();
}
}
示例13: Serializable_locks
public void Serializable_locks()
{
using (var connectionA = new SqliteConnection("Data Source=testdb;Mode=Memory;Cache=Shared"))
{
connectionA.Open();
using (var transactionA = connectionA.BeginTransaction(IsolationLevel.Serializable))
{
using (var connectionB = new SqliteConnection("Data Source=testdb;Mode=Memory;Cache=Shared"))
{
connectionB.Open();
var ex = Assert.Throws<SqliteException>(() => new SqliteTransaction(connectionB, IsolationLevel.Serializable, 1));
Assert.Equal(SQLITE_LOCKED, ex.SqliteErrorCode);
}
}
}
}
示例14: 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;"));
}
}
示例15: BeginTransaction_throws_when_parallel_transaction
public void BeginTransaction_throws_when_parallel_transaction()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
using (connection.BeginTransaction())
{
var ex = Assert.Throws<InvalidOperationException>(() => connection.BeginTransaction());
Assert.Equal(Strings.ParallelTransactionsNotSupported, ex.Message);
}
}
}