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


C# NpgsqlConnection.BeginBinaryImport方法代码示例

本文整理汇总了C#中Npgsql.NpgsqlConnection.BeginBinaryImport方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlConnection.BeginBinaryImport方法的具体用法?C# NpgsqlConnection.BeginBinaryImport怎么用?C# NpgsqlConnection.BeginBinaryImport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Npgsql.NpgsqlConnection的用法示例。


在下文中一共展示了NpgsqlConnection.BeginBinaryImport方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CancelBinaryImport

        public void CancelBinaryImport()
        {
            using (var conn = new NpgsqlConnection(ConnectionString))
            {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (field_text TEXT, field_int2 SMALLINT, field_int4 INTEGER)", conn);
                using (var writer = conn.BeginBinaryImport("COPY data (field_text, field_int4) FROM STDIN BINARY"))
                {
                    writer.StartRow();
                    writer.Write("Hello");
                    writer.Write(8);

                    writer.Cancel();
                }
                Assert.That(ExecuteScalar(@"SELECT COUNT(*) FROM data", conn), Is.EqualTo(0));
            }
        }
开发者ID:neisbut,项目名称:npgsql,代码行数:17,代码来源:CopyTests.cs

示例2: CreateAndFillEvents

		private void CreateAndFillEvents()
		{
			var creator = new TableBuilder(PostgresFixture.ConnectionString);
			creator.CreateTable(typeof(Guid), StreamName);

			using (var connection = new NpgsqlConnection(PostgresFixture.ConnectionString))
			{
				connection.Open();

				var id = Guid.NewGuid();

				var events = Enumerable
					.Range(0, TotalRecords)
					.Select(i => i.AsSequence())
					.Select(seq => new TestEvent { AggregateID = id, Sequence = seq, Stamp = DefaultStamper.Now() });

				using (var writer = connection.BeginBinaryImport("COPY importstream_events(aggregateid, sequence, eventtype, event) from STDIN (format binary)"))
				{
					foreach (var @event in events)
					{
						writer.StartRow();

						writer.Write(@event.AggregateID.ToString(), NpgsqlDbType.Uuid);
						writer.Write((int)@event.Sequence);
						writer.Write(@event.GetType().AssemblyQualifiedName);
						writer.Write(Serializer.Serialize(@event));
					}
				}
			}
		}
开发者ID:Pondidum,项目名称:Ledger.Stores.Postgres,代码行数:30,代码来源:PostgresStoreReaderTests.cs

示例3: UnexpectedExceptionBinaryImport

        public void UnexpectedExceptionBinaryImport()
        {
            var conn = new NpgsqlConnection(ConnectionString);
            conn.Open();
            ExecuteNonQuery("CREATE TEMP TABLE data (blob BYTEA)", conn);

            var data = new byte[conn.BufferSize + 10];

            var writer = conn.BeginBinaryImport("COPY data (blob) FROM STDIN BINARY");
            ExecuteNonQuery(string.Format("SELECT pg_terminate_backend({0})", conn.ProcessID));
            Thread.Sleep(50);
            Assert.That(() =>
            {
                writer.StartRow();
                writer.Write(data);
                writer.Dispose();
            }, Throws.Exception.TypeOf<IOException>());
            Assert.That(conn.FullState, Is.EqualTo(ConnectionState.Broken));
        }
开发者ID:neisbut,项目名称:npgsql,代码行数:19,代码来源:CopyTests.cs

示例4: ImportDirectBuffer

        public void ImportDirectBuffer()
        {
            using (var conn = new NpgsqlConnection(ConnectionString))
            {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (blob BYTEA)", conn);

                using (var writer = conn.BeginBinaryImport("COPY data (blob) FROM STDIN BINARY"))
                {
                    // Big value - triggers use of the direct buffer optimization
                    var data = new byte[conn.BufferSize + 10];

                    writer.StartRow();
                    writer.Write(data);
                    writer.StartRow();
                    writer.Write(data);
                    writer.Dispose();
                }
            }
        }
开发者ID:neisbut,项目名称:npgsql,代码行数:20,代码来源:CopyTests.cs

示例5: CloseDuringCopy

        public void CloseDuringCopy()
        {
            // TODO: Check no broken connections were returned to the pool
            using (var conn = new NpgsqlConnection(ConnectionString)) {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (field_text TEXT, field_int2 SMALLINT, field_int4 INTEGER)", conn);
                conn.BeginBinaryImport("COPY data (field_text, field_int4) FROM STDIN BINARY");
            }

            using (var conn = new NpgsqlConnection(ConnectionString)) {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (field_text TEXT, field_int2 SMALLINT, field_int4 INTEGER)", conn);
                conn.BeginBinaryExport("COPY data (field_text, field_int2) TO STDIN BINARY");
            }

            using (var conn = new NpgsqlConnection(ConnectionString)) {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (field_text TEXT, field_int2 SMALLINT, field_int4 INTEGER)", conn);
                conn.BeginRawBinaryCopy("COPY data (field_text, field_int4) FROM STDIN BINARY");
            }

            using (var conn = new NpgsqlConnection(ConnectionString)) {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (field_text TEXT, field_int2 SMALLINT, field_int4 INTEGER)", conn);
                conn.BeginRawBinaryCopy("COPY data (field_text, field_int4) TO STDIN BINARY");
            }

            using (var conn = new NpgsqlConnection(ConnectionString)) {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (field_text TEXT, field_int2 SMALLINT, field_int4 INTEGER)", conn);
                conn.BeginTextImport("COPY data (field_text, field_int4) FROM STDIN");
            }

            using (var conn = new NpgsqlConnection(ConnectionString)) {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (field_text TEXT, field_int2 SMALLINT, field_int4 INTEGER)", conn);
                conn.BeginTextExport("COPY data (field_text, field_int4) TO STDIN");
            }
        }
开发者ID:neisbut,项目名称:npgsql,代码行数:39,代码来源:CopyTests.cs


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