回答編集履歴
2
少し追記
answer
CHANGED
|
@@ -2,4 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[https://github.com/PyMySQL/PyMySQL/blob/ddbf0e8521d111e2f4ac4deb4ef8d42fad72f159/pymysql/connections.py#L870](https://github.com/PyMySQL/PyMySQL/blob/ddbf0e8521d111e2f4ac4deb4ef8d42fad72f159/pymysql/connections.py#L870)
|
|
4
4
|
|
|
5
|
+
従いまして、
|
|
6
|
+
```
|
|
7
|
+
with getConnection() as db:
|
|
8
|
+
cursor = db.cursor()
|
|
9
|
+
```
|
|
5
|
-
`Cursor`オブジェクトには、`cursor`メソッドはありませんので、エラーとなります。
|
|
10
|
+
ここの`db`には`Connection`オブジェクトではなく、`Cursor`オブジェクトが入っています。`Cursor`オブジェクトには、`cursor`メソッドはありませんので、エラーとなります。
|
1
文頭追記
answer
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
`getConnection()`関数は`PyMYSQL`の`Connection`オブジェクトを返し、それに対してwith句にかけると`Cursor`(`DictCursor`)オブジェクトが得られます。
|
|
1
|
+
ご自身が作成された`getConnection()`関数は`PyMYSQL`の`Connection`オブジェクトを返し、それに対してwith句にかけると`Cursor`(`DictCursor`)オブジェクトが得られます。
|
|
2
2
|
|
|
3
3
|
[https://github.com/PyMySQL/PyMySQL/blob/ddbf0e8521d111e2f4ac4deb4ef8d42fad72f159/pymysql/connections.py#L870](https://github.com/PyMySQL/PyMySQL/blob/ddbf0e8521d111e2f4ac4deb4ef8d42fad72f159/pymysql/connections.py#L870)
|
|
4
4
|
|