Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Basic cursor usage - fetchall / fetchone returning List of Tuples instead of Row objects?#65

ClosedUnanswered
chadbaldwin asked this question inQ&A
Discussion options

Disclaimer: I am 100% completely new to python, which is why I've posted this as a discussion instead of an issue. But I am a SQL Server developer, so when I saw this new driver announcement, I decided to start learning it.

I installed Python v3.13.3 andmssql-python v0.1.6.

I'm literally just trying to re-create the samples used in the documentation and they are not working. The query runs fine, I can see data populating into the variable after fetching. But it seems the data type returned byfetchone is not matching what the documentation says it should be.

I'm running this:

frommssql_pythonimportconnectconn=connect("Server=localhost;Database=master;UID=sa;PWD=MyPassword;Encrypt=no;")cursor=conn.cursor()cursor.execute("SELECT [type], row_count = COUNT(*) FROM sys.objects GROUP BY [type]")row=cursor.fetchone()row.row_count

Which results in...

Traceback (most recent call last):  File "<python-input-5>", line 1, in <module>    row.row_countAttributeError: 'list' object has no attribute 'row_count'

The documentation says thatfetchone() should return aRow object, but instead it is returning aTuple. So when I try to access the attribute by name, it simply fails because it doesn't exist because the object looks like this['SQ', 3].

So, I understand what I need to do to make this work in regard to accessing the values I need using indexes rather than names. But I don't understand why the fetch commands are returning tuples and lists of tuples instead of thisRow object?

You must be logged in to vote

Replies: 2 comments

Comment options

Hi@chadbaldwin Thank you for connecting with us, appreciate you for using this driver. We are triaging this issue and will revert in a day or two on this issue.
You can also report such issueshere in future.
Thank you again!

You must be logged in to vote
0 replies
Comment options

Hi@chadbaldwin We acknowledge issues in the documentation and corresponding intended behavior. We are now in the process of fixing this issue. This will be released in our upcoming release. Necessary changes will be done on the documentation as well. Thank you again for reporting this problem.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@chadbaldwin@sumitmsft

[8]ページ先頭

©2009-2025 Movatter.jp