This is Controller.m in view mode; [Download] [Up]
/* Controller.m: * You may freely copy, distribute, and reuse the code in this example. * NeXT disclaims any warranty of any kind, expressed or implied, as to its * fitness for any particular use. * * Written by Mai Nguyen, NeXT Developer Support * */ #import <dbkit/dbkit.h> #import <libc.h> #import "Controller.h" #import "QualifiedAssociation.h" /* Define localized strings */ #define INSTALL_MODEL NXLocalizedString("Please install OracleDemo.dbmodel into your ~/Library/Databases directory and restart.", NULL, "Notify user that SybaseDemo.dbmodel must be installed in his local Databases directory.") @implementation Controller /* At init time, the proper association is set up between the master fetchgroup * and the detail fetchgroup, such that whenever a fetch happens, that fetch * will be done with the specified qualifier. */ -appDidInit:sender { id dbDatabase; /* Notify the user if the database can't be found */ if ( (dbDatabase = [DBDatabase findDatabaseNamed:"OracleDemo" connect:YES]) == nil) { NXRunAlertPanel(NULL, INSTALL_MODEL, "OK", NULL, NULL); return self; } [dbDatabase setDelegate:self]; detailFetchGroup = [departmentTable fetchGroupNamed:"employees"]; /* Set up the new association. Note that the caller of this function is responsible for freeing the new association. */ newAssociation = setUpAssociation(detailFetchGroup); dbQualifier = [[DBQualifier alloc] initForEntity:[detailFetchGroup entity] fromDescription: "%p > 1000", "salary"]; [newAssociation setQualifier: dbQualifier]; [departmentTable fetchAllRecords:sender]; [theWindow makeKeyAndOrderFront:nil]; return self; } - changeQualifier:sender { dbQualifier = [[DBQualifier alloc] initForEntity:[detailFetchGroup entity] fromDescription: "%p > %d", "salary", (int)[salaryField intValue]]; [newAssociation setQualifier: dbQualifier]; [departmentTable fetchAllRecords:sender]; return self; } - free { if (dbQualifier) [dbQualifier free]; if (newAssociation) [newAssociation free]; return [super free]; } /* For debugging purpose */ - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString usingBinder:aBinder { fprintf(stderr, "SQL Query: %s\n", (char *)aString); return YES; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.