ExportData() public méthode

public ExportData ( string conn, TextWriter data, string tableHint = null ) : void
conn string
data System.IO.TextWriter
tableHint string
Résultat void
Exemple #1
0
		public void TestExportData() {
			var t = new Table("dbo", "Status");
			t.Columns.Add(new Column("id", "int", false, null));
			t.Columns.Add(new Column("code", "char", 1, false, null));
			t.Columns.Add(new Column("description", "varchar", 20, false, null));
			t.Columns.Find("id").Identity = new Identity(1, 1);
			t.AddConstraint(new Constraint("PK_Status", "PRIMARY KEY", "id"));

			var conn = TestHelper.GetConnString("TESTDB");
			DBHelper.DropDb(conn);
			DBHelper.CreateDb(conn);
			SqlConnection.ClearAllPools();
			DBHelper.ExecBatchSql(conn, t.ScriptCreate());

			var dataIn =
				@"1	R	Ready
2	P	Processing
3	F	Frozen
";
			var filename = Path.GetTempFileName();

			var writer = File.AppendText(filename);
			writer.Write(dataIn);
			writer.Flush();
			writer.Close();

			t.ImportData(conn, filename);
			var sw = new StringWriter();
			t.ExportData(conn, sw);
			Assert.AreEqual(dataIn, sw.ToString());

			File.Delete(filename);
		}
Exemple #2
0
		public void TestLargeAmountOfRowsImportAndExport() {
			var t = new Table("dbo", "TestData");
			t.Columns.Add(new Column("test_field", "int", false, null));
			t.AddConstraint(new Constraint("PK_TestData", "PRIMARY KEY", "test_field"));
			t.AddConstraint(new Constraint("IX_TestData_PK", "INDEX", "test_field") { Clustered = true, Table = t, Unique = true }); // clustered index is required to ensure the row order is the same as what we import

			var conn = TestHelper.GetConnString("TESTDB");
			DBHelper.DropDb(conn);
			DBHelper.CreateDb(conn);
			SqlConnection.ClearAllPools();
			DBHelper.ExecBatchSql(conn, t.ScriptCreate());

			var filename = Path.GetTempFileName();

			var writer = File.CreateText(filename);
			StringBuilder sb = new StringBuilder();

			for (var i = 0; i < Table.rowsInBatch * 4.2; i++) {
				sb.AppendLine(i.ToString());
				writer.WriteLine(i.ToString());
			}

			writer.Flush();
			writer.Close();

			var dataIn = sb.ToString();
			Assert.AreEqual(dataIn, File.ReadAllText(filename)); // just prove that the file and the string are the same, to make the next assertion meaningful!

			try {
				t.ImportData(conn, filename);
				var sw = new StringWriter();
				t.ExportData(conn, sw);

				Assert.AreEqual(dataIn, sw.ToString());
			} finally {
				File.Delete(filename);
			}
		}