aminghadersohi opened a new pull request, #44706:
URL: https://github.com/apache/superset/pull/44706

   ### SUMMARY
   
   SQL Lab passes the selected schema to `Db2EngineSpec.get_prequeries` as 
listed by the SQLAlchemy inspector. The DB2 dialect normalizes unquoted 
(upper-case) DB2 names to lower case, so a schema stored as `DB2INST1` is 
listed as `db2inst1`. `get_prequeries` quoted that value as-is:
   
   ```sql
   set current_schema "db2inst1"
   ```
   
   A quoted identifier is case-sensitive in DB2, so this selects a different, 
usually non-existent, schema, and every unqualified query in SQL Lab then fails:
   
   ```
   SQL0204N  "db2inst1.ORDERS" is an undefined name.  SQLSTATE=42704
   ```
   
   This change converts the listed name back to the name stored in the catalog 
with the dialect's `denormalize_name` before quoting it (`db2inst1` → 
`DB2INST1`, mixed-case names unchanged), keeping the existing quote escaping.
   
   ### BEFORE/AFTER
   
   Against a local DB2 LUW 11.5.9.0 server, running 
`sql_lab.execute_sql_statements` for `SELECT SUM(AMOUNT) AS TOTAL FROM ORDERS` 
with the schema picked from `Database.get_all_schema_names()`:
   
   - Before: query fails with `SQL0204N "sqllab….ORDERS" is an undefined name`.
   - After: query succeeds and returns the expected row.
   
   ### TESTING INSTRUCTIONS
   
   `pytest tests/unit_tests/db_engine_specs/test_db2.py` — 
`test_get_prequeries` now covers a lower-case listed name, a mixed-case name 
and quote escaping (fails before this change, 15 passed after).
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: no
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to