forked from PocketRent/hhvm-pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdo_pgsql_statement.h
101 lines (81 loc) · 3.06 KB
/
pdo_pgsql_statement.h
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
92
93
94
95
96
97
98
99
100
101
#ifndef incl_HPHP_PDO_PGSQL_STATEMENT_H_
#define incl_HPHP_PDO_PGSQL_STATEMENT_H_
#include "hphp/runtime/ext/pdo/pdo_driver.h"
#include "pdo_pgsql_resource.h"
#include "pq.h"
#include "stdarg.h"
#define BOOLOID 16
#define BYTEAOID 17
#define INT8OID 20
#define INT2OID 21
#define INT4OID 23
#define TEXTOID 25
#define OIDOID 26
namespace HPHP {
class PDOPgSqlStatement : public PDOStatement {
friend PDOPgSqlConnection;
public:
DECLARE_RESOURCE_ALLOCATION(PDOPgSqlStatement);
PDOPgSqlStatement(PDOPgSqlResource* conn, PQ::Connection* server);
virtual ~PDOPgSqlStatement();
bool create(const String& sql, const Array &options);
virtual bool executer();
virtual bool fetcher(PDOFetchOrientation ori, long offset);
virtual bool describer(int colno);
virtual bool getColumnMeta(int64_t colno, Array &return_value);
virtual bool getColumn(int colno, Variant &value);
virtual bool paramHook(PDOBoundParam* param, PDOParamEvent event_type);
virtual bool cursorCloser();
virtual bool support(SupportedMethod method);
private:
std::shared_ptr<PDOPgSqlConnection> m_conn;
PQ::Connection* m_server;
static unsigned long m_stmtNameCounter;
static unsigned long m_cursorNameCounter;
std::string m_stmtName;
std::string m_resolvedQuery;
std::string m_cursorName;
std::string err_msg;
PQ::Result m_result;
bool m_isPrepared;
bool m_hasParams;
std::vector<Oid> param_types;
std::vector<Variant> param_values;
std::vector<int> param_lengths;
std::vector<int> param_formats;
std::vector<Oid> m_pgsql_column_types;
long m_current_row;
std::string strprintf(const char* format, ...){
va_list args;
va_start (args, format);
int size = vsnprintf(nullptr, 0, format, args);
auto buffer = std::unique_ptr<char[]>(new char[size+1]);
if(vsnprintf((char*)buffer.get(), size+1, format, args) != size){
throw std::exception();
}
va_end (args);
return std::string((char*)buffer.get());
}
std::string oriToStr(PDOFetchOrientation ori, long offset, bool& success){
success = true;
switch(ori){
case PDO_FETCH_ORI_NEXT:
return std::string("NEXT");
case PDO_FETCH_ORI_PRIOR:
return std::string("BACKWARD");
case PDO_FETCH_ORI_FIRST:
return std::string("FIRST");
case PDO_FETCH_ORI_LAST:
return std::string("LAST");
case PDO_FETCH_ORI_ABS:
return strprintf("ABSOLUTE %ld", offset);
case PDO_FETCH_ORI_REL:
return strprintf("RELATIVE %ld", offset);
default:
success = false;
return std::string();
}
}
};
}
#endif