Re: [Mysql-cocoa-users] Method to expose MYSQL pointer
Brought to you by:
sergecohen
From: Aaron J. <aj...@ed...> - 2004-09-07 13:24:27
|
Serge, That's fair enough - you're right about the data encapsulation aspect. In fact, I wasn't able to get the reconnect parameter to work at all - for some reason it would work when I linked directly against libmysqlclient, but not when I used SMySQL, even if I put the proper setting right in the SMySQL code and built SMySQL myself with the same version of libmysqlclient that worked on its own. I'm still not sure why this is, but for future reference (in case anybody else needs it) here is what I did. I just made a category on MCPConnection with one extra function: - (MCPResult *)queryStringWithoutReconnect:(NSString *)query { static BOOL disconnected = NO; if (disconnected) { NSLog(@"Connection disconnected!"); return nil; } MCPResult *result = [self queryString:query]; if (([self getLastErrorID] == CR_SERVER_GONE_ERROR) || ([self getLastErrorID] == CR_SERVER_LOST)) { NSLog(@"Connection disconnected!"); disconnected = YES; } return result; } There are definitely more elegant ways to do this, but all I needed for my particular application was for no more queries to happen under any circumstances once the connection was lost. Serge, you might consider making a method that allows you to set the reconnect option and then use code similar to the above in the queryString: method to make sure that a reconnect doesn't occur if not desired. The reason that this is a big deal is that when libmysqlclient reconnects it loses any session variables you had set and, more importantly, it loses locks and transactions that the application will not be aware are gone. Aaron On Sep 6, 2004, at 4:21 PM, Serge Cohen wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi Aaron; > > Indeed I'd rather not provide the pointer to the connection > directly... just because this breaks the object concept and if some > one deadly needs it, the derivation solution (that you use) is still > there. > Instead I can propose to have an interface to set this kind of > parameters directly from the object. > I have to check exactly what should be 'settable' and which interface > will be correct with that (trying to avoid having too many functions > for that, maybe some kind of -setParameter:forKey: message). > > If other users are similar requirements or have preferences concerning > the interface to these kind of setting, please answer (to the list so > - - -if necessary- we can have a discution on that). > > Serge. > > PS: Aaron, sorry I sent you the mail from a wrong mail account, please > if you answer me use the sourceforge mail account, and don't reply > directly to the previous mail. Thanks. > > Le 4 sept. 04, à 03:47, Aaron Jacobs a écrit : > >> I've run across a situation where it would be very unfortunate for my >> application to automatically and silently re-establish its connection >> to the MySQL server if it is lost. The only way I've found to >> disable this behavior is to set the 'reconnect' member of the MYSQL >> structure to zero, rather than the default of one. So what I need is >> a method in MCPConnection that simply returns mConnection so that I >> can set the flag. For now I'll make a subclass of MCPConnection >> since mConnection is protected, but Serge do you think it would be >> possible to get such a method officially supported? >> >> Thanks, >> Aaron >> > ******************************************* > Serge Cohen > > GPG Key ID: 9CBB58FB > ******************************************* > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.3 (Darwin) > > iD8DBQFBPNTy5EPeG5y7WPsRAtTMAJ94ccaejFmam0EZIit++eoYd9mWTQCgkAKs > 26hTqH7QqWdTFQGyIO8bZ34= > =IARO > -----END PGP SIGNATURE----- > > > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_idP47&alloc_id808&op=click > _______________________________________________ > Mysql-cocoa-users mailing list > Mys...@li... > https://lists.sourceforge.net/lists/listinfo/mysql-cocoa-users |