]> err.no Git - sope/blob - sope-gdl1/GDLAccess/connect-EOAdaptor.m
minor changes to Xcode project layout
[sope] / sope-gdl1 / GDLAccess / connect-EOAdaptor.m
1 /* 
2    EOAdaptorChannel.m
3
4    Copyright (C) 1996 Free Software Foundation, Inc.
5
6    Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
7    Date: October 1996
8
9    This file is part of the GNUstep Database Library.
10
11    This library is free software; you can redistribute it and/or
12    modify it under the terms of the GNU Library General Public
13    License as published by the Free Software Foundation; either
14    version 2 of the License, or (at your option) any later version.
15
16    This library is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    Library General Public License for more details.
20
21    You should have received a copy of the GNU Library General Public
22    License along with this library; see the file COPYING.LIB.
23    If not, write to the Free Software Foundation,
24    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26 // $Id: connect-EOAdaptor.m 1 2004-08-20 10:38:46Z znek $
27
28 #import <Foundation/Foundation.h>
29 #include <GDLAccess/EOAdaptor.h>
30 #include <GDLAccess/EOAdaptorContext.h>
31 #include <GDLAccess/EOAdaptorChannel.h>
32 #include <stdio.h>
33
34 int main(int argc, char **argv, char **env) {
35   NSAutoreleasePool *pool;
36   NSArray      *args;
37   NSString     *adaptorName;
38   NSString     *condictstr;
39   NSDictionary *condict;
40   EOAdaptor    *adaptor;
41   EOAdaptorContext *adctx;
42   EOAdaptorChannel *adch;
43   BOOL ok;
44   
45   pool = [[NSAutoreleasePool alloc] init];
46 #if LIB_FOUNDATION_LIBRARY
47   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
48 #endif
49   
50   args = [[NSProcessInfo processInfo] arguments];
51   if ([args count] < 3) {
52     fprintf(stderr, "usage: %s adaptorname condict\n", argv[0]);
53     exit(10);
54   }
55   
56   adaptorName = [args objectAtIndex:1];
57   condictstr  = [args objectAtIndex:2];
58
59   /* load adaptor */
60   
61   NS_DURING {
62     adaptor = [EOAdaptor adaptorWithName:adaptorName];
63   }
64   NS_HANDLER {
65     fprintf(stderr, "ERROR: %s: %s\n",
66             [[localException name]   cString],
67             [[localException reason] cString]);
68     adaptor = nil;
69   }
70   NS_ENDHANDLER;
71   
72   if (adaptor == nil) {
73     fprintf(stderr, "ERROR: failed to load adaptor '%s'.\n", 
74             [adaptorName cString]);
75     exit(1);
76   }
77   
78   printf("did load adaptor: %s\n", [[adaptor name] cString]);
79
80   /* setup connection dictionary */
81   
82   if ((condict = [condictstr propertyList]) == nil) {
83     fprintf(stderr, "ERROR: invalid connection dictionary '%s'.\n", 
84             [condictstr cString]);
85     exit(2);
86   }
87   [adaptor setConnectionDictionary:condict];
88
89   /* setup connection */
90   
91   if ((adctx = [adaptor createAdaptorContext]) == nil) {
92     fprintf(stderr, "ERROR: could not create adaptor context.");
93     exit(3);
94   }
95   if ((adch = [adctx createAdaptorChannel]) == nil) {
96     fprintf(stderr, "ERROR: could not create adaptor channel.");
97     exit(4);
98   }
99   
100   /* connect */
101
102   ok = NO;
103   NS_DURING {
104     ok = [adch openChannel];
105   }
106   NS_HANDLER {
107     fprintf(stderr, "ERROR: could not connect to database %s: %s\n",
108             [[localException name]   cString],
109             [[localException reason] cString]);
110     exit(5);
111   }
112   NS_ENDHANDLER;
113   
114   if (!ok) {
115     fprintf(stderr, "ERROR: could not connect to database.\n");
116     exit(6);
117   }
118   else
119     printf("connection could be established.\n");
120   
121   [adch closeChannel];
122   
123   exit(0);
124   return 0;
125 }