-
Notifications
You must be signed in to change notification settings - Fork 1
/
PHPDbConnection.cpp
91 lines (74 loc) · 1.65 KB
/
PHPDbConnection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "stdafx.h"
#undef _DEBUG
#include <Python.h>
#define _DEBUG
#include "PHPDbConnectionCursor.h"
#include "PHPDbConnection.h"
CPyDbConnWraper::CPyDbConnWraper(PyObject* dbh)
{
this->dbh = dbh;
Py_INCREF(this->dbh);
};
CPyDbConnWraper::~CPyDbConnWraper()
{
Py_DECREF(this->dbh);
};
bool CPyDbConnWraper::commit()
{
PyObject *result;
bool retVal = true;
PyObject *Method;
Method = PyObject_GetAttrString(this->dbh, "commit");
result = PyEval_CallObject(Method, NULL);
//ìåòîä îêîí÷èëñÿ ïðîâàëîì è áûëî áðîøåíî Pythonic Èñêëþ÷åíèå
if(result == NULL)
{
retVal = false;
PyErr_Clear();
}
else
{
//äåêðåìåíèðóåì ñ÷åò÷èê ññûëîê - íàì îí íå îñîáî íóæåí ðåçóëüòàò
Py_DECREF(result);
};
Py_DECREF(Method);
return retVal;
};
bool CPyDbConnWraper::rollback()
{
PyObject *result;
bool retVal = true;
PyObject *Method;
Method = PyObject_GetAttrString(this->dbh, "rollback");
result = PyEval_CallObject(Method, NULL);
//ìåòîä îêîí÷èëñÿ ïðîâàëîì è áûëî áðîøåíî Pythonic Èñêëþ÷åíèå
if(result == NULL)
{
retVal = false;
PyErr_Clear();
}
else
{
//äåêðåìåíèðóåì ñ÷åò÷èê ññûëîê - íàì îí íå îñîáî íóæåí ðåçóëüòàò
Py_DECREF(result);
};
Py_DECREF(Method);
return retVal;
};
IDbConnectionCursor* CPyDbConnWraper::cursor()
{
PyObject *result;
CPyDbConnCursorWraper* retVal = NULL;
result = PyObject_CallMethod(this->dbh, "cursor", NULL);
//ìåòîä îêîí÷èëñÿ ïðîâàëîì è áûëî áðîøåíî Pythonic Èñêëþ÷åíèå
if(result != NULL)
{
retVal = new CPyDbConnCursorWraper(result);
Py_DECREF(result);
}
else
{
PyErr_Clear();
};
return retVal;
};