@@ -29,8 +29,7 @@ struct ExtendedQueryStateMachine {
29
29
case sendParseDescribeBindExecuteSync( PostgresQuery )
30
30
case sendParseDescribeSync( name: String , query: String , bindingDataTypes: [ PostgresDataType ] )
31
31
case sendBindExecuteSync( PSQLExecuteStatement )
32
- case sendQuery( String )
33
-
32
+
34
33
// --- general actions
35
34
case failQuery( EventLoopPromise < PSQLRowStream > , with: PSQLError )
36
35
case succeedQuery( EventLoopPromise < PSQLRowStream > , with: QueryResult )
@@ -176,12 +175,7 @@ struct ExtendedQueryStateMachine {
176
175
}
177
176
178
177
mutating func rowDescriptionReceived( _ rowDescription: RowDescription ) -> Action {
179
- let queryContext : ExtendedQueryContext
180
- switch self . state {
181
- case . messagesSent( let extendedQueryContext) ,
182
- . parameterDescriptionReceived( let extendedQueryContext) :
183
- queryContext = extendedQueryContext
184
- default :
178
+ guard case . parameterDescriptionReceived( let queryContext) = self . state else {
185
179
return self . setAndFireError ( . unexpectedBackendMessage( . rowDescription( rowDescription) ) )
186
180
}
187
181
@@ -270,7 +264,7 @@ struct ExtendedQueryStateMachine {
270
264
}
271
265
// we ignore all rows and wait for readyForQuery
272
266
return . wait
273
-
267
+
274
268
case . initialized,
275
269
. messagesSent,
276
270
. parseCompleteReceived,
@@ -301,7 +295,7 @@ struct ExtendedQueryStateMachine {
301
295
case . prepareStatement:
302
296
preconditionFailure ( " Invalid state: \( self . state) " )
303
297
}
304
-
298
+
305
299
case . streaming( _, var demandStateMachine) :
306
300
return self . avoidingStateMachineCoW { state -> Action in
307
301
state = . commandComplete( commandTag: commandTag)
@@ -312,14 +306,14 @@ struct ExtendedQueryStateMachine {
312
306
precondition ( self . isCancelled)
313
307
self . state = . commandComplete( commandTag: commandTag)
314
308
return . wait
315
-
309
+
316
310
case . initialized,
311
+ . messagesSent,
317
312
. parseCompleteReceived,
318
313
. parameterDescriptionReceived,
319
314
. noDataMessageReceived,
320
315
. emptyQueryResponseReceived,
321
316
. rowDescriptionReceived,
322
- . messagesSent,
323
317
. commandComplete,
324
318
. error:
325
319
return self . setAndFireError ( . unexpectedBackendMessage( . commandComplete( commandTag) ) )
@@ -329,21 +323,20 @@ struct ExtendedQueryStateMachine {
329
323
}
330
324
331
325
mutating func emptyQueryResponseReceived( ) -> Action {
332
- switch self . state {
333
- case . bindCompleteReceived( let queryContext) :
334
- switch queryContext. query {
335
- case . unnamed( _, let eventLoopPromise) ,
336
- . executeStatement( _, let eventLoopPromise) :
337
- return self . avoidingStateMachineCoW { state -> Action in
338
- state = . emptyQueryResponseReceived
339
- let result = QueryResult ( value: . noRows( . emptyResponse) , logger: queryContext. logger)
340
- return . succeedQuery( eventLoopPromise, with: result)
341
- }
326
+ guard case . bindCompleteReceived( let queryContext) = self . state else {
327
+ return self . setAndFireError ( . unexpectedBackendMessage( . emptyQueryResponse) )
328
+ }
342
329
343
- case . prepareStatement:
344
- return self . setAndFireError ( . unexpectedBackendMessage( . emptyQueryResponse) )
330
+ switch queryContext. query {
331
+ case . unnamed( _, let eventLoopPromise) ,
332
+ . executeStatement( _, let eventLoopPromise) :
333
+ return self . avoidingStateMachineCoW { state -> Action in
334
+ state = . emptyQueryResponseReceived
335
+ let result = QueryResult ( value: . noRows( . emptyResponse) , logger: queryContext. logger)
336
+ return . succeedQuery( eventLoopPromise, with: result)
345
337
}
346
- default :
338
+
339
+ case . prepareStatement( _, _, _, _) :
347
340
return self . setAndFireError ( . unexpectedBackendMessage( . emptyQueryResponse) )
348
341
}
349
342
}
0 commit comments