@@ -69,6 +69,7 @@ class Connection : public ObjectWrap {
69
69
NODE_SET_PROTOTYPE_METHOD (t, " _sendQueryWithParams" , SendQueryWithParams);
70
70
NODE_SET_PROTOTYPE_METHOD (t, " _sendPrepare" , SendPrepare);
71
71
NODE_SET_PROTOTYPE_METHOD (t, " _sendQueryPrepared" , SendQueryPrepared);
72
+ NODE_SET_PROTOTYPE_METHOD (t, " cancel" , Cancel);
72
73
NODE_SET_PROTOTYPE_METHOD (t, " end" , End);
73
74
74
75
target->Set (String::NewSymbol (" Connection" ), t->GetFunction ());
@@ -104,6 +105,22 @@ class Connection : public ObjectWrap {
104
105
return Undefined ();
105
106
}
106
107
108
+ // v8 entry point into Connection#cancel
109
+ static Handle <Value>
110
+ Cancel (const Arguments& args)
111
+ {
112
+ HandleScope scope;
113
+ Connection *self = ObjectWrap::Unwrap<Connection>(args.This ());
114
+
115
+ bool success = self->Cancel ();
116
+ if (!success) {
117
+ self -> EmitLastError ();
118
+ self -> DestroyConnection ();
119
+ }
120
+
121
+ return Undefined ();
122
+ }
123
+
107
124
// v8 entry point into Connection#_sendQuery
108
125
static Handle <Value>
109
126
SendQuery (const Arguments& args)
@@ -267,6 +284,15 @@ class Connection : public ObjectWrap {
267
284
return PQsendQueryPrepared (connection_, name, nParams, paramValues, NULL , NULL , 0 );
268
285
}
269
286
287
+ int Cancel ()
288
+ {
289
+ PGcancel* pgCancel = PQgetCancel (connection_);
290
+ char errbuf[256 ];
291
+ int result = PQcancel (pgCancel, errbuf, 256 );
292
+ PQfreeCancel (pgCancel);
293
+ return result;
294
+ }
295
+
270
296
// flushes socket
271
297
void Flush ()
272
298
{
0 commit comments