]> err.no Git - sope/blob - sope-gdl1/GDLAccess/test.py
minor changes to Xcode project layout
[sope] / sope-gdl1 / GDLAccess / test.py
1 #!/usr/bin/env python
2 # $Id: test.py 2 2004-08-20 10:48:47Z znek $
3 from sys          import *
4 from Foundation   import *
5 from eoaccess     import *
6 from EOControl    import *
7 from NGExtensions import *
8 from GDLExtensions import *
9 import resource;
10
11 defaults = NSUserDefaults();
12
13 connDict = defaults["LSConnectionDictionary"];
14 if connDict is None:
15     print "missing connection dictionary\n";
16     exit(1);
17
18 primKeyGenDict = defaults["pkeyGeneratorDictionary"];
19 print primKeyGenDict;
20 if primKeyGenDict is None:
21     print "missing pkeyGeneratorDictionary\n";
22     exit(1);
23
24
25 print "ConnectionDictionary: ";
26 print connDict.description();
27
28 adaptorName = defaults["LSAdaptor"];
29 if adaptorName is None:
30     adaptorName = "Sybase10";
31
32 adaptor = EOAdaptor(adaptorName);
33 adaptor.setConnectionDictionary(connDict);
34 adaptor.setPkeyGeneratorDictionary(primKeyGenDict);
35
36 adContext = adaptor.createAdaptorContext();
37 adChannel = adContext.createAdaptorChannel();
38
39 def test_database_channel():
40     print "adChannel " + adChannel.description() + "\n";
41     print "channel   ";
42     print "attributesForTableName doc";
43     print adChannel.invoke1("attributesForTableName:", "doc");
44     print "primaryKeyAttributesForTableName document  _______________________________________\n";
45     print adChannel.invoke1("primaryKeyAttributesForTableName:", "document");
46     print "primaryKeyAttributesForTableName:, doc _______________________________________\n";    
47     print adChannel.invoke1("primaryKeyAttributesForTableName:", "doc");
48     print "primaryKeyAttributesForTableName company _______________________________________\n";    
49     print adChannel.invoke1("primaryKeyAttributesForTableName:", "company");
50     print "primaryKeyAttributesForTableName person_______________________________________\n";    
51     print adChannel.invoke1("primaryKeyAttributesForTableName:", "person");
52     print "_______________________________________\n";    
53
54 def test_adaptor_data_source():
55     adaptor = adChannel.adaptorContext().adaptor();
56     dict = NSMutableDictionary();
57     dict["login"]      = "jan_1";
58     dict["name"]       = "JR";
59     dict["firstname"]  = "jan";
60     dict["is_person"]  = 1;
61     dict["number"]     = "12345_1";
62     dict["birthday"]   = NSCalendarDate('1999-09-21 13:23', '%Y-%m-%d %H:%M');
63     dict["middlename"] = "Ein Unnuetzer middlename";
64     
65
66     dataSource = EOAdaptorDataSource(adChannel);
67     hints = NSMutableDictionary();
68     pks   = NSMutableArray();
69     pks.addObject("company_id");
70     hints.setObjectForKey(pks, "EOPrimaryKeyAttributeNamesHint")
71     
72     fetchSpec = EOFetchSpecification();
73     fetchSpec.setEntityName("company");
74     fetchSpec.setHints(hints);
75
76     dataSource.setFetchSpecification(fetchSpec);
77     print "-------------------- {insert ---------------------\n";
78     dataSource.insertObject(dict);
79     print "-------------------- insert} ---------------------\n";
80
81     print "-------------------- {select with hints ---------------------\n";
82     qualifier = EOQualifier("login = %@", ("jan_1", ))
83     fetchSpec = EOFetchSpecification();
84     fetchSpec.setQualifier(qualifier);
85     fetchSpec.setEntityName("company");
86     
87     hints = NSMutableDictionary();
88     pks.addObject("company_id");
89     hints.setObjectForKey(NSTimeZone('MET'), "EOFetchResultTimeZoneHint")
90     fetchSpec.setHints(hints);
91
92     sortOrderings = NSMutableArray();
93     sortOrderings.addObject(EOSortOrdering("login", "compareCaseInsensitiveAscending:"));
94     sortOrderings.addObject(EOSortOrdering("company_id", "compareCaseInsensitiveDescending:"));    
95     fetchSpec.setSortOrderings(sortOrderings);
96     dataSource = EOAdaptorDataSource(adChannel);
97     dataSource.setFetchSpecification(fetchSpec);
98     objs = dataSource.fetchObjects();
99     print objs;
100     print "-------------------- select} ---------------------\n";
101     obj = objs[0];
102
103     print "-------------------- {update ---------------------\n";
104     print obj;
105     obj["login"]      = "jan_1_1";
106     obj["middlename"] = EONull();
107     dataSource.updateObject(obj);
108     print "-------------------- update} ---------------------\n";
109
110     qualifier = EOQualifier("login caseInsensitiveLike %@", ("jan_1_*", ))
111     fetchSpec.setQualifier(qualifier);
112     dataSource.setFetchSpecification(fetchSpec);
113     
114     print "-------------------- {select ---------------------\n";
115     objs = dataSource.fetchObjects();
116     print objs;    
117     print "-------------------- select} ---------------------\n";
118
119     print "-------------------- {delete ---------------------\n";
120     obj = objs[0];
121     dataSource.deleteObject(obj);
122     print "-------------------- delete} ---------------------\n";
123
124     print "-------------------- {select ---------------------\n";
125     objs = dataSource.fetchObjects();
126     print objs;    
127     print "-------------------- select} ---------------------\n";
128
129
130 def test_cascaded_datasources():
131
132     adaptor = adChannel.adaptorContext().adaptor();
133     dict = NSMutableDictionary();
134     dict["login"]      = "jan_1";
135     dict["name"]       = "JR";
136     dict["firstname"]  = "jan";
137     dict["is_person"]  = 1;
138     dict["number"]     = "12345_1";
139
140     dataSource      = EOAdaptorDataSource(adChannel);
141     fetchSpec = EOFetchSpecification();
142     fetchSpec.setEntityName("company");
143     qualifier = EOQualifier("login like %@", ("j%", ))
144     fetchSpec = EOFetchSpecification();
145     fetchSpec.setQualifier(qualifier);
146     fetchSpec.setEntityName("company");
147     sortOrderings = NSMutableArray();
148     sortOrderings.addObject(EOSortOrdering("login", "compareCaseInsensitiveAscending:"));
149     fetchSpec.setSortOrderings(sortOrderings);    
150     hints = NSMutableDictionary();
151     pks   = NSMutableArray();
152     pks.addObject("company_id");
153     hints.setObjectForKey(pks, "EOPrimaryKeyAttributeNamesHint")
154     
155     fetchSpec.setHints(hints);
156
157     dataSource.setFetchSpecification(fetchSpec);
158     cacheDataSource = EOCacheDataSource(dataSource);    
159     objs = dataSource.fetchObjects();
160     print objs;
161     print cacheDataSource.fetchObjects();
162     print "-----------------------------\n";
163     print cacheDataSource.fetchObjects();
164     dataSource.insertObject(dict);
165     print "++++++++++++++++++++++++++++\n";
166
167     fetchSpec = EOFetchSpecification();
168     fetchSpec.setEntityName("company");
169     qualifier = EOQualifier("login = %@", ("jan_1", ))
170     fetchSpec = EOFetchSpecification();
171     fetchSpec.setQualifier(qualifier);
172     fetchSpec.setEntityName("company");
173     dataSource.setFetchSpecification(fetchSpec);
174     cacheDataSource = EOCacheDataSource(dataSource);    
175     objs = dataSource.fetchObjects();
176     obj = objs[0];
177     print objs;
178     print "-----------------------------\n";
179     print cacheDataSource.deleteObject(obj);
180     print "++++++++++++++++++++++++++++\n";    
181     print cacheDataSource.fetchObjects();
182
183 def echo_logins(objs):
184     for o in objs:
185         print o['login'];
186
187 def test_sort_datasource():
188     dataSource      = EOAdaptorDataSource(adChannel);
189
190     fetchSpec = EOFetchSpecification();
191     fetchSpec.setEntityName("company");
192     qualifier = EOQualifier("login like %@", ("%a%", ))
193     fetchSpec.setQualifier(qualifier);
194     
195     dataSource.setFetchSpecification(fetchSpec);
196     echo_logins(dataSource.fetchObjects());
197
198     sortOrderings = NSMutableArray();
199     sO = EOSortOrdering("login", "compareDescending:");
200     sortOrderings.addObject(sO);
201     fetchSpec.setSortOrderings(sortOrderings);
202     dataSource.setFetchSpecification(fetchSpec);
203
204     echo_logins(dataSource.fetchObjects());
205
206 print resource.getrlimit(resource.RLIMIT_CORE);
207 if adChannel.openChannel():
208     print "open channel ok";
209 else:
210     print "open channel failed";
211     exit(1);
212 print "adChannel ", adChannel;
213
214
215 #test_database_channel();
216 test_adaptor_data_source();
217 #test_cascaded_datasources();
218 #test_sort_datasource();