Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e95593e

Browse files
committed
Merged revisions 63888 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 90cc5ab commit e95593e

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Doc/library/msilib.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,18 @@ Record Objects
262262
:cfunc:`MsiRecordGetFieldCount`.
263263

264264

265+
.. method:: Record.GetInteger(field)
266+
267+
Return the value of *field* as an integer where possible. *field* must
268+
be an integer.
269+
270+
271+
.. method:: Record.GetString(field)
272+
273+
Return the value of *field* as a string where possible. *field* must
274+
be an integer.
275+
276+
265277
.. method:: Record.SetString(field, value)
266278

267279
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.
541553
This module contains definitions for the UIText and ActionText tables, for the
542554
standard installer actions.
543555

556+

PC/_msi.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,49 @@ record_getfieldcount(msiobj* record, PyObject* args)
338338
return PyLong_FromLong(MsiRecordGetFieldCount(record->h));
339339
}
340340

341+
static PyObject*
342+
record_getinteger(msiobj* record, PyObject* args)
343+
{
344+
unsigned int field;
345+
int status;
346+
347+
if (!PyArg_ParseTuple(args, "I:GetInteger", &field))
348+
return NULL;
349+
status = MsiRecordGetInteger(record->h, field);
350+
if (status == MSI_NULL_INTEGER){
351+
PyErr_SetString(MSIError, "could not convert record field to integer");
352+
return NULL;
353+
}
354+
return PyInt_FromLong((long) status);
355+
}
356+
357+
static PyObject*
358+
record_getstring(msiobj* record, PyObject* args)
359+
{
360+
unsigned int field;
361+
unsigned int status;
362+
char buf[2000];
363+
char *res = buf;
364+
DWORD size = sizeof(buf);
365+
PyObject* string;
366+
367+
if (!PyArg_ParseTuple(args, "I:GetString", &field))
368+
return NULL;
369+
status = MsiRecordGetString(record->h, field, res, &size);
370+
if (status == ERROR_MORE_DATA) {
371+
res = (char*) malloc(size + 1);
372+
if (res == NULL)
373+
return PyErr_NoMemory();
374+
status = MsiRecordGetString(record->h, field, res, &size);
375+
}
376+
if (status != ERROR_SUCCESS)
377+
return msierror((int) status);
378+
string = PyString_FromString(res);
379+
if (buf != res)
380+
free(res);
381+
return string;
382+
}
383+
341384
static PyObject*
342385
record_cleardata(msiobj* record, PyObject *args)
343386
{
@@ -405,6 +448,10 @@ record_setinteger(msiobj* record, PyObject *args)
405448
static PyMethodDef record_methods[] = {
406449
{ "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS,
407450
PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")},
451+
{ "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS,
452+
PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")},
453+
{ "GetString", (PyCFunction)record_getstring, METH_VARARGS,
454+
PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")},
408455
{ "SetString", (PyCFunction)record_setstring, METH_VARARGS,
409456
PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")},
410457
{ "SetStream", (PyCFunction)record_setstream, METH_VARARGS,

0 commit comments

Comments
 (0)