1 // $Id: gdltest.m 1 2004-08-20 10:38:46Z znek $
3 #import <Foundation/Foundation.h>
4 #import <EOAccess/EOAccess.h>
5 #include <NGExtensions/NGExtensions.h>
7 int main(int argc, char **argv, char **env) {
10 EOAdaptorContext *ctx;
12 NSDictionary *conDict;
15 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
19 conDict = [NSDictionary dictionaryWithContentsOfFile:@"condict.plist"];
20 NSLog(@"condict is %@", conDict);
22 if ((a = [EOAdaptor adaptorWithName:@"PostgreSQL"]) == nil) {
23 NSLog(@"found no PostgreSQL adaptor ..");
27 NSLog(@"got adaptor %@", a);
28 [a setConnectionDictionary:conDict];
29 NSLog(@"got adaptor with condict %@", a);
31 ctx = [a createAdaptorContext];
32 ch = [ctx createAdaptorChannel];
35 m = AUTORELEASE([[EOModel alloc] initWithContentsOfFile:@"test.eomodel"]);
38 [a setConnectionDictionary:conDict];
42 expr = [[NSUserDefaults standardUserDefaults] stringForKey:@"sql"];
44 NSLog(@"opening channel ..");
46 [ch setDebugEnabled:YES];
48 if ([ch openChannel]) {
49 NSLog(@"channel is open");
51 if ([ctx beginTransaction]) {
52 NSLog(@"began tx ..");
56 NSAutoreleasePool *pool = [NSAutoreleasePool new];
65 if ([ch evaluateExpression:expr]) {
68 attrs = [ch describeResults];
69 NSLog(@"results: %@", attrs);
71 while ((record = [ch fetchAttributes:attrs withZone:nil]))
72 NSLog(@"fetched %@", record);
76 /* fetch some doof records */
78 e = [m entityNamed:@"Doof"];
79 NSLog(@"entity: %@", e);
84 attrs = [e attributes];
86 if ([ch selectAttributes:attrs
87 describedByQualifier:q
92 while ((record = [ch fetchAttributes:attrs withZone:nil])) {
93 NSLog(@"fetched %@ birthday %@",
94 [record valueForKey:@"pkey"],
95 [record valueForKey:@"companyId"]);
99 NSLog(@"Could not select ..");
101 /* fetch some team records */
103 if ((e = [m entityNamed:@"Team"])) {
105 attrs = [e attributes];
107 if ([ch selectAttributes:attrs
108 describedByQualifier:q
111 NSDictionary *record;
113 while ((record = [ch fetchAttributes:attrs withZone:nil])) {
114 NSLog(@"fetched %@ birthday %@",
115 [record valueForKey:@"description"],
116 [record valueForKey:@"companyId"]);
120 NSLog(@"Could not select ..");
125 if ((e = [m entityNamed:@"Person"])) {
126 attrs = [e attributes];
127 q = [[EOSQLQualifier alloc]
129 qualifierFormat:@"%A='helge'", @"login"];
132 if ([ch selectAttributes:attrs
133 describedByQualifier:q
136 NSDictionary *record;
138 record = [ch fetchAttributes:attrs withZone:nil];
141 NSLog(@"Could not select ..");
147 NSLog(@"committing tx ..");
148 if ([ctx commitTransaction])
149 NSLog(@" could commit.");
151 NSLog(@" commit failed.");
154 NSLog(@"closing channel ..");
159 fprintf(stderr, "exception: %s\n", [[localException description] cString]);