Re: [Mysql-cocoa-users] MySQL Result in NSTable
Brought to you by:
sergecohen
From: Camille Goureau-S. <sui...@wa...> - 2003-03-12 07:35:36
|
Hi, > > I'm new to Cocoa, and really need help learning on how to get a result > from a MySQL query, and putting the result into multiple fields on an > NSTableView. Any help would be greatly appreciated, thanks. Do you know how to handle a data source for your NSTableView ? If yes, here's how I handle this : - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { id resultat ; resultat = [self obtenirChamps: [aTableColumn identifier] atIndex: [[listeIndexLocal objectAtIndex: rowIndex] intValue]] ; if (resultat != nil) return resultat ; else return @"-" ; } - (NSString*) obtenirChamps: (NSString*)champs atIndex: (int)index { SMySQLResult *result; NSDictionary *ligne; NSMutableString *chaineQuery = [[NSMutableString alloc] initWithString: @""] ; NSString *chaine ; [chaineQuery setString: @"select "] ; [chaineQuery appendString: champs] ; [chaineQuery appendString: @" from stock where id ="] ; [chaineQuery appendString: [[NSNumber numberWithInt: index] stringValue]] ; [chaineQuery appendString: @";"] ; result = [connectMySQL queryString: chaineQuery]; ligne = [result fetchRowAsDictionary] ; chaine = [ligne objectForKey: champs] ; [chaineQuery release] ; return chaine ; } Hope that helps. Camille |