[Python-checkins] bpo-1102: View.Fetch() now returns None when it's exhausted (GH-4459)
Berker Peksag
webhook-mailer at python.org
Thu Nov 23 09:33:14 EST 2017
https://github.com/python/cpython/commit/4b3042900e7e8dc120408bab86642c09c9d25a5a
commit: 4b3042900e7e8dc120408bab86642c09c9d25a5a
branch: 3.6
author: Berker Peksag <berker.peksag at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-11-23T17:33:12+03:00
summary:
bpo-1102: View.Fetch() now returns None when it's exhausted (GH-4459)
(cherry picked from commit bdb8315c21825487b54852ff0511fb4881ea2181)
files:
A Misc/NEWS.d/next/Windows/2017-11-19-09-46-27.bpo-1102.NY-g1F.rst
M Lib/test/test_msilib.py
M PC/_msi.c
diff --git a/Lib/test/test_msilib.py b/Lib/test/test_msilib.py
index f656f7234e2..aa19883ac6f 100644
--- a/Lib/test/test_msilib.py
+++ b/Lib/test/test_msilib.py
@@ -1,7 +1,45 @@
""" 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()
+ 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
diff --git a/Misc/NEWS.d/next/Windows/2017-11-19-09-46-27.bpo-1102.NY-g1F.rst b/Misc/NEWS.d/next/Windows/2017-11-19-09-46-27.bpo-1102.NY-g1F.rst
new file mode 100644
index 00000000000..6a6618e9692
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2017-11-19-09-46-27.bpo-1102.NY-g1F.rst
@@ -0,0 +1,4 @@
+Return ``None`` when ``View.Fetch()`` returns ``ERROR_NO_MORE_ITEMS``
+instead of raising ``MSIError``.
+
+Initial patch by Anthony Tuininga.
diff --git a/PC/_msi.c b/PC/_msi.c
index 2ab7e731a1e..eab39d9b002 100644
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -729,8 +729,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);
}
More information about the Python-checkins
mailing list