Skip to content

Add schema to mssql#11856

Merged
ZoranPandovski merged 3 commits into
developfrom
mssql-schema
Nov 7, 2025
Merged

Add schema to mssql#11856
ZoranPandovski merged 3 commits into
developfrom
mssql-schema

Conversation

@ZoranPandovski
Copy link
Copy Markdown
Member

@ZoranPandovski ZoranPandovski commented Nov 6, 2025

Description

Fixes the issue where AI agents generate SQL queries without schema qualifiers, causing queries to fail when user data is in a specific schema. Now, we check if schema exist and use that schema without the need to ALTER users table for MS SQL

Type of change

(Please delete options that are not relevant)

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ⚡ New feature (non-breaking change which adds functionality)
  • 📢 Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • 📄 This change requires a documentation update

Checklist:

  • My code follows the style guidelines(PEP 8) of MindsDB.
  • I have appropriately commented on my code, especially in complex areas.
  • Necessary documentation updates are either made or tracked in issues.
  • Relevant unit and integration tests are updated or added.

@entelligence-ai-pr-reviews
Copy link
Copy Markdown
Contributor

🔒 Entelligence AI Vulnerability Scanner

No security vulnerabilities found!

Your code passed our comprehensive security analysis.

📊 Files Analyzed: 1 files


@entelligence-ai-pr-reviews
Copy link
Copy Markdown
Contributor

Review Summary

🏷️ Draft Comments (2)

Skipped posting 2 draft comments that were valid but scored below your review threshold (>=13/15). Feel free to update them here.

mindsdb/integrations/handlers/mssql_handler/mssql_handler.py (2)

408-687: get_tables, get_columns, and other meta methods build SQL queries by directly interpolating schema and table names, which can cause runtime SQL errors or incorrect results if these identifiers contain special characters or reserved words.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 3/5
  • Urgency Impact: 4/5
  • Total Score: 11/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb/integrations/handlers/mssql_handler/mssql_handler.py, lines 408-687, several methods (e.g., get_tables, get_columns, meta_get_tables, meta_get_columns, etc.) build SQL queries by directly interpolating schema and table names into the query string. This can cause runtime SQL errors or incorrect results if the schema or table names contain special characters or reserved words. Please update all such interpolations to use proper SQL Server identifier quoting (e.g., wrap identifiers in square brackets or use parameterization where possible), and escape single quotes in string literals (e.g., N'{self.schema.replace("'", "''")}'). Ensure all dynamic identifiers are safely handled to prevent runtime failures.

59-152: _make_table_response (lines 59-152) is a large, complex function with many branches and statements, making it difficult to maintain and optimize for performance as the codebase grows.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Refactor the `_make_table_response` function in mindsdb/integrations/handlers/mssql_handler/mssql_handler.py (lines 59-152). The function is overly complex, with many branches and statements, making it hard to maintain and optimize. Break it into smaller, well-named helper functions for type inference, DataFrame construction, and MySQL type mapping. Ensure the refactored code preserves all current logic and performance characteristics.

@ZoranPandovski ZoranPandovski merged commit bde93d5 into develop Nov 7, 2025
23 checks passed
@ZoranPandovski ZoranPandovski deleted the mssql-schema branch November 7, 2025 16:38
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants