2 # $Id: test.py 2 2004-08-20 10:48:47Z znek $
4 from Foundation import *
6 from EOControl import *
7 from NGExtensions import *
8 from GDLExtensions import *
11 defaults = NSUserDefaults();
13 connDict = defaults["LSConnectionDictionary"];
15 print "missing connection dictionary\n";
18 primKeyGenDict = defaults["pkeyGeneratorDictionary"];
20 if primKeyGenDict is None:
21 print "missing pkeyGeneratorDictionary\n";
25 print "ConnectionDictionary: ";
26 print connDict.description();
28 adaptorName = defaults["LSAdaptor"];
29 if adaptorName is None:
30 adaptorName = "Sybase10";
32 adaptor = EOAdaptor(adaptorName);
33 adaptor.setConnectionDictionary(connDict);
34 adaptor.setPkeyGeneratorDictionary(primKeyGenDict);
36 adContext = adaptor.createAdaptorContext();
37 adChannel = adContext.createAdaptorChannel();
39 def test_database_channel():
40 print "adChannel " + adChannel.description() + "\n";
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";
54 def test_adaptor_data_source():
55 adaptor = adChannel.adaptorContext().adaptor();
56 dict = NSMutableDictionary();
57 dict["login"] = "jan_1";
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";
66 dataSource = EOAdaptorDataSource(adChannel);
67 hints = NSMutableDictionary();
68 pks = NSMutableArray();
69 pks.addObject("company_id");
70 hints.setObjectForKey(pks, "EOPrimaryKeyAttributeNamesHint")
72 fetchSpec = EOFetchSpecification();
73 fetchSpec.setEntityName("company");
74 fetchSpec.setHints(hints);
76 dataSource.setFetchSpecification(fetchSpec);
77 print "-------------------- {insert ---------------------\n";
78 dataSource.insertObject(dict);
79 print "-------------------- insert} ---------------------\n";
81 print "-------------------- {select with hints ---------------------\n";
82 qualifier = EOQualifier("login = %@", ("jan_1", ))
83 fetchSpec = EOFetchSpecification();
84 fetchSpec.setQualifier(qualifier);
85 fetchSpec.setEntityName("company");
87 hints = NSMutableDictionary();
88 pks.addObject("company_id");
89 hints.setObjectForKey(NSTimeZone('MET'), "EOFetchResultTimeZoneHint")
90 fetchSpec.setHints(hints);
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();
100 print "-------------------- select} ---------------------\n";
103 print "-------------------- {update ---------------------\n";
105 obj["login"] = "jan_1_1";
106 obj["middlename"] = EONull();
107 dataSource.updateObject(obj);
108 print "-------------------- update} ---------------------\n";
110 qualifier = EOQualifier("login caseInsensitiveLike %@", ("jan_1_*", ))
111 fetchSpec.setQualifier(qualifier);
112 dataSource.setFetchSpecification(fetchSpec);
114 print "-------------------- {select ---------------------\n";
115 objs = dataSource.fetchObjects();
117 print "-------------------- select} ---------------------\n";
119 print "-------------------- {delete ---------------------\n";
121 dataSource.deleteObject(obj);
122 print "-------------------- delete} ---------------------\n";
124 print "-------------------- {select ---------------------\n";
125 objs = dataSource.fetchObjects();
127 print "-------------------- select} ---------------------\n";
130 def test_cascaded_datasources():
132 adaptor = adChannel.adaptorContext().adaptor();
133 dict = NSMutableDictionary();
134 dict["login"] = "jan_1";
136 dict["firstname"] = "jan";
137 dict["is_person"] = 1;
138 dict["number"] = "12345_1";
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")
155 fetchSpec.setHints(hints);
157 dataSource.setFetchSpecification(fetchSpec);
158 cacheDataSource = EOCacheDataSource(dataSource);
159 objs = dataSource.fetchObjects();
161 print cacheDataSource.fetchObjects();
162 print "-----------------------------\n";
163 print cacheDataSource.fetchObjects();
164 dataSource.insertObject(dict);
165 print "++++++++++++++++++++++++++++\n";
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();
178 print "-----------------------------\n";
179 print cacheDataSource.deleteObject(obj);
180 print "++++++++++++++++++++++++++++\n";
181 print cacheDataSource.fetchObjects();
183 def echo_logins(objs):
187 def test_sort_datasource():
188 dataSource = EOAdaptorDataSource(adChannel);
190 fetchSpec = EOFetchSpecification();
191 fetchSpec.setEntityName("company");
192 qualifier = EOQualifier("login like %@", ("%a%", ))
193 fetchSpec.setQualifier(qualifier);
195 dataSource.setFetchSpecification(fetchSpec);
196 echo_logins(dataSource.fetchObjects());
198 sortOrderings = NSMutableArray();
199 sO = EOSortOrdering("login", "compareDescending:");
200 sortOrderings.addObject(sO);
201 fetchSpec.setSortOrderings(sortOrderings);
202 dataSource.setFetchSpecification(fetchSpec);
204 echo_logins(dataSource.fetchObjects());
206 print resource.getrlimit(resource.RLIMIT_CORE);
207 if adChannel.openChannel():
208 print "open channel ok";
210 print "open channel failed";
212 print "adChannel ", adChannel;
215 #test_database_channel();
216 test_adaptor_data_source();
217 #test_cascaded_datasources();
218 #test_sort_datasource();