martinrybak / SQLClient

Native Microsoft SQL Server client for iOS
http://objcsharp.wordpress.com/2013/10/15/an-open-source-sql-server-library-for-ios/
MIT License
124 stars 51 forks source link

Getting bad access when try to execute multiple queries through sqlclient. #19

Closed gopalsys closed 7 years ago

gopalsys commented 9 years ago

Here is my code trying to execute multiple commands at a time. i am unable get data getting bad access error.

SQLClient* client = [SQLClient sharedInstance]; client.delegate = (id)self; [client connect:@"port" username:@"un" password:@"pwd" database:@"db" completion:^(BOOL success) { if (success) { for(int i=0;i<=onholdarraycount;i++){ NSString _query=[NSString stringWithFormat:@"select a.Invoice_Number,a.OnHoldID,a.Cashier_ID,a.Section_ID,a.Status,a.Occupied,b.ShapeType from Invoice_OnHold a,Table_Diagram b where a.OnHoldID=b.Table_Number and a.SectionID='%@'",sectionaname]; [client execute:query completion:^(NSArray results) { for (NSArray* table in results) nslog(@“%@”,table); } [client disconnect]; }else{ } }];

Thanks for help in advance.

martinrybak commented 9 years ago

FreeTDS only allows one execute operation at a time. You must wait for the completion block to be invoked before you can submit your next operation.

martinrybak commented 9 years ago

Yes, that is fine. I do the same in my projects. You just can't run multiple execute commands at once. You could use a serial operation queue, or simply block the UI with a modal spinner while an operation executes.

martinrybak commented 9 years ago

Hi, like I said FreeTDS only allows you to execute one statement at a time. Please review how to chain asynchronous methods in objective-C via nested callbacks, operation queues, or Promises to get your desired behavior.