[issue29725] sqlite3.Cursor doesn't properly document "arraysize"
New submission from Jürgen A. Erhard: It's an attribute mentioned in fetchmany and fetchall, but it's not in the list with those two, but it should be, since the section says "A Cursor instance has the following attributes and methods." and it is an attribute. ---------- assignee: docs@python components: Documentation messages: 289023 nosy: docs@python, jae priority: normal severity: normal status: open title: sqlite3.Cursor doesn't properly document "arraysize" _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Changes by Berker Peksag <berker.peksag@gmail.com>: ---------- keywords: +easy nosy: +berker.peksag stage: -> needs patch type: -> enhancement versions: +Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Cheryl Sabella added the comment: I wanted to try to work on the documentation for this, but I had some questions. I looked at: https://github.com/python/cpython/blob/master/Modules/_sqlite/cursor.c And I don't see arraysize being set to anything other than 1. I also don't see fetchall using it like the documentation says. fetchmany does seem to be using the size sent in as an argument or using the arraysize (which is 1) to break out of the loop early, so the default behaviour appears to be the similar to fetchone. Please take this all with the caveat that I don't know c, so I may be missing something really obvious. But, I can see all the other cursor attributes being changed within this module, so I expected arraysize to work in a similar way. I did find this website which has a definition of arraysize: http://initd.org/psycopg/docs/cursor.html#cursor.arraysize Sorry if this is too many questions. I've just started trying to help with documentation issues and I may have gotten in over my head. ---------- nosy: +csabella _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Changes by Aviv Palivoda <palaviv@gmail.com>: ---------- nosy: +palaviv _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Aviv Palivoda added the comment: Hi Cheryl, the arraysize value can be set by doing:
cursor.array = 5
For example I can do the following
import sqlite3 s = sqlite3.connect(":memory:") s.execute("create table a(a,b)") s.execute("insert into a(a,b) values (1,2)") s.execute("insert into a(a,b) values (3,4)") c = s.cursor() # Array size is 1 c.execute("select * from a") c.fetchmany() [(1, 2)] c.fetchmany() [(3, 4)] c.arraysize = 2 # Change array size c.fetchmany() [(1, 2), (3, 4)]
As you can see the arraysize set the number of results the fetchmany will return. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Cheryl Sabella added the comment: Hi Aviv, Thank you so much for explaining that! It's obvious to me now. It wasn't marked as READ ONLY in the program, so of course it would set by the caller. I'll be able to document that. I still have the question about this line in fetchall - " Note that the cursor’s arraysize attribute can affect the performance of this operation. " I don't see arraysize referenced in that function. I must be missing something else, but if it's not used, then maybe I should remove that line? One other question -- There is another attribute called row_factory in the cursor structure that isn't in the docs. There is a row_factory defined in the docs, but that one is for the connection structure. Should it be added under cursor as well? Thank you! ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Berker Peksag added the comment:
There is another attribute called row_factory in the cursor structure that isn't in the docs. There is a row_factory defined in the docs, but that one is for the connection structure. Should it be added under cursor as well?
Thank you for working on this issue, Cheryl. Cursor.row_factory is there for backwards compatibility reasons so we can't remove it until we retire Python 2. For example, pysqlite has already been removed it in version 2.8.0 [1] but they don't have a strict backwards compatibility policy since their user base is much smaller than us and it only supports Python 2. [1] https://github.com/ghaering/pysqlite/commit/10dbbe4cca7487a3c65776186b3fb4ce... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Changes by Cheryl Sabella <chekat2@gmail.com>: ---------- pull_requests: +1129 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Cheryl Sabella added the comment: Thank you so much for being patient with me and explaining that. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Senthil Kumaran added the comment: Thanks for working on this. row_factory seems to be another parameter that can be set in the Cursor object. https://github.com/python/cpython/blob/master/Modules/_sqlite/cursor.c#L65 This can addressed in a different issue/ pr. ---------- nosy: +orsenthil _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Senthil Kumaran added the comment: New changeset 02e12138000da834f23719521a011fa93763384d by Senthil Kumaran (csabella) in branch 'master': bpo-29725: DOC: add text for arraysize in sqlite3.Cursor (#947) https://github.com/python/cpython/commit/02e12138000da834f23719521a011fa9376... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Changes by Senthil Kumaran <senthil@uthcode.com>: ---------- pull_requests: +1157 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Changes by Senthil Kumaran <senthil@uthcode.com>: ---------- pull_requests: +1158 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Senthil Kumaran added the comment: New changeset cb1e002c07622e027e80a3843d27a623d1617430 by Senthil Kumaran in branch '3.6': bpo-29725: DOC: add text for arraysize in sqlite3.Cursor (#947) (#985) https://github.com/python/cpython/commit/cb1e002c07622e027e80a3843d27a623d16... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Senthil Kumaran added the comment: New changeset 0f9ceaf322cc9358373167115fd4c21ab2d9ad50 by Senthil Kumaran in branch '3.5': bpo-29725: DOC: add text for arraysize in sqlite3.Cursor (#947) (#986) https://github.com/python/cpython/commit/0f9ceaf322cc9358373167115fd4c21ab2d... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Changes by Senthil Kumaran <senthil@uthcode.com>: ---------- resolution: -> fixed stage: needs patch -> resolved status: open -> closed type: enhancement -> behavior _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
Berker Peksag added the comment:
row_factory seems to be another parameter that can be set in the Cursor object. https://github.com/python/cpython/blob/master/Modules/_sqlite/cursor.c#L65
This can addressed in a different issue/ pr.
Like I already said in msg290943, Cursor.row_factory is kept for backwards compatibility reasons and it shouldn't be documented. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29725> _______________________________________
participants (5)
-
Aviv Palivoda -
Berker Peksag -
Cheryl Sabella -
Jürgen A. Erhard -
Senthil Kumaran