Commit c677819
Returning ids/rows after bulk insert (#107)
* Implement can_return_rows_from_bulk_insert feature, returning ids or rows after bulk inserts.
* Since mssql-django supports Django 2.2, we also need the pre-Django 3.0 version of feature flag can_return_rows_from_bulk_insert (namely, can_return_ids_from_bulk_insert) (cf. https://docs.djangoproject.com/en/4.0/releases/3.0/#database-backend-api)
* My alternative changes on SQLInsertCompiler.as_sql.
Maybe a bit ambitious, as we completely forsake the SCOPE_IDENTITY strategy (dead code path - we keep the code here, but we could decide not to, really) in favor of OUTPUT strategy.
* Don't try to use the OUTPUT clause when inserting without fields
* Actually we don't really have to offer the feature for Django 2.2, so let's only set can_return_rows_from_bulk_insert to True and not can_return_ids_from_bulk_insert
* Tentative fix: when there are returning fields, but no fields (which means default values insertion - for n objects of course!), we must still fulfill our contract, and return the appropriate rows.
This means we won't use INSERT INTO (...) DEFAULT VALUES n times, but a single INSERT INTO (...) VALUES (DEFAULT, (...), DEFAULT), (...), (DEFAULT, (...), DEFAULT)
Also: be more thorough re the infamous feature flag rename from Django 3.0
* Using MERGE INTO to support Bulk Insertion of multiple rows into a table with only an IDENTITY column.
* Add a link to a reference web page.
* Attempt to make Django 2.2 tests pass
* Get back to a lighter diff of as_sql function vs. original
* Use a query to generate sequence of numbers instead of using the master....spt_values table.
* Update mssql/operations.py
Co-authored-by: marcperrinoptel <[email protected]>
* Simplification & refactoring
Co-authored-by: marcperrinoptel <[email protected]>
Co-authored-by: marcperrinoptel <[email protected]>1 parent db20051 commit c677819
3 files changed
+79
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
429 | 439 | | |
430 | 440 | | |
431 | 441 | | |
| |||
441 | 451 | | |
442 | 452 | | |
443 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
444 | 478 | | |
445 | 479 | | |
446 | 480 | | |
447 | 481 | | |
448 | 482 | | |
449 | 483 | | |
450 | | - | |
451 | 484 | | |
452 | 485 | | |
| 486 | + | |
453 | 487 | | |
454 | 488 | | |
455 | 489 | | |
| |||
470 | 504 | | |
471 | 505 | | |
472 | 506 | | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
478 | 532 | | |
479 | 533 | | |
480 | 534 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
191 | 209 | | |
192 | 210 | | |
193 | 211 | | |
| |||
0 commit comments