Skip to content

Commit a935654

Browse files
authored
bpo-20486: Implement Database.Close() method in msilib (GH-4141)
1 parent 3cc4c53 commit a935654

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

Doc/library/msilib.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,18 @@ Database Objects
152152
:c:func:`MsiGetSummaryInformation`. *count* is the maximum number of updated
153153
values.
154154

155+
.. method:: Database.Close()
156+
157+
Close the database object, through :c:func:`MsiCloseHandle`.
158+
159+
.. versionadded:: 3.7
155160

156161
.. seealso::
157162

158163
`MSIDatabaseOpenView <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msidatabaseopenview.asp>`_
159164
`MSIDatabaseCommit <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msidatabasecommit.asp>`_
160165
`MSIGetSummaryInformation <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msigetsummaryinformation.asp>`_
166+
`MsiCloseHandle <https://msdn.microsoft.com/en-us/library/windows/desktop/aa370067(v=vs.85).aspx>`_
161167

162168
.. _view-objects:
163169

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Implement the ``Database.Close()`` method to help closing MSI database
2+
objects.

PC/_msi.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,6 @@ msiobj_dealloc(msiobj* msidb)
286286
PyObject_Del(msidb);
287287
}
288288

289-
static PyObject*
290-
msiobj_close(msiobj* msidb, PyObject *args)
291-
{
292-
MsiCloseHandle(msidb->h);
293-
msidb->h = 0;
294-
Py_RETURN_NONE;
295-
}
296-
297289
static PyObject*
298290
msierror(int status)
299291
{
@@ -342,6 +334,17 @@ msierror(int status)
342334
return NULL;
343335
}
344336

337+
static PyObject*
338+
msidb_close(msiobj* msidb, PyObject *args)
339+
{
340+
int status;
341+
if ((status = MsiCloseHandle(msidb->h)) != ERROR_SUCCESS) {
342+
return msierror(status);
343+
}
344+
msidb->h = 0;
345+
Py_RETURN_NONE;
346+
}
347+
345348
/*************************** Record objects **********************/
346349

347350
static PyObject*
@@ -901,6 +904,8 @@ static PyMethodDef db_methods[] = {
901904
PyDoc_STR("Commit() -> None\nWraps MsiDatabaseCommit")},
902905
{ "GetSummaryInformation", (PyCFunction)msidb_getsummaryinformation, METH_VARARGS,
903906
PyDoc_STR("GetSummaryInformation(updateCount) -> viewobj\nWraps MsiGetSummaryInformation")},
907+
{ "Close", (PyCFunction)msidb_close, METH_NOARGS,
908+
PyDoc_STR("Close() -> None\nWraps MsiCloseHandle")},
904909
{ NULL, NULL }
905910
};
906911

0 commit comments

Comments
 (0)