本文整理汇总了C++中Object::AttachAndIncrement方法的典型用法代码示例。如果您正苦于以下问题:C++ Object::AttachAndIncrement方法的具体用法?C++ Object::AttachAndIncrement怎么用?C++ Object::AttachAndIncrement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object::AttachAndIncrement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetResultError
PyObject* SetResultError(PGresult* r)
{
// Creates an exception from `result`.
//
// This function takes ownership of `result` and will clear it, even if an exception cannot be created.
//
// Always returns zero so it can be called using "return SetResultError(result);"
// TODO: Make a new exception class that always has SQLSTATE
ResultHolder result(r); // make sure `r` gets cleared no matter what
const char* szMessage = PQresultErrorMessage(result);
const char* szSQLSTATE = PQresultErrorField(result, PG_DIAG_SQLSTATE);
if (!szMessage || !szSQLSTATE)
return PyErr_NoMemory();
Object msg(PyUnicode_FromFormat("[%s] %s", szSQLSTATE, szMessage));
if (!msg)
return 0;
PyObject* error = PyObject_CallFunction(Error, (char*)"O", msg.Get());
if (!error)
return 0;
for (size_t i = 0; i < _countof(errorFields); i++)
{
const char* szValue = PQresultErrorField(result, errorFields[i].fieldcode);
Object value;
if (szValue == 0)
{
value.AttachAndIncrement(Py_None);
}
else
{
value.Attach(PyUnicode_FromString(szValue));
if (!value)
return 0;
}
if (PyObject_SetAttrString(error, errorFields[i].szAttr, value) == -1)
return 0;
}
PyErr_SetObject(Error, error);
return 0;
}