forked from r-dbi/RPostgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.cpp
More file actions
120 lines (92 loc) · 2.41 KB
/
Copy pathconnection.cpp
File metadata and controls
120 lines (92 loc) · 2.41 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "pch.h"
#include "RPostgres_types.h"
// [[Rcpp::export]]
int client_version() {
return PQlibVersion();
}
// [[Rcpp::export]]
XPtr<DbConnectionPtr> connection_create(
std::vector<std::string> keys,
std::vector<std::string> values,
bool check_interrupts
) {
LOG_VERBOSE;
DbConnectionPtr* pConn = new DbConnectionPtr(
new DbConnection(keys, values, check_interrupts)
);
return XPtr<DbConnectionPtr>(pConn, true);
}
// [[Rcpp::export]]
bool connection_valid(XPtr<DbConnectionPtr> con_) {
DbConnectionPtr* con = con_.get();
return con;
}
// [[Rcpp::export]]
void connection_release(XPtr<DbConnectionPtr> con_) {
if (!connection_valid(con_)) {
warning("Already disconnected");
return;
}
DbConnectionPtr* con = con_.get();
if (con->get()->has_query()) {
warning("%s\n%s",
"There is a result object still in use.",
"The connection will be automatically released when it is closed"
);
}
con->get()->disconnect();
con_.release();
}
// [[Rcpp::export]]
List connection_info(DbConnection* con) {
return con->info();
}
// Quoting
// [[Rcpp::export]]
CharacterVector connection_quote_string(DbConnection* con, CharacterVector xs) {
R_xlen_t n = xs.size();
CharacterVector output(n);
for (R_xlen_t i = 0; i < n; ++i) {
String x = xs[i];
output[i] = con->quote_string(x);
}
return output;
}
// [[Rcpp::export]]
CharacterVector connection_quote_identifier(DbConnection* con, CharacterVector xs) {
R_xlen_t n = xs.size();
CharacterVector output(n);
for (R_xlen_t i = 0; i < n; ++i) {
String x = xs[i];
output[i] = con->quote_identifier(x);
}
return output;
}
// Transactions
// [[Rcpp::export]]
bool connection_is_transacting(DbConnection* con) {
return con->is_transacting();
}
// [[Rcpp::export]]
void connection_set_transacting(DbConnection* con, bool transacting) {
con->set_transacting(transacting);
}
// Specific functions
// [[Rcpp::export]]
void connection_copy_data(DbConnection* con, std::string sql, List df) {
return con->copy_data(sql, df);
}
// [[Rcpp::export]]
List connection_wait_for_notify(DbConnection* con, int timeout_secs) {
return con->wait_for_notify(timeout_secs);
}
// as() override
namespace Rcpp {
template<>
DbConnection* as(SEXP x) {
DbConnectionPtr* connection = (DbConnectionPtr*)(R_ExternalPtrAddr(x));
if (!connection)
stop("Invalid connection");
return connection->get();
}
}