This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sqlite3.Cursor doesn't properly document "arraysize"
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: berker.peksag, cheryl.sabella, docs@python, jae, orsenthil, palaviv
Priority: normal Keywords: easy

Created on 2017-03-05 16:47 by jae, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 947 merged cheryl.sabella, 2017-04-01 12:22
PR 985 merged orsenthil, 2017-04-04 05:21
PR 986 merged orsenthil, 2017-04-04 05:21
Messages (11)
msg289023 - (view) Author: Jürgen A. Erhard (jae) Date: 2017-03-05 16:47
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.
msg290842 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2017-03-30 14:20
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.
msg290914 - (view) Author: Aviv Palivoda (palaviv) * Date: 2017-03-31 15:10
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.
msg290921 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2017-03-31 16:31
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!
msg290943 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-03-31 21:37
> 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/10dbbe4cca7487a3c65776186b3fb4ceeab5e8fa
msg290982 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2017-04-01 12:27
Thank you so much for being patient with me and explaining that.
msg291103 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2017-04-04 05:15
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.
msg291104 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2017-04-04 05:16
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/02e12138000da834f23719521a011fa93763384d
msg291105 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2017-04-04 05:27
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/cb1e002c07622e027e80a3843d27a623d1617430
msg291106 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2017-04-04 05:28
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/0f9ceaf322cc9358373167115fd4c21ab2d9ad50
msg291335 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-04-08 16:07
> 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.
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73911
2017-04-08 16:07:15berker.peksagsetmessages: + msg291335
2017-04-04 05:29:07orsenthilsetstatus: open -> closed
type: enhancement -> behavior
resolution: fixed
stage: needs patch -> resolved
2017-04-04 05:28:25orsenthilsetmessages: + msg291106
2017-04-04 05:27:17orsenthilsetmessages: + msg291105
2017-04-04 05:21:25orsenthilsetpull_requests: + pull_request1158
2017-04-04 05:21:21orsenthilsetpull_requests: + pull_request1157
2017-04-04 05:16:16orsenthilsetmessages: + msg291104
2017-04-04 05:15:09orsenthilsetnosy: + orsenthil
messages: + msg291103
2017-04-01 12:27:29cheryl.sabellasetmessages: + msg290982
2017-04-01 12:22:58cheryl.sabellasetpull_requests: + pull_request1129
2017-03-31 21:37:56berker.peksagsetmessages: + msg290943
2017-03-31 16:31:36cheryl.sabellasetmessages: + msg290921
2017-03-31 15:10:42palavivsetmessages: + msg290914
2017-03-31 05:34:14palavivsetnosy: + palaviv
2017-03-30 14:20:23cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg290842
2017-03-15 09:54:17berker.peksagsetversions: + Python 3.5, Python 3.6, Python 3.7
nosy: + berker.peksag

keywords: + easy
type: enhancement
stage: needs patch
2017-03-05 16:47:29jaecreate