Repository navigation
fix(plugin-mssql): establish the required session options and complete the routine list - #2855
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Signed-off-by: Ngô Quốc Đạt <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A SQL Server user reported that TablePro shows no Stored Procedures or Functions. It is not a missing feature and not version skew: the lists are empty on current
main, for every SQL Server connection, and the same cause silently blocks a whole class of writes.Root cause
FreeTDS db-lib inherits Sybase's defaults and hands back a session with none of SQL Server's required SET profile in place. Measured against SQL Server 2022 (16.0.4275.2) with a C probe linked against the shipped
Libs/libsybdb.a:ANSI_NULLSANSI_PADDINGANSI_WARNINGSARITHABORTCONCAT_NULL_YIELDS_NULLQUOTED_IDENTIFIERNUMERIC_ROUNDABORTMSSQLObjectQueries.routineListaggregates a parameter list throughFOR XML PATHand.value('.', 'nvarchar(max)'). That is an XML data type method, and the server refuses it while those options are off:The failure does not stop at browsing. With the options off, an
INSERTinto a table carrying a filtered index or an index on a computed column fails with the sameMsg 1934, so such a row could never be saved. Measured failing with them off and succeeding with them on, on one connection.The fix
MSSQLSessionOptionsestablishes the whole profile, andFreeTDSConnection.adopt()applies it beside theTEXTSIZEit already raised.adoptis the only caller of the plugin's onlydbopen, so every path reaches it: first connect, reconnect, and the metadata pool's own driver. Measured: the options survive a laterdbuse, so a database switch keeps them.A server that refuses one still gets a working connection. db-lib's defaults are wrong rather than fatal, and failing the connect over them would take the database away from a user who could otherwise work in it.
FreeTDSConnection.swiftis compiled into the iOS app as well, so iOS gets this too.Why not rewrite the query instead
Replacing the XML aggregate with
STRING_AGGwas the obvious alternative and does not survive the evidence. It cannot fix theINSERTfailure, which involves no query of ours at all. AndSTRING_AGGis SQL Server 2017+, so it needs a version gate, and the version gate was itself broken (below).NUMERIC_ROUNDABORT is part of the profile and nothing else would have caught it
NUMERIC_ROUNDABORTalready arrives off, so on a default server setting it changes nothing. It is set because a database or a login can carry it on, and a session that inherits it fails those same writes while every other option reads correctly. Measured: with the six ON options set andNUMERIC_ROUNDABORTon, the INSERT fails withMsg 1934namingNUMERIC_ROUNDABORTalone. The first version of this fix set five options and its probe asserted those five, so it would have reported OK on exactly that server while the writes still failed.ARITHABORTis implied byANSI_WARNINGSat compatibility level 90 and above, which is every server TDS 7.4 can reach, so it is belt and braces rather than load-bearing. It is set because Microsoft documents it as part of the profile.Two defects this fix depends on or would have regressed
@@VERSIONwas truncated to 50 characters. On a patched server the build number falls outside the prefix, soMSSQLCapabilities.parsefound nomajor.minor.buildand reported the version as unknown. Measured on 2022 CU26: 50 characters isMicrosoft SQL Server 2022 (RTM-CU26-GDR) (KB512276, and16.0.4275.2is cut off. Every version gate was dead, soCREATE OR ALTERwent unused on servers that have had it since 2016.MSSQLServerBannernow keeps the product line whole for display and matches the build number against the whole banner.CONCAT_NULL_YIELDS_NULL ONwould have regressed the table-size query.CAST(...SUM(a.total_pages)...) + ' MB'yields NULL rather than' MB'once the option is on. Guarded withISNULL(SUM(...), 0). Caught by the review pass, not by me.Also fixed in the same list
CLR and extended routines were never listed. The filter was
o.type IN ('P','FN','IF','TF'), which dropsPC,FS,FT,AFandX. A database holding them listed fewer routines than it has, with nothing saying so. The kind mapping read everything butPas a function, so adding the codes required fixing that too.A routine the caller cannot read was labelled "Encrypted: YES".
sys.sql_modules.definitionis NULL both forWITH ENCRYPTIONand for a caller withoutVIEW DEFINITION. I assumed the module row would be absent in the second case and measured that wrong: a user with only SELECT and EXECUTE still sees the row with a NULL definition.OBJECTPROPERTY(object_id, 'IsEncrypted')does separate them, and answers correctly for that caller, so the two now read differently in the row and throw different errors when opened.CLR and extended routines had no source and were reported as missing. Widening the type filter surfaced them, and
PC,FS,FTandAFlive insys.assembly_moduleswhileXis a DLL entry point, so none has asys.sql_modulesrow. The definition query's inner join returned zero rows for them, which the caller read as "no longer exists" for a routine sitting in the list in front of the reader; the listing also called their source permission-withheld and their language T-SQL. Measured with an object that has no module row: inner join 0 rows, left join 1 row. The query now drives fromsys.objectswith the module table joined on the outside and returns the object type, so a CLR routine reports its language as CLR, claims no SQL source, and says the source cannot be shown rather than inventing a cause.Every routine body was fetched to draw the list and then discarded.
routineListselectedm.definitionand the consumer never read it, so listing a schema pulled its whole source over the wire for nothing.routineDefinitionreads the one the reader opens.Verification
verify.sh build: PASSverify.sh test MSSQLObjectQueryTests PostgreSQLObjectQueryTests: PASSswift testinPackages/TableProCore(56 tests): PASSdocs/scripts/check-writing-style.shandcheck-docs-against-source.py: PASSscripts/check-mssql-session-options.shagainst SQL Server 2022:db-lib defaults: 0 0 0 0 0 0 0thenafter establish: 1 1 1 1 1 1 0No UI automation: every failure here needs a live SQL Server, which
TableProUITestshas no deterministic access to. The probe covers the wired half and the unit tests cover the pure half.A second model reviewed this branch (Codex,
review --scope working-tree). It found four issues, all real and all fixed here: the missingNUMERIC_ROUNDABORT, the CLR routines with no module row, the password in generated C, and an unlocalized attribute label.The probe is committed as
scripts/check-mssql-session-options.shso a FreeTDS bump re-checks it. It reads the option names and their required values out ofMSSQLSessionOptions.swiftrather than repeating them, so it cannot drift from what ships, and it takes its credentials from the environment rather than pasting them into generated C, which a password containing a quote or a backslash would otherwise break or corrupt. No unit test can catch this class of bug: the statement text is correct and the defect is in the session it runs against.Fixtures used for the measurements were seeded into a throwaway
tp_objectsdatabase: alias and table types, procedures with and without parameters, an encrypted procedure, a CLR-free multi-statement TVF, a low-privilege user, and a table with a filtered index and an indexed computed column.https://claude.ai/code/session_016PSQC4EGqkpq32cWdPVMBJ