@@ -29,8 +29,7 @@ struct ExtendedQueryStateMachine {
2929 case sendParseDescribeBindExecuteSync( PostgresQuery )
3030 case sendParseDescribeSync( name: String , query: String , bindingDataTypes: [ PostgresDataType ] )
3131 case sendBindExecuteSync( PSQLExecuteStatement )
32- case sendQuery( String )
33-
32+
3433 // --- general actions
3534 case failQuery( EventLoopPromise < PSQLRowStream > , with: PSQLError )
3635 case succeedQuery( EventLoopPromise < PSQLRowStream > , with: QueryResult )
@@ -176,12 +175,7 @@ struct ExtendedQueryStateMachine {
176175 }
177176
178177 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 {
185179 return self . setAndFireError ( . unexpectedBackendMessage( . rowDescription( rowDescription) ) )
186180 }
187181
@@ -270,7 +264,7 @@ struct ExtendedQueryStateMachine {
270264 }
271265 // we ignore all rows and wait for readyForQuery
272266 return . wait
273-
267+
274268 case . initialized,
275269 . messagesSent,
276270 . parseCompleteReceived,
@@ -301,7 +295,7 @@ struct ExtendedQueryStateMachine {
301295 case . prepareStatement:
302296 preconditionFailure ( " Invalid state: \( self . state) " )
303297 }
304-
298+
305299 case . streaming( _, var demandStateMachine) :
306300 return self . avoidingStateMachineCoW { state -> Action in
307301 state = . commandComplete( commandTag: commandTag)
@@ -312,14 +306,14 @@ struct ExtendedQueryStateMachine {
312306 precondition ( self . isCancelled)
313307 self . state = . commandComplete( commandTag: commandTag)
314308 return . wait
315-
309+
316310 case . initialized,
311+ . messagesSent,
317312 . parseCompleteReceived,
318313 . parameterDescriptionReceived,
319314 . noDataMessageReceived,
320315 . emptyQueryResponseReceived,
321316 . rowDescriptionReceived,
322- . messagesSent,
323317 . commandComplete,
324318 . error:
325319 return self . setAndFireError ( . unexpectedBackendMessage( . commandComplete( commandTag) ) )
@@ -329,21 +323,20 @@ struct ExtendedQueryStateMachine {
329323 }
330324
331325 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+ }
342329
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)
345337 }
346- default :
338+
339+ case . prepareStatement( _, _, _, _) :
347340 return self . setAndFireError ( . unexpectedBackendMessage( . emptyQueryResponse) )
348341 }
349342 }
0 commit comments