You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/pg/lib/query.js
+25-27
Original file line number
Diff line number
Diff line change
@@ -97,24 +97,33 @@ class Query extends EventEmitter {
97
97
}
98
98
}
99
99
100
-
handleCommandComplete(msg,con){
100
+
handleCommandComplete(msg,connection){
101
101
this._checkForMultirow()
102
102
this._result.addCommandComplete(msg)
103
103
// need to sync after each command complete of a prepared statement
104
-
if(this.isPreparedStatement&&!this._hasSentSync){
105
-
this._hasSentSync=true
106
-
con.sync()
107
-
}
104
+
this.maybeSync(connection)
108
105
}
109
106
110
107
// if a named prepared statement is created with empty query text
111
108
// the backend will send an emptyQuery message but *not* a command complete message
112
109
// execution on the connection will hang until the backend receives a sync message
113
-
handleEmptyQuery(con){
114
-
if(this.isPreparedStatement&&!this._hasSentSync){
115
-
this._hasSentSync=true
116
-
con.sync()
110
+
handleEmptyQuery(connection){
111
+
this.maybeSync(connection)
112
+
}
113
+
114
+
handleError(err,connection){
115
+
// need to sync after error during a prepared statement
116
+
this.maybeSync(connection)
117
+
if(this._canceledDueToError){
118
+
err=this._canceledDueToError
119
+
this._canceledDueToError=false
120
+
}
121
+
// if callback supplied do not emit error event as uncaught error
122
+
// events will bubble up to node process
123
+
if(this.callback){
124
+
returnthis.callback(err)
117
125
}
126
+
this.emit('error',err)
118
127
}
119
128
120
129
handleReadyForQuery(con){
@@ -127,27 +136,16 @@ class Query extends EventEmitter {
127
136
this.emit('end',this._results)
128
137
}
129
138
130
-
handleError(err,connection){
131
-
// need to sync after error during a prepared statement
132
-
// in postgres 9.6 the backend sends both a command complete and error response
133
-
// to a query which has timed out on rare, random occasions. If we send sync twice we will receive
134
-
// to 'readyForQuery' events. I think this might be a bug in postgres 9.6, but I'm not sure...
135
-
// the docs here: https://www.postgresql.org/docs/9.6/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
136
-
// say "Therefore, an Execute phase is always terminated by the appearance of exactly one of these messages: CommandComplete, EmptyQueryResponse (if the portal was created from an empty query string), ErrorResponse, or PortalSuspended."
137
-
if(this.isPreparedStatement&&!this._hasSentSync){
139
+
// in postgres 9.6 the backend sends both a command complete and error response
140
+
// to a query which has timed out on rare, random occasions. If we send sync twice we will receive
141
+
// to 'readyForQuery' events. I think this might be a bug in postgres 9.6, but I'm not sure...
142
+
// the docs here: https://www.postgresql.org/docs/9.6/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
143
+
// say "Therefore, an Execute phase is always terminated by the appearance of exactly one of these messages: CommandComplete, EmptyQueryResponse (if the portal was created from an empty query string), ErrorResponse, or PortalSuspended."
144
+
maybeSync(connection){
145
+
if(this.isPreparedStatement){
138
146
this._hasSentSync=true
139
147
connection.sync()
140
148
}
141
-
if(this._canceledDueToError){
142
-
err=this._canceledDueToError
143
-
this._canceledDueToError=false
144
-
}
145
-
// if callback supplied do not emit error event as uncaught error
0 commit comments