From a935654f0613640535fbf0ba190f81d02a63d35c Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 7 Nov 2017 15:58:53 +0300 Subject: bpo-20486: Implement Database.Close() method in msilib (GH-4141) --- Doc/library/msilib.rst | 6 ++++++ .../2017-10-26-23-02-57.bpo-20486.3IdsZ1.rst | 2 ++ PC/_msi.c | 21 +++++++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2017-10-26-23-02-57.bpo-20486.3IdsZ1.rst diff --git a/Doc/library/msilib.rst b/Doc/library/msilib.rst index 09d00a6..a66e52c 100644 --- a/Doc/library/msilib.rst +++ b/Doc/library/msilib.rst @@ -152,12 +152,18 @@ Database Objects :c:func:`MsiGetSummaryInformation`. *count* is the maximum number of updated values. +.. method:: Database.Close() + + Close the database object, through :c:func:`MsiCloseHandle`. + + .. versionadded:: 3.7 .. seealso:: `MSIDatabaseOpenView `_ `MSIDatabaseCommit `_ `MSIGetSummaryInformation `_ + `MsiCloseHandle `_ .. _view-objects: diff --git a/Misc/NEWS.d/next/Windows/2017-10-26-23-02-57.bpo-20486.3IdsZ1.rst b/Misc/NEWS.d/next/Windows/2017-10-26-23-02-57.bpo-20486.3IdsZ1.rst new file mode 100644 index 0000000..d65971e --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2017-10-26-23-02-57.bpo-20486.3IdsZ1.rst @@ -0,0 +1,2 @@ +Implement the ``Database.Close()`` method to help closing MSI database +objects. diff --git a/PC/_msi.c b/PC/_msi.c index a15f684..df6c881 100644 --- a/PC/_msi.c +++ b/PC/_msi.c @@ -287,14 +287,6 @@ msiobj_dealloc(msiobj* msidb) } static PyObject* -msiobj_close(msiobj* msidb, PyObject *args) -{ - MsiCloseHandle(msidb->h); - msidb->h = 0; - Py_RETURN_NONE; -} - -static PyObject* msierror(int status) { int code; @@ -342,6 +334,17 @@ msierror(int status) return NULL; } +static PyObject* +msidb_close(msiobj* msidb, PyObject *args) +{ + int status; + if ((status = MsiCloseHandle(msidb->h)) != ERROR_SUCCESS) { + return msierror(status); + } + msidb->h = 0; + Py_RETURN_NONE; +} + /*************************** Record objects **********************/ static PyObject* @@ -901,6 +904,8 @@ static PyMethodDef db_methods[] = { PyDoc_STR("Commit() -> None\nWraps MsiDatabaseCommit")}, { "GetSummaryInformation", (PyCFunction)msidb_getsummaryinformation, METH_VARARGS, PyDoc_STR("GetSummaryInformation(updateCount) -> viewobj\nWraps MsiGetSummaryInformation")}, + { "Close", (PyCFunction)msidb_close, METH_NOARGS, + PyDoc_STR("Close() -> None\nWraps MsiCloseHandle")}, { NULL, NULL } }; -- cgit v0.12