Merged revisions 63888 via svnmerge from
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 2 Jun 2008 10:08:54 +0000 (10:08 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 2 Jun 2008 10:08:54 +0000 (10:08 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r63888 | martin.v.loewis | 2008-06-02 10:40:06 +0200 (Mo, 02 Jun 2008) | 2 lines

  Patch #2125: Add GetInteger and GetString methods for
  msilib.Record objects.
........

Doc/library/msilib.rst
PC/_msi.c

index 6f558e6caa84050b20068ee96c7fab37a352b85f..eb58d44226e685512d80d15919034ef038421462 100644 (file)
@@ -262,6 +262,18 @@ Record Objects
    :cfunc:`MsiRecordGetFieldCount`.
 
 
+.. method:: Record.GetInteger(field)
+
+   Return the value of *field* as an integer where possible.  *field* must
+   be an integer.
+
+
+.. method:: Record.GetString(field)
+
+   Return the value of *field* as a string where possible.  *field* must
+   be an integer.
+
+
 .. method:: Record.SetString(field, value)
 
    Set *field* to *value* through :cfunc:`MsiRecordSetString`. *field* must be an
@@ -541,3 +553,4 @@ definitions. Currently, these definitions are based on MSI version 2.0.
    This module contains definitions for the UIText and ActionText tables, for the
    standard installer actions.
 
+
index 5b68bc2e2f947a9a3fe8d3dceeb9894f78cb46b7..d3727760a561a1975e669719d88ebc7558b372ec 100644 (file)
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -338,6 +338,49 @@ record_getfieldcount(msiobj* record, PyObject* args)
     return PyLong_FromLong(MsiRecordGetFieldCount(record->h));
 }
 
+static PyObject*
+record_getinteger(msiobj* record, PyObject* args)
+{
+    unsigned int field;
+    int status;
+    
+    if (!PyArg_ParseTuple(args, "I:GetInteger", &field))
+        return NULL;
+    status = MsiRecordGetInteger(record->h, field);
+    if (status == MSI_NULL_INTEGER){
+        PyErr_SetString(MSIError, "could not convert record field to integer");
+        return NULL;
+    }
+    return PyInt_FromLong((long) status);
+}
+
+static PyObject*
+record_getstring(msiobj* record, PyObject* args)
+{
+    unsigned int field;
+    unsigned int status;
+    char buf[2000];
+    char *res = buf;
+    DWORD size = sizeof(buf);
+    PyObject* string;
+    
+    if (!PyArg_ParseTuple(args, "I:GetString", &field))
+        return NULL;
+    status = MsiRecordGetString(record->h, field, res, &size);
+    if (status == ERROR_MORE_DATA) {
+        res = (char*) malloc(size + 1);
+        if (res == NULL)
+            return PyErr_NoMemory();
+        status = MsiRecordGetString(record->h, field, res, &size);
+    }
+    if (status != ERROR_SUCCESS)
+        return msierror((int) status);
+    string = PyString_FromString(res);
+    if (buf != res)
+        free(res);
+    return string;
+}
+
 static PyObject*
 record_cleardata(msiobj* record, PyObject *args)
 {
@@ -405,6 +448,10 @@ record_setinteger(msiobj* record, PyObject *args)
 static PyMethodDef record_methods[] = {
     { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, 
        PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")},
+    { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS,
+    PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")},
+    { "GetString", (PyCFunction)record_getstring, METH_VARARGS,
+    PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")},
     { "SetString", (PyCFunction)record_setstring, METH_VARARGS, 
        PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")},
     { "SetStream", (PyCFunction)record_setstream, METH_VARARGS,