oleghnidets / OHMySQL

Swift + MySQL = ❤️
https://oleghnidets.github.io/OHMySQL/documentation/ohmysql/
MIT License
235 stars 42 forks source link

Commands out of sync #24

Closed piotrekjeremicz closed 2 years ago

piotrekjeremicz commented 4 years ago

What did you do?

I am trying to fetch a bunch of queries that were prepared as "CALL" function. The queue contains the same function with other variables. The database has a limit of logged instances on the same credentials.

What happened instead?

Unfortunately, despite the fact that I was able to log in one time and invoke many commands, I get this error after first positive result: 2020-04-09 23:47:48.503632+0200 app[4332:387694] -[OHMySQLQueryContext executeQueryRequest:error:] -[ERROR] The connection is broken: Commands out of sync; you can't run this command now 2020-04-09 23:47:48.503779+0200 app[4332:387694] -[OHMySQLQueryContext executeQueryRequest:error:] -[ERROR] Cannot connect to DB. Check your configuration properties. 2020-04-09 23:47:48.504129+0200 app[4332:387694] -[OHMySQLQueryContext executeQueryRequestAndFetchResult:error:] -[ERROR] Cannot get results: Error Domain=mysql.error.domain Code=2000 "Cannot connect to DB. Check your configuration properties." UserInfo={NSLocalizedDescription=Cannot connect to DB. Check your configuration properties.}

What did you expect?

I want to fetch the completed queue by call many queries of the same function with different variables.

Demo Project

Sample code:

let user = OHMySQLUser(userName: "username", password: "password", serverName: "www.example.com", dbName: "name", port: 123456, socket: nil)!
self.coordinator = OHMySQLStoreCoordinator(user: user)
self.coordinator!.connect()

let context = OHMySQLQueryContext()
context.storeCoordinator = self.coordinator!

var i = 1001
var requestArray: [[String: Any]] = []
repeat {
        let query = "CALL fetch_data_with_parameters('\(i)', '01', null)"
        let request = OHMySQLQueryRequest.init(queryString: query)

        let response = try context.storeCoordinator.executeQueryRequestAndFetchResult(request)

       if let add = response {
              requestArray += add
       }

       sleep(10)

      i += 1
} while i < 1900

self.coordinator!.disconnect()
oleghnidets commented 3 years ago

Hi @piotrekjeremicz,

Feels like threading issue. I know the response is too late 😄 but I'll try to find a time to investigate that.

piotrekjeremicz commented 3 years ago

Hi @oleghnidets Thank you very much! I did not solve this problem. To skip it I moved a part of the code to php scripts but still I will prefer to refactor it into the swift if there will be a possibility.

oleghnidets commented 2 years ago

Hi @piotrekjeremicz

Could you check out a new version 3.0.0? Fingers crossed it's fixed.