diff --git a/Library/Models/Table.cs b/Library/Models/Table.cs index 51c3d79..7c27486 100644 --- a/Library/Models/Table.cs +++ b/Library/Models/Table.cs @@ -165,7 +165,8 @@ public void ExportData(string conn, TextWriter data, string tableHint = null) { var ordinal = dr.GetOrdinal(c.Name); if (dr.IsDBNull(ordinal)) data.Write(_nullValue); - else if (dr.GetDataTypeName(ordinal).EndsWith(".sys.geometry")) + else if (dr.GetDataTypeName(ordinal).EndsWith(".sys.geometry") + || dr.GetDataTypeName(ordinal).EndsWith(".sys.geography")) // https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2012/ms143179(v=sql.110)?redirectedfrom=MSDN#sql-clr-data-types-geometry-geography-and-hierarchyid data.Write(StringUtil.ToHexString(dr.GetSqlBytes(ordinal).Value)); else if (dr[c.Name] is byte[]) diff --git a/Test/Integration/TableTest.cs b/Test/Integration/TableTest.cs index f65dc67..0565cca 100644 --- a/Test/Integration/TableTest.cs +++ b/Test/Integration/TableTest.cs @@ -247,6 +247,7 @@ public async Task TestScript() { t.Columns.Add(new Column("cc", "xml", true, null)); t.Columns.Add(new Column("dd", "hierarchyid", false, null)); t.Columns.Add(new Column("ee", "geometry", false, null)); + t.Columns.Add(new Column("ff", "geography", false, null)); await using var testDb = await _dbHelper.CreateTestDbAsync(); await testDb.ExecSqlAsync(t.ScriptCreate()); @@ -283,4 +284,35 @@ public async Task TestImportExportGeometryData() { File.Delete(filename); } } + + [Fact] + public async Task TestImportExportGeographyData() { + var t = new Table("dbo", "PointsOfInterest"); + t.Columns.Add(new Column("id", "int", false, null)); + t.Columns.Add(new Column("location", "geography", false, null)); + t.Columns.Find("id").Identity = new Identity(1, 1); + t.AddConstraint(new Constraint("PK_PointsOfInterest", "PRIMARY KEY", "id")); + + await using var testDb = await _dbHelper.CreateTestDbAsync(); + await testDb.ExecSqlAsync(t.ScriptCreate()); + + var dataIn = + @"1 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0" + Environment.NewLine; + + var filename = Path.GetTempFileName(); + + var writer = File.AppendText(filename); + writer.Write(dataIn); + writer.Flush(); + writer.Close(); + + try { + t.ImportData(testDb.GetConnString(), filename); + var sw = new StringWriter(); + t.ExportData(testDb.GetConnString(), sw); + Assert.Equal(dataIn, sw.ToString()); + } finally { + File.Delete(filename); + } + } }