]> err.no Git - scalable-opengroupware.org/blob - db/tests/znek/inserts.m
87bb6ff6f9b5b01794a949f319a48789f80d3e5b
[scalable-opengroupware.org] / db / tests / znek / inserts.m
1 /*
2   @DISCLAIMER@
3 */
4 // $Id$
5
6 #import <Foundation/Foundation.h>
7 #import <EOAccess/EOAccess.h>
8 #import <NGExtensions/NGExtensions.h>
9
10
11 #define DEBUG 0
12
13
14 #define ALL_RECORDS @"/home/znek/all-BALI.plist"
15
16
17 int main(int argc, char **argv, char **env) {
18     NSAutoreleasePool *pool;
19     EOModel          *m = nil;
20     EOAdaptor        *a;
21     EOAdaptorContext *ctx;
22     EOAdaptorChannel *ch;
23     NSDictionary     *conDict;
24     
25     pool = [[NSAutoreleasePool alloc] init];
26 #if LIB_FOUNDATION_LIBRARY
27     [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
28 #endif
29
30     conDict = [NSDictionary dictionaryWithContentsOfFile:@"connection.plist"];
31     NSLog(@"condict is %@", conDict);
32     
33     if ((a = [EOAdaptor adaptorWithName:@"PostgreSQL72"]) == nil) {
34         NSLog(@"found no PostgreSQL adaptor ..");
35         exit(1);
36     }
37     
38     NSLog(@"got adaptor %@", a);
39     [a setConnectionDictionary:conDict];
40     NSLog(@"got adaptor with condict %@", a);
41     
42     ctx = [a   createAdaptorContext];
43     ch  = [ctx createAdaptorChannel];
44     
45     m = [[EOModel alloc] initWithContentsOfFile:@"inserts.eomodel"];
46     if (m) {
47         [a setModel:m];
48         [a setConnectionDictionary:conDict];
49     }
50     
51     
52     NSLog(@"opening channel ..");
53     
54     [ch setDebugEnabled:YES];
55     
56     if ([ch openChannel]) {
57         NSLog(@"channel is open");
58
59 #if 0
60         if ([ctx beginTransaction]) {
61             NSLog(@"began tx ..");
62 #endif            
63             /* do something */
64             {
65                 NSAutoreleasePool *lpool = [[NSAutoreleasePool alloc] init];
66                 EOEntity *e;
67                 EOSQLQualifier *q;
68                 NSArray *attrs;
69                 NSString *expr;
70
71 #if 0
72                 NS_DURING
73
74                 if([ctx beginTransaction]) {
75                     expr = @"DROP TABLE SOGo_test";
76
77                     if([ch evaluateExpression:expr]) {
78                         attrs = [ch describeResults];
79                         NSLog(@"results: %@", attrs);
80
81
82                         if([ctx commitTransaction]) {
83                             NSLog(@"DROP'ed table - committed.");
84                         } else {
85                             NSLog(@"couldn't commit DROP TABLE!");
86                         }
87                     }
88                 }
89                 NS_HANDLER
90
91                     NSLog(@"DROP table aborted - %@", [localException reason]);
92                     NSLog(@"a");
93
94                 NS_ENDHANDLER
95 #endif
96
97                 NS_DURING
98
99                 if([ctx beginTransaction]) {
100                     expr = @"CREATE TABLE SOGo_test (c_id INT PRIMARY KEY, c_dir       VARCHAR(255) NOT NULL, c_cn VARCHAR(40) NOT NULL, c_mailto    VARCHAR(120) NOT NULL);";
101                     if([ch evaluateExpression:expr]) {
102                         if([ctx commitTransaction]) {
103                             NSLog(@"CREATE TABLE - committed");
104                         } else {
105                             NSLog(@"couldn't commit CREATE TABLE!");
106                         }
107                     }
108                 }
109                 
110                 NS_HANDLER
111
112                    fprintf(stderr, "exception: %s\n", [[localException description] cString]);
113                    abort();
114
115                 NS_ENDHANDLER;
116
117                 [lpool release];
118             }
119  
120 #if 0
121             NSLog(@"committing tx ..");
122             if ([ctx commitTransaction])
123                 NSLog(@"  could commit.");
124             else
125                 NSLog(@"  commit failed.");
126         }
127 #endif
128         
129         NSLog(@"closing channel ..");
130         [ch closeChannel];
131     }
132
133     
134     [m release];
135     [pool release];
136
137     exit(0);
138     return 0;
139 }