Reputation: 1039
I'm fiddling around with Python and SQLite. I have a table structured like so:
PID | CID | a | b
=================
1 | 1 | ...
1 | 2 | ...
2 | 1 | ...
2 | 2 | ...
where PID is the ID of one object, and CID the id of another. Basically, a table that keeps track of the relationships between these two objects with properties (a, b, etc...) that may override those of the objects.
When I execute the following statement in python (c is a sqlite3 cursor):
results = c.execute("SELECT cid FROM test WHERE pid=?", (the_related_id,)).fetchmany()
I only get one result in the list, however, when I run the same (?) query in a sqlite browser, I get many results as expected:
SELECT cid FROM test WHERE pid=1
Whats the deal?
Upvotes: 2
Views: 929
Reputation: 673
The number of rows to fetch per call is specified by the size parameter. If it is not given, the cursor’s arraysize determines the number of rows to be fetched.
results = c.execute("SELECT cid FROM test WHERE pid=?", (the_related_id,)).fetchmany(N)
will return N rows. If you want to retrieve all the rows, use fetchall() function instead:
results = c.execute("SELECT cid FROM test WHERE pid=?", (the_related_id,)).fetchall()
Upvotes: 2