Skip to content

bpo-1102: View.Fetch() now returns None when it's exhausted #4459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion Lib/test/test_msilib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
""" Test suite for the code in msilib """
import unittest
from test.support import import_module
from test.support import TESTFN, import_module, unlink
msilib = import_module('msilib')
import msilib.schema


def init_database():
path = TESTFN + '.msi'
db = msilib.init_database(
path,
msilib.schema,
'Python Tests',
'product_code',
'1.0',
'PSF',
)
return db, path


class MsiDatabaseTestCase(unittest.TestCase):

def test_view_fetch_returns_none(self):
db, db_path = init_database()
properties = []
view = db.OpenView('SELECT Property, Value FROM Property')
view.Execute(None)
while True:
record = view.Fetch()
if record is None:
break
properties.append(record.GetString(1))
view.Close()
db.Close()
self.assertEqual(
properties,
[
'ProductName', 'ProductCode', 'ProductVersion',
'Manufacturer', 'ProductLanguage',
]
)
self.addCleanup(unlink, db_path)


class Test_make_id(unittest.TestCase):
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Return ``None`` when ``View.Fetch()`` returns ``ERROR_NO_MORE_ITEMS``
instead of raising ``MSIError``.

Initial patch by Anthony Tuininga.
6 changes: 5 additions & 1 deletion PC/_msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,12 @@ view_fetch(msiobj *view, PyObject*args)
int status;
MSIHANDLE result;

if ((status = MsiViewFetch(view->h, &result)) != ERROR_SUCCESS)
status = MsiViewFetch(view->h, &result);
if (status == ERROR_NO_MORE_ITEMS) {
Py_RETURN_NONE;
} else if (status != ERROR_SUCCESS) {
return msierror(status);
}

return record_new(result);
}
Expand Down