Commit 1566c67
Theekshna Kotian
Merged PR 5282: Check if statement is prepared before calling SQLExecute
- If you send a statement with param markers & params list to DDBCSQLExecute, with usePrepare=false, the C++ code will bind the params & then call SQLExecute without preparing the statement. The ODBC code for SQLExecute crashes due to a memory violation.
- SQLExecute is supposed to be called only after preparing a statement. Ideally this case should give an error. But it's causing a crash in python driver
- RCA - after attaching debugger & stepping over the DDBC & ODBC code, it looks like the check to error out when user executes without prepare is handled by windows Driver Manager. So ODBC code assumes this as a given & doesn't have checks around it. This is causing memory violation.
Since Python Driver will not use Driver Manager, this task adds a check inside Python Driver to make sure that we don't call SQLExecute API on unprepared statements.
**Implementation details:**
- ODBC has internal fields to tell if a statement is already prepared or not, but it does not expose these APIs to external users. So we cannot use ODBC APIs to tell if a statement is prepared.
- The only other alternative is populate the is_stmt_prepared info in C++ code, but save this state for every statement in cursor class of Python code. This is what I've implemented
**This PR also has following changes:**
- Removed parameter binding code from SQLExecute_wrap & refactored it into BindParameters function.
- Provide Release/Debug as parameter to build.bat script
----
----
#### AI description (iteration 1)
#### PR Classification
Bug fix to prevent memory violation by ensuring SQLExecute is called only on prepared statements.
#### PR Summary
This pull request adds a check to ensure that SQLExecute is not called on unprepared statements, preventing a memory violation crash in the Python driver.
- `mssql_python/pybind/ddbc_bindings.cpp`: Added a check to ensure statements are prepared before calling SQLExecute and refactored parameter binding into a separate function.
- `mssql_python/pybind/build.bat`: Updated build script to support different build types (Debug/Release).
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
Related work items: #337231 parent 5d62207 commit 1566c67
4 files changed
Lines changed: 323 additions & 251 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| |||
433 | 438 | | |
434 | 439 | | |
435 | 440 | | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
436 | 448 | | |
437 | 449 | | |
438 | 450 | | |
439 | | - | |
| 451 | + | |
| 452 | + | |
440 | 453 | | |
| 454 | + | |
441 | 455 | | |
442 | 456 | | |
443 | 457 | | |
| |||
460 | 474 | | |
461 | 475 | | |
462 | 476 | | |
| 477 | + | |
463 | 478 | | |
464 | 479 | | |
465 | 480 | | |
466 | 481 | | |
467 | 482 | | |
468 | 483 | | |
469 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
470 | 494 | | |
471 | 495 | | |
472 | 496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
1 | 8 | | |
2 | 9 | | |
3 | 10 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
7 | 21 | | |
8 | | - | |
| |||
0 commit comments