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


C# NpgsqlConnection.ExecuteNonQuery方法代码示例

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

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

示例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)");
        }
开发者ID:npgsql,项目名称:npgsql,代码行数:20,代码来源:SystemTransactionTests.cs

示例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" }));
         }
     }
 }
开发者ID:ArsenShnurkov,项目名称:npgsql,代码行数:17,代码来源:EnumTests.cs

示例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" +
                          ")");
 }
开发者ID:ArsenShnurkov,项目名称:npgsql,代码行数:11,代码来源:DataAdapterTests.cs

示例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));
            }
        }
开发者ID:ArsenShnurkov,项目名称:npgsql,代码行数:27,代码来源:TransactionTests.cs


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