home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Examples / DatabaseKit / AssociationSybase / Controller.m < prev    next >
Encoding:
Text File  |  1993-03-30  |  2.2 KB  |  78 lines

  1. /* Controller.m:
  2.  * You may freely copy, distribute, and reuse the code in this example.
  3.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  4.  * fitness for any particular use.
  5.  *
  6.  * Written by Mai Nguyen, NeXT Developer Support
  7.  *
  8.  */
  9. #import    <dbkit/dbkit.h>
  10. #import <libc.h>
  11. #import "Controller.h"
  12. #import "QualifiedAssociation.h"
  13.  
  14. /* Define localized strings */
  15. #define INSTALL_MODEL NXLocalizedString("Please install SybaseDemo.dbmodela into your project directory and restart.", NULL, "Notify user that SybaseDemo.dbmodeal must be installed in his project directory.")
  16.  
  17. @implementation Controller
  18.  
  19. /* At init time, the proper association is set up between the master fetchgroup
  20.  * and the detail fetchgroup, such that whenever a fetch happens, that fetch
  21.  * will be done with the specified qualifier.
  22.  */ 
  23. -appDidInit:sender
  24. {
  25.     id    dbDatabase;
  26.  
  27.         /* Notify the user if the database can't be found */
  28.     if ( (dbDatabase = [DBDatabase findDatabaseNamed:"SybaseDemo" connect:YES]) == nil) {
  29.         NXRunAlertPanel(NULL, INSTALL_MODEL, "OK", NULL, NULL);
  30.         return self;
  31.     }
  32.     [dbDatabase setDelegate:self];
  33.     
  34.     detailFetchGroup = [storeTable fetchGroupNamed:"sales"];
  35.  
  36.           /* Set up the new association.
  37.            Note that the new association now belongs to the DBModule
  38.            just as the old one did. */
  39.         newAssociation = [[QualifiedAssociation alloc]
  40.         initAndReplaceAssociationTo:detailFetchGroup];
  41.     dbQualifier = [[DBQualifier alloc] 
  42.             initForEntity:[detailFetchGroup entity]
  43.             fromDescription: "%p > 1", "quantity"];
  44.     [newAssociation setQualifier: dbQualifier];
  45.     [storeTable fetchAllRecords:sender];
  46.     [theWindow makeKeyAndOrderFront:nil];
  47.     return self;
  48. }
  49.  
  50. - changeQualifier:sender
  51. {
  52.     dbQualifier = [[DBQualifier alloc] 
  53.             initForEntity:[detailFetchGroup entity]
  54.             fromDescription: "%p > %d", "quantity", 
  55.             (int)[quantityField intValue]];
  56.     [newAssociation setQualifier: dbQualifier];
  57.     [storeTable fetchAllRecords:sender];
  58.     return self;
  59. }
  60.  
  61. - free
  62. {
  63.     if (dbQualifier)
  64.         [dbQualifier free];
  65.     return [super free];
  66. }
  67.  
  68. /* For debugging purpose */
  69. - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString
  70.      usingBinder:aBinder
  71. {
  72.     fprintf(stderr, "SQL Query: %s\n", (char *)aString);
  73.     return YES;
  74. }
  75.     
  76. @end
  77.  
  78.