]> err.no Git - sope/blob - sope-gdl1/FrontBase2/fbtest.py
more directory hierarchy reorganisations,
[sope] / sope-gdl1 / FrontBase2 / fbtest.py
1 #!/usr/bin/env python
2 # $Id: fbtest.py 2 2004-08-20 10:48:47Z znek $
3
4 from Foundation import *
5 from eoaccess import *
6
7 conDict = { 'userName':     "skyrix",
8             'databaseName': "Skyrix",
9             'hostName':     "inster" }
10
11 adaptor = EOAdaptor(name='FrontBase2')
12 adaptor.setConnectionDictionary(conDict)
13 print "got adaptor ",  adaptor.invoke0("class");
14
15 ctx = adaptor.createAdaptorContext()
16 ch  = ctx.createAdaptorChannel()
17
18 model = EOModel(contentsOfFile='test.eomodel')
19 adaptor.setModel(model)
20 adaptor.setConnectionDictionary(conDict)
21
22 ch.setDebugEnabled(YES)
23
24 if ch.openChannel():
25     print "channel is open"
26
27     if ctx.beginTransaction():
28         print "began tx .."
29
30         pool = NSAutoreleasePool()
31         
32         e     = model.entityNamed('Person')
33         q     = e.qualifier()
34         attrs = e.attributes()
35
36         if ch.selectAttributes(attrs, q):
37             record = ch.fetchAttributes(attrs)
38             while record is not None:
39                 print "  login=%(login)s name=%(name)s bday=%(birthday)s" % \
40                       record
41                 record = ch.fetchAttributes(attrs)
42         
43         del pool
44         
45         pool = NSAutoreleasePool()
46
47         e     = model.entityNamed('Person')
48         attrs = e.attributes()
49         q     = EOKeyValueQualifier('login', EOQualifierOperatorEqual, 'helge')
50         q     = q.sqlQualifierForEntity(e)
51
52         if ch.selectAttributes(attrs, q):
53             record = ch.fetchAttributes(attrs)
54             print "  login=%(login)s name=%(name)s bday=%(birthday)s" % \
55                   record
56             ch.cancelFetch()
57
58         date = NSCalendarDate()
59         print "date in localtime:", date
60         date.setTimeZone(NSTimeZone("PST"))
61         print "date in pacific time:", date
62         
63         record['birthday'] = date
64         print "  login=%(login)s name=%(name)s bday=%(birthday)s" % record
65         
66         if ch.updateRow(record, q):
67             print "did update .."
68         else:
69             print "update failed .."
70
71         if ch.selectAttributes(attrs, q):
72             nrecord = ch.fetchAttributes(attrs)
73             print "  login=%(login)s name=%(name)s bday=%(birthday)s" % \
74                   nrecord
75             print nrecord['birthday'].__class__
76             ch.cancelFetch()
77         
78         del pool
79
80         ctx.rollbackTransaction()
81     else:
82         print "couldn't begin tx."
83
84     ch.closeChannel()
85 else:
86     print "couldn't open channel."
87