|
64 | 64 | ], |
65 | 65 | "primaryKey": "orderkey", |
66 | 66 | }, |
| 67 | + { |
| 68 | + "name": "null_test", |
| 69 | + "tableReference": { |
| 70 | + "schema": "dbo", |
| 71 | + "table": "null_test", |
| 72 | + }, |
| 73 | + "columns": [ |
| 74 | + {"name": "id", "type": "integer"}, |
| 75 | + {"name": "letter", "type": "varchar"}, |
| 76 | + ], |
| 77 | + }, |
67 | 78 | ], |
68 | 79 | } |
69 | 80 |
|
@@ -103,6 +114,13 @@ def mssql(request) -> SqlServerContainer: |
103 | 114 | @level2type = N'COLUMN', @level2name = 'o_comment'; |
104 | 115 | """) |
105 | 116 | ) |
| 117 | + conn.execute(text('CREATE TABLE "null_test" ("id" INT, "letter" TEXT)')) |
| 118 | + conn.execute( |
| 119 | + text( |
| 120 | + "INSERT INTO \"null_test\" (\"id\", \"letter\") VALUES (1, 'one'), (2, 'two'), (NULL, 'three')" |
| 121 | + ) |
| 122 | + ) |
| 123 | + |
106 | 124 | request.addfinalizer(mssql.stop) |
107 | 125 | return mssql |
108 | 126 |
|
@@ -438,6 +456,58 @@ async def test_password_with_special_characters(client): |
438 | 456 | assert "Microsoft SQL Server 2019" in response.text |
439 | 457 |
|
440 | 458 |
|
| 459 | +async def test_order_by_nulls_last(client, manifest_str, mssql: SqlServerContainer): |
| 460 | + connection_info = _to_connection_info(mssql) |
| 461 | + response = await client.post( |
| 462 | + url=f"{base_url}/query", |
| 463 | + json={ |
| 464 | + "connectionInfo": connection_info, |
| 465 | + "manifestStr": manifest_str, |
| 466 | + "sql": 'SELECT letter FROM "null_test" ORDER BY id', |
| 467 | + }, |
| 468 | + params={"limit": 3}, |
| 469 | + ) |
| 470 | + assert response.status_code == 200 |
| 471 | + result = response.json() |
| 472 | + assert len(result["data"]) == 3 |
| 473 | + assert result["data"][0][0] == "one" |
| 474 | + assert result["data"][1][0] == "two" |
| 475 | + assert result["data"][2][0] == "three" |
| 476 | + |
| 477 | + connection_info = _to_connection_info(mssql) |
| 478 | + response = await client.post( |
| 479 | + url=f"{base_url}/query", |
| 480 | + json={ |
| 481 | + "connectionInfo": connection_info, |
| 482 | + "manifestStr": manifest_str, |
| 483 | + "sql": 'SELECT letter FROM "null_test" ORDER BY id LIMIT 3', |
| 484 | + }, |
| 485 | + ) |
| 486 | + assert response.status_code == 200 |
| 487 | + result = response.json() |
| 488 | + assert len(result["data"]) == 3 |
| 489 | + assert result["data"][0][0] == "one" |
| 490 | + assert result["data"][1][0] == "two" |
| 491 | + assert result["data"][2][0] == "three" |
| 492 | + |
| 493 | + |
| 494 | +async def test_order_by_require_limit(client, manifest_str, mssql: SqlServerContainer): |
| 495 | + connection_info = _to_connection_info(mssql) |
| 496 | + response = await client.post( |
| 497 | + url=f"{base_url}/query", |
| 498 | + json={ |
| 499 | + "connectionInfo": connection_info, |
| 500 | + "manifestStr": manifest_str, |
| 501 | + "sql": 'SELECT letter FROM "null_test" ORDER BY id NULLS LAST', |
| 502 | + }, |
| 503 | + ) |
| 504 | + assert response.status_code == 422 |
| 505 | + assert ( |
| 506 | + "The query with order-by requires a specific limit to be set in MSSQL." |
| 507 | + in response.text |
| 508 | + ) |
| 509 | + |
| 510 | + |
441 | 511 | def _to_connection_info(mssql: SqlServerContainer): |
442 | 512 | return { |
443 | 513 | "host": mssql.get_container_host_ip(), |
|
0 commit comments