本文整理汇总了C#中Npgsql.NpgsqlConnection.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlConnection.ExecuteNonQuery方法的具体用法?C# NpgsqlConnection.ExecuteNonQuery怎么用?C# NpgsqlConnection.ExecuteNonQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Npgsql.NpgsqlConnection
的用法示例。
在下文中一共展示了NpgsqlConnection.ExecuteNonQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rollback
public void Rollback()
{
var connectionString = ConnectionString + ";enlist=true";
using (var scope = new TransactionScope())
using (var conn = new NpgsqlConnection(connectionString))
{
conn.Open();
Assert.That(conn.ExecuteNonQuery(@"INSERT INTO data (name) VALUES('test')"), Is.EqualTo(1));
// No commit
}
AssertNoPreparedTransactions();
using (var conn = OpenConnection())
Assert.That(conn.ExecuteScalar(@"SELECT COUNT(*) FROM data"), Is.EqualTo(0));
}
示例2: ExplicitEnlist
public void ExplicitEnlist()
{
using (var conn = new NpgsqlConnection(ConnectionString))
using (var scope = new TransactionScope())
{
conn.Open();
conn.EnlistTransaction(Transaction.Current);
Assert.That(conn.ExecuteNonQuery(@"INSERT INTO data (name) VALUES('test')"), Is.EqualTo(1));
scope.Complete();
}
AssertNoPreparedTransactions();
using (var conn = OpenConnection())
Assert.That(conn.ExecuteScalar(@"SELECT COUNT(*) FROM data"), Is.EqualTo(1));
}
示例3: OneTimeSetUp
public void OneTimeSetUp()
{
using (new TransactionScope(TransactionScopeOption.RequiresNew))
{
try
{
Transaction.Current.EnlistPromotableSinglePhase(new FakePromotableSinglePhaseNotification());
}
catch (NotImplementedException)
{
Assert.Ignore("Promotable single phase transactions aren't supported (mono < 3.0.0?)");
}
}
// All tests in this fixture should have totally access to the database they're running on.
// If we run these tests in parallel (i.e. two builds in parallel) they will interfere.
// Solve this by taking a PostgreSQL advisory lock for the lifetime of the fixture.
_controlConn = OpenConnection();
_controlConn.ExecuteNonQuery("SELECT pg_advisory_lock(666)");
}
示例4: ReadUnmappedEnumsAsString
public void ReadUnmappedEnumsAsString()
{
using (var conn = new NpgsqlConnection(ConnectionString))
{
conn.Open();
conn.ExecuteNonQuery("CREATE TYPE pg_temp.mood7 AS ENUM ('Sad', 'Ok', 'Happy')");
conn.ReloadTypes();
using (var cmd = new NpgsqlCommand("SELECT 'Sad'::MOOD7, ARRAY['Ok', 'Happy']::MOOD7[]", conn))
using (var reader = cmd.ExecuteReader())
{
reader.Read();
Assert.That(reader[0], Is.EqualTo("Sad"));
Assert.That(reader.GetDataTypeName(0), Does.StartWith("pg_temp").And.EndsWith("mood7"));
Assert.That(reader[1], Is.EqualTo(new[] { "Ok", "Happy" }));
}
}
}
示例5: Setup
public void Setup(NpgsqlConnection conn)
{
conn.ExecuteNonQuery("CREATE TEMP TABLE data (" +
"field_pk SERIAL PRIMARY KEY," +
"field_serial SERIAL," +
"field_int2 SMALLINT," +
"field_int4 INTEGER," +
"field_numeric NUMERIC," +
"field_timestamp TIMESTAMP" +
")");
}
示例6: PrependedRollbackWhileStartingNewTransaction
public void PrependedRollbackWhileStartingNewTransaction()
{
var connString = new NpgsqlConnectionStringBuilder(ConnectionString) {
CommandTimeout = 600,
InternalCommandTimeout = 30
};
int backendId;
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
backendId = conn.Connector.BackendProcessId;
conn.BeginTransaction();
conn.ExecuteNonQuery("SELECT 1");
}
// Connector is back in the pool with a queued ROLLBACK
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
Assert.That(conn.Connector.BackendProcessId, Is.EqualTo(backendId));
var tx = conn.BeginTransaction();
// We've captured the transaction instance, a new begin transaction is now enqueued after the rollback
conn.ExecuteNonQuery("SELECT 1");
Assert.That(tx.Connection, Is.SameAs(conn));
Assert.That(conn.Connector.Transaction, Is.SameAs(tx));
}
}