Skip to content

Commit 4b30429

Browse files
authored
bpo-1102: View.Fetch() now returns None when it's exhausted (GH-4459)
(cherry picked from commit bdb8315)
1 parent ae3c5c7 commit 4b30429

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

Lib/test/test_msilib.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,45 @@
11
""" Test suite for the code in msilib """
22
import unittest
3-
from test.support import import_module
3+
from test.support import TESTFN, import_module, unlink
44
msilib = import_module('msilib')
5+
import msilib.schema
6+
7+
8+
def init_database():
9+
path = TESTFN + '.msi'
10+
db = msilib.init_database(
11+
path,
12+
msilib.schema,
13+
'Python Tests',
14+
'product_code',
15+
'1.0',
16+
'PSF',
17+
)
18+
return db, path
19+
20+
21+
class MsiDatabaseTestCase(unittest.TestCase):
22+
23+
def test_view_fetch_returns_none(self):
24+
db, db_path = init_database()
25+
properties = []
26+
view = db.OpenView('SELECT Property, Value FROM Property')
27+
view.Execute(None)
28+
while True:
29+
record = view.Fetch()
30+
if record is None:
31+
break
32+
properties.append(record.GetString(1))
33+
view.Close()
34+
self.assertEqual(
35+
properties,
36+
[
37+
'ProductName', 'ProductCode', 'ProductVersion',
38+
'Manufacturer', 'ProductLanguage',
39+
]
40+
)
41+
self.addCleanup(unlink, db_path)
42+
543

644
class Test_make_id(unittest.TestCase):
745
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Return ``None`` when ``View.Fetch()`` returns ``ERROR_NO_MORE_ITEMS``
2+
instead of raising ``MSIError``.
3+
4+
Initial patch by Anthony Tuininga.

PC/_msi.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,12 @@ view_fetch(msiobj *view, PyObject*args)
729729
int status;
730730
MSIHANDLE result;
731731

732-
if ((status = MsiViewFetch(view->h, &result)) != ERROR_SUCCESS)
732+
status = MsiViewFetch(view->h, &result);
733+
if (status == ERROR_NO_MORE_ITEMS) {
734+
Py_RETURN_NONE;
735+
} else if (status != ERROR_SUCCESS) {
733736
return msierror(status);
737+
}
734738

735739
return record_new(result);
736740
}

0 commit comments

Comments
 (0)