New submission from 
                                        Anthony Tuininga
                                :

Attached is a patch that adds the requested support. This is in relation
to the thread at

http://www.gossamer-threads.com/lists/python/python/584264

In addition to the two methods I also "fixed" Fetch() by ensuring that
when the records are exhausted None is returned instead of an error.

If something further is required of me or I submitted this patch
incorrectly, please let me know so I don't screw it up next time. :-)

----------
nosy: +atuining

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1102>
__________________________________
Index: _msi.c
===================================================================
--- _msi.c      (revision 57972)
+++ _msi.c      (working copy)
@@ -350,6 +350,34 @@
 }
 
 static PyObject*
+record_getstring(msiobj* record, PyObject *args)
+{
+    int status, field, size;
+    PyObject *value;
+    char *data;
+
+    if (!PyArg_ParseTuple(args, "i:GetString", &field))
+           return NULL;
+
+    size = 0;
+    status = MsiRecordGetString(record->h, field, "", &size);
+    if (status != ERROR_MORE_DATA)
+        return msierror(status);
+    size++;
+    data = PyMem_Malloc(size);
+    if (!data)
+        return PyErr_NoMemory();
+    status = MsiRecordGetString(record->h, field, data, &size);
+    if (status != ERROR_SUCCESS) {
+        PyMem_Free(data);
+        return msierror(status);
+    }
+    value = PyString_FromString(data);
+    PyMem_Free(data);
+    return value;
+}
+
+static PyObject*
 record_setstring(msiobj* record, PyObject *args)
 {
     int status;
@@ -384,6 +412,22 @@
 }
 
 static PyObject*
+record_getinteger(msiobj* record, PyObject *args)
+{
+    int field, value;
+
+    if (!PyArg_ParseTuple(args, "i:GetInteger", &field))
+           return NULL;
+
+    value = MsiRecordGetInteger(record->h, field);
+    if (value != MSI_NULL_INTEGER)
+        return PyInt_FromLong(value);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static PyObject*
 record_setinteger(msiobj* record, PyObject *args)
 {
     int status;
@@ -405,10 +449,14 @@
 static PyMethodDef record_methods[] = {
     { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, 
        PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")},
+    { "GetString", (PyCFunction)record_getstring, METH_VARARGS, 
+       PyDoc_STR("GetString(field) -> value\nWraps MsiRecordGetString")},
     { "SetString", (PyCFunction)record_setstring, METH_VARARGS, 
        PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")},
     { "SetStream", (PyCFunction)record_setstream, METH_VARARGS, 
        PyDoc_STR("SetStream(field,filename) -> None\nWraps 
MsiRecordSetInteger")},
+    { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS, 
+       PyDoc_STR("GetInteger(field) -> value\nWraps MsiRecordGetInteger")},
     { "SetInteger", (PyCFunction)record_setinteger, METH_VARARGS, 
        PyDoc_STR("SetInteger(field,int) -> None\nWraps MsiRecordSetInteger")},
     { "ClearData", (PyCFunction)record_cleardata, METH_NOARGS, 
@@ -662,8 +710,13 @@
     int status;
     MSIHANDLE result;
 
-    if ((status = MsiViewFetch(view->h, &result)) != ERROR_SUCCESS)
-       return msierror(status);
+    status = MsiViewFetch(view->h, &result);
+    if (status == ERROR_NO_MORE_ITEMS) {
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+    if (status != ERROR_SUCCESS)
+        return msierror(status);
 
     return record_new(result);
 }
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to