-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlNumResultCols returns count as 0 for CURSOR queries while using FreeTDS driver, works in Microsoft's ODBC driver #590
Comments
@freddy77 we also saved the query as a stored procedure and tried executing it, we faced the same issue again, works in Microsoft ODBC driver and doesn't work in FreeTDS. |
@freddy77 to add more information: We also rewrote the query to avoid using cursor and ran this query:
This one doesn't use the CURSOR, but still this doesn't return value in SqlNumResultCols. SET NOCOUNT ON in the query is optionally used to make it work when Microsoft's ODBC Driver is used. |
Hello, I am having a similar problem. The application is getting odbc error code 100 |
I probably could use this to reproduce the issue. |
I do not have source code available for the app but I can share the part of the procedure that causes the behavior. ALTER PROCEDURE [dbo].[_Procedure]
@Param INT
AS
SET NOCOUNT ON
SET @NewID = 0
BEGIN TRANSACTION
-- Bunch of inserts here
SET @NewID = @@IDENTITY
-- Some more inserts here also
COMMIT TRANSACTION
RETURN @NewID
GO The above procedure works as expected and performs all the tasks it needs to but when using FreeTDS the app does not get any results but instead complains about ODBC error code 100. Using the Microsoft driver the app gets the return value without any errors. ALTER PROCEDURE [dbo].[_Procedure]
@Param INT
AS
SET NOCOUNT ON
SET @NewID = 0
BEGIN TRANSACTION
-- Bunch of inserts here
SET @NewID = @@IDENTITY
-- Some more inserts here also
COMMIT TRANSACTION
SET NOCOUNT OFF
RETURN @NewID
GO Could this be related to Microsoft handling |
We have used the native SqlNumResultCols() method to run a query that uses CURSOR but the result is returned wrongly as 0 for FreeTDS driver, but works correctly in Microsoft's ODBC Driver.
This is the query used:
DECLARE db_cursor CURSOR FOR SELECT name FROM sys.databases WHERE state_desc = 'ONLINE' AND name NOT IN ('master','tempdb','model','msdb'); DECLARE @DatabaseName NVARCHAR(128); DECLARE @outset TABLE([DATABASENAME] varchar(100),[TABLENAME] varchar(100));OPEN db_cursor;FETCH NEXT FROM db_cursor INTO @DatabaseName;WHILE @@FETCH_STATUS = 0 BEGIN DECLARE @command nvarchar(1000) = ' USE ' + QUOTENAME(@DatabaseName) + ';SELECT DB_NAME() AS databasename,ISNULL(''['' + SCHEMA_NAME(schema_id) + ''].['' + name + '']'', ''No Tables'') AS tablename FROM sys.tables UNION ALL SELECT DB_NAME() AS databasename, ''No Tables'' AS tablename WHERE NOT EXISTS (SELECT 1 FROM sys.tables)';INSERT INTO @outset EXEC (@command);FETCH NEXT FROM db_cursor INTO @DatabaseName; END CLOSE db_cursor; DEALLOCATE db_cursor; SELECT DISTINCT databasename, tablename FROM @outset ORDER BY databasename,tablename;
Here's a screenshot that highlights the issue:
When ODBC driver is used:
When FreeTDS driver is used:
Kindly help us with this issue.
FreeTDS Version: Current Master branch (I think 1.04.12 in registry)
SQL server Version: 2019
OS: Windows 10
The text was updated successfully, but these errors were encountered: