|
10 | 10 | using System.Threading;
|
11 | 11 | using Xunit;
|
12 | 12 | #if NET6_0_OR_GREATER
|
| 13 | +using Microsoft.SqlServer.Types; |
13 | 14 | using Microsoft.Data.SqlClient.Server;
|
14 | 15 | #endif
|
15 | 16 |
|
@@ -243,7 +244,7 @@ public static void Test_WithGuidValue_ShouldReturnGuid()
|
243 | 244 | }
|
244 | 245 |
|
245 | 246 | // Synapse: Parse error at line: 1, column: 8: Incorrect syntax near 'TYPE'.
|
246 |
| - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] |
| 247 | + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] |
247 | 248 | public static void TestParametersWithDatatablesTVPInsert()
|
248 | 249 | {
|
249 | 250 | SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString);
|
@@ -310,6 +311,90 @@ public static void TestParametersWithDatatablesTVPInsert()
|
310 | 311 | }
|
311 | 312 |
|
312 | 313 | #if NET6_0_OR_GREATER
|
| 314 | + // Synapse: Parse error at line: 1, column: 8: Incorrect syntax near 'TYPE'. |
| 315 | + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] |
| 316 | + public static void TestParametersWithSqlRecordsTVPInsert() |
| 317 | + { |
| 318 | + SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString); |
| 319 | + |
| 320 | + SqlGeography geog = SqlGeography.Point(43, -81, 4326); |
| 321 | + |
| 322 | + SqlMetaData[] metadata = new SqlMetaData[] |
| 323 | + { |
| 324 | + new SqlMetaData("Id", SqlDbType.UniqueIdentifier), |
| 325 | + new SqlMetaData("geom", SqlDbType.Udt, typeof(SqlGeography), "Geography") |
| 326 | + }; |
| 327 | + |
| 328 | + SqlDataRecord record1 = new SqlDataRecord(metadata); |
| 329 | + record1.SetValues(Guid.NewGuid(), geog); |
| 330 | + |
| 331 | + SqlDataRecord record2 = new SqlDataRecord(metadata); |
| 332 | + record2.SetValues(Guid.NewGuid(), geog); |
| 333 | + |
| 334 | + IList<SqlDataRecord> featureInserts = new List<SqlDataRecord> |
| 335 | + { |
| 336 | + record1, |
| 337 | + record2, |
| 338 | + }; |
| 339 | + |
| 340 | + using SqlConnection connection = new(builder.ConnectionString); |
| 341 | + string procName = DataTestUtility.GetUniqueNameForSqlServer("Proc"); |
| 342 | + string typeName = DataTestUtility.GetUniqueName("Type"); |
| 343 | + try |
| 344 | + { |
| 345 | + connection.Open(); |
| 346 | + |
| 347 | + using (SqlCommand cmd = connection.CreateCommand()) |
| 348 | + { |
| 349 | + cmd.CommandText = $"CREATE TYPE {typeName} AS TABLE([Id] [uniqueidentifier] NULL, [geom] [geography] NULL)"; |
| 350 | + cmd.ExecuteNonQuery(); |
| 351 | + |
| 352 | + cmd.CommandText = @$"CREATE PROCEDURE {procName} |
| 353 | + @newRoads as {typeName} READONLY |
| 354 | + AS |
| 355 | + BEGIN |
| 356 | + SELECT* FROM @newRoads |
| 357 | + END"; |
| 358 | + cmd.ExecuteNonQuery(); |
| 359 | + |
| 360 | + } |
| 361 | + using (SqlCommand cmd = connection.CreateCommand()) |
| 362 | + { |
| 363 | + // Update Data Using TVPs |
| 364 | + cmd.CommandText = procName; |
| 365 | + cmd.CommandType = CommandType.StoredProcedure; |
| 366 | + |
| 367 | + SqlParameter param = new SqlParameter("@newRoads", SqlDbType.Structured); |
| 368 | + param.Value = featureInserts; |
| 369 | + param.TypeName = typeName; |
| 370 | + |
| 371 | + cmd.Parameters.Add(param); |
| 372 | + |
| 373 | + using var reader = cmd.ExecuteReader(); |
| 374 | + |
| 375 | + Assert.True(reader.HasRows); |
| 376 | + |
| 377 | + int count = 0; |
| 378 | + while (reader.Read()) |
| 379 | + { |
| 380 | + Assert.NotNull(reader[0]); |
| 381 | + Assert.NotNull(reader[1]); |
| 382 | + count++; |
| 383 | + } |
| 384 | + |
| 385 | + Assert.Equal(2, count); |
| 386 | + } |
| 387 | + } |
| 388 | + finally |
| 389 | + { |
| 390 | + using SqlCommand cmd = connection.CreateCommand(); |
| 391 | + cmd.CommandText = "DROP PROCEDURE " + procName; |
| 392 | + cmd.ExecuteNonQuery(); |
| 393 | + cmd.CommandText = "DROP TYPE " + typeName; |
| 394 | + cmd.ExecuteNonQuery(); |
| 395 | + } |
| 396 | + } |
| 397 | + |
313 | 398 | [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
|
314 | 399 | public static void TestDateOnlyTVPDataTable_CommandSP()
|
315 | 400 | {
|
|
0 commit comments