當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。