mysql-python fetchrow 带来: TypeError: 'long'对象不可调用

发布于 2024-12-27 08:01:28 字数 883 浏览 2 评论 0原文

我得到了一张桌子:

+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Benutzer  | varchar(50) | YES  |     | NULL    |       |
| Confirmed | tinyint(1)  | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+

只有一个条目!

如果我在 shell 中的 mysql 控制台上执行:

select Benutzer from UserConfirm where Benutzer = '\{\'gid\'\:\ \'tamer\'\,\ \'uid\'\:\ \'tamer\'\}'

它可以工作!

在 mysql-python 出现错误消息:

TypeError: 'long' object is not callable

我做错了什么?! 这是我的 python 代码:

cursor = self.__db.cursor().execute('select * from UserConfirm where Benutzer = \'' + ds + '\'') 
return cursor().fetchrow()

如有任何建议,我将非常感谢。

I got a table:

+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Benutzer  | varchar(50) | YES  |     | NULL    |       |
| Confirmed | tinyint(1)  | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+

with one entry!

If I execute on the mysql console in a shell:

select Benutzer from UserConfirm where Benutzer = '\{\'gid\'\:\ \'tamer\'\,\ \'uid\'\:\ \'tamer\'\}'

it works!

At mysql-python there comes the errormessage:

TypeError: 'long' object is not callable

What did I make wrong?!
Here is my python code:

cursor = self.__db.cursor().execute('select * from UserConfirm where Benutzer = \'' + ds + '\'') 
return cursor().fetchrow()

For any advice, I would kindly thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傾城如夢未必闌珊 2025-01-03 08:01:28

问题是您没有存储游标对象,只是存储了execute的返回值,这不是游标,它应该是:

cursor = self.__db.cursor()
cursor.execute('select * from UserConfirm where Benutzer = \'' + ds + '\'') 
return cursor.fetchone()

The problem is that you are not storing the cursor object, just the return value of execute, which is not the cursor, it should be:

cursor = self.__db.cursor()
cursor.execute('select * from UserConfirm where Benutzer = \'' + ds + '\'') 
return cursor.fetchone()
您的好友蓝忘机已上羡 2025-01-03 08:01:28

请注意,我假设您的行 cursor().fetchrow() 是一个拼写错误,您的意思是 cursor.fetchrow()

我自己不了解 mysql-python,从错误中我可以假设 Cursor.execute 返回的是行数或错误代码,而不是游标本身。

请尝试以下方法:

cursor = self.__db.cursor()
cursor.execute('select * from UserConfirm where Benutzer = \'' + ds + '\'')
return cursor.fetchrow()

Note that I assume your line cursor().fetchrow() is a typo and you meant cursor.fetchrow().

Not knowing mysql-python myself, from the error I can assume cursor.execute is returning the number of rows or an error code, not the cursor itself.

Try the following instead:

cursor = self.__db.cursor()
cursor.execute('select * from UserConfirm where Benutzer = \'' + ds + '\'')
return cursor.fetchrow()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文