|
|
1.1 root 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: if (dbQualifier)
53: [dbQualifier free];
54: dbQualifier = [[DBQualifier alloc]
55: initForEntity:[detailFetchGroup entity]
56: fromDescription: "%p > %d", "quantity",
57: (int)[quantityField intValue]];
58: [newAssociation setQualifier: dbQualifier];
59: [storeTable fetchAllRecords:sender];
60: return self;
61: }
62:
63: - free
64: {
65: if (dbQualifier)
66: [dbQualifier free];
67: return [super free];
68: }
69:
70: /* For debugging purpose */
71: - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString
72: usingBinder:aBinder
73: {
74: fprintf(stderr, "SQL Query: %s\n", (char *)aString);
75: return YES;
76: }
77:
78: @end
79:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.