Пример #1
0
    def __init__(self, name):
        """Define initial relvars and their initial values here
           (Called once on database creation)"""
        Database.__init__(self, name)

        if 'S' not in self:
            print "Adding S..."
            self.S = Relation(['S#', 'SNAME', 'STATUS', 'CITY'], [
                ('S1', 'Smith', 20, 'London'),
                ('S2', 'Jones', 10, 'Paris'),
                ('S3', 'Blake', 30, 'Paris'),
                ('S4', 'Clark', 20, 'London'),
                ('S5', 'Adams', 30, 'Athens'),
            ], {'pk': (Key, ['S#'])})

        if 'P' not in self:
            print "Adding P..."
            self.P = Relation(['P#', 'PNAME', 'COLOR', 'WEIGHT', 'CITY'], [
                ('P1', 'Nut', 'Red', 12, 'London'),
                ('P2', 'Bolt', 'Green', 17, 'Paris'),
                ('P3', 'Screw', 'Blue', 17, 'Rome'),
                ('P4', 'Screw', 'Red', 14, 'London'),
                ('P5', 'Cam', 'Blue', 12, 'Paris'),
                ('P6', 'Cog', 'Red', 19, 'London'),
            ], {'pk': (Key, ['P#'])})

        if 'SP' not in self:
            print "Adding SP..."
            self.SP = Relation(
                ['S#', 'P#', 'QTY'], [
                    ('S1', 'P1', 300),
                    ('S1', 'P2', 200),
                    ('S1', 'P3', 400),
                    ('S1', 'P4', 200),
                    ('S1', 'P5', 100),
                    ('S1', 'P6', 100),
                    ('S2', 'P1', 300),
                    ('S2', 'P2', 400),
                    ('S3', 'P2', 200),
                    ('S4', 'P2', 200),
                    ('S4', 'P4', 300),
                    ('S4', 'P5', 400),
                ], {
                    'pk': (Key, ['S#', 'P#']),
                    'fkS': (ForeignKey, ('S', {
                        'S#': 'S#'
                    })),
                    'fkP': (ForeignKey, ('P', {
                        'P#': 'P#'
                    })),
                })
Пример #2
0
    def __init__(self, name):
        """Define initial relvars and their initial values here
           (Called once on database creation)"""
        Database.__init__(self, name)

        if 'IS_CALLED' not in self:
            print "Adding IS_CALLED..."
            self.IS_CALLED = Relation(['StudentId', 'Name'], [
                ('S1', 'Anne'),
                ('S2', 'Boris'),
                ('S3', 'Cindy'),
                ('S4', 'Devinder'),
                ('S5', 'Boris'),
            ])

        if 'IS_ENROLLED_ON' not in self:
            print "Adding IS_ENROLLED_ON..."
            self.IS_ENROLLED_ON = Relation(['StudentId', 'CourseId'], [
                ('S1', 'C1'),
                ('S1', 'C2'),
                ('S2', 'C1'),
                ('S3', 'C3'),
                ('S4', 'C1'),
            ])

        if 'COURSE' not in self:
            print "Adding COURSE..."
            self.COURSE = Relation(['CourseId', 'Title'], [
                ('C1', 'Database'),
                ('C2', 'HCI'),
                ('C3', 'Op Systems'),
                ('C4', 'Programming'),
            ])

        if 'EXAM_MARK' not in self:
            print "Adding EXAM_MARK..."
            self.EXAM_MARK = Relation(['StudentId', 'CourseId', 'Mark'], [
                ('S1', 'C1', 85),
                ('S1', 'C2', 49),
                ('S2', 'C1', 49),
                ('S3', 'C3', 66),
                ('S4', 'C1', 93),
            ])
Пример #3
0
    def __init__(self, name="nemo"):
        """Create a Cluster

           Define initial databases here
           (Called once on cluster creation)
        """
        dict.__init__(self)

        self.name = name

        self.databases = Relation(['database_name'], self.vdatabases)
Пример #4
0
    def _vinit(self):
        """Define virtual relvars/relconsts
           (Called repeatedly, e.g. after database load from disk or commit)
        """
        Database._vinit(self)

        if 'C_ER' not in self:
            print "Defining C_ER..."
            #this will always be the case, even when re-loading: we don't store relations with callable bodies
            self.C_ER = Relation(['CourseId', 'Exam_Result'], self.vC_ER,
                                 {'pk': (Key, ['CourseId'])})
Пример #5
0
    def __init__(self, name):
        """Define initial relvars and their initial values here
           (Called once on database creation)"""
        Database.__init__(self, name)

        if 'IS_CALLED' not in self:
            print "Adding IS_CALLED..."
            self.IS_CALLED = Relation(['StudentId', 'Name'],
                                 [('S1', 'Anne'),
                                  ('S2', 'Boris'),
                                  ('S3', 'Cindy'),
                                  ('S4', 'Devinder'),
                                  ('S5', 'Boris'),
                                 ]
                                )

        if 'IS_ENROLLED_ON' not in self:
            print "Adding IS_ENROLLED_ON..."
            self.IS_ENROLLED_ON = Relation(['StudentId', 'CourseId'],
                                     [('S1', 'C1'),
                                      ('S1', 'C2'),
                                      ('S2', 'C1'),
                                      ('S3', 'C3'),
                                      ('S4', 'C1'),
                                     ]
                                    )

        if 'COURSE' not in self:
            print "Adding COURSE..."
            self.COURSE = Relation(['CourseId', 'Title'],
                              [('C1', 'Database'),
                               ('C2', 'HCI'),
                               ('C3', 'Op Systems'),
                               ('C4', 'Programming'),
                              ]
                             )

        if 'EXAM_MARK' not in self:
            print "Adding EXAM_MARK..."
            self.EXAM_MARK = Relation(['StudentId', 'CourseId', 'Mark'],
                                 [('S1', 'C1', 85),
                                  ('S1', 'C2', 49),
                                  ('S2', 'C1', 49),
                                  ('S3', 'C3', 66),
                                  ('S4', 'C1', 93),
                                 ]
                                )
Пример #6
0
class darwen_Database(Database):
    def __init__(self, name):
        """Define initial relvars and their initial values here
           (Called once on database creation)"""
        Database.__init__(self, name)

        if 'IS_CALLED' not in self:
            print "Adding IS_CALLED..."
            self.IS_CALLED = Relation(['StudentId', 'Name'],
                                 [('S1', 'Anne'),
                                  ('S2', 'Boris'),
                                  ('S3', 'Cindy'),
                                  ('S4', 'Devinder'),
                                  ('S5', 'Boris'),
                                 ]
                                )

        if 'IS_ENROLLED_ON' not in self:
            print "Adding IS_ENROLLED_ON..."
            self.IS_ENROLLED_ON = Relation(['StudentId', 'CourseId'],
                                     [('S1', 'C1'),
                                      ('S1', 'C2'),
                                      ('S2', 'C1'),
                                      ('S3', 'C3'),
                                      ('S4', 'C1'),
                                     ]
                                    )

        if 'COURSE' not in self:
            print "Adding COURSE..."
            self.COURSE = Relation(['CourseId', 'Title'],
                              [('C1', 'Database'),
                               ('C2', 'HCI'),
                               ('C3', 'Op Systems'),
                               ('C4', 'Programming'),
                              ]
                             )

        if 'EXAM_MARK' not in self:
            print "Adding EXAM_MARK..."
            self.EXAM_MARK = Relation(['StudentId', 'CourseId', 'Mark'],
                                 [('S1', 'C1', 85),
                                  ('S1', 'C2', 49),
                                  ('S2', 'C1', 49),
                                  ('S3', 'C3', 66),
                                  ('S4', 'C1', 93),
                                 ]
                                )

    def _vinit(self):
        """Define virtual relvars/relconsts
           (Called repeatedly, e.g. after database load from disk or commit)
        """
        Database._vinit(self)

        if 'C_ER' not in self:
            print "Defining C_ER..."
            #this will always be the case, even when re-loading: we don't store relations with callable bodies
            self.C_ER = Relation(['CourseId', 'Exam_Result'],
                                           self.vC_ER,
                                           {'pk':(Key,['CourseId'])})

    def vC_ER(self):
        return self.COURSE.extend(['Exam_Result'], lambda t:{'Exam_Result':
                                                             (self.EXAM_MARK & GENERATE({'CourseId':t.CourseId})
                                                             )(['StudentId', 'Mark'])}
                                 )(['CourseId', 'Exam_Result']) #fixed
Пример #7
0
class darwen_Database(Database):
    def __init__(self, name):
        """Define initial relvars and their initial values here
           (Called once on database creation)"""
        Database.__init__(self, name)

        if 'IS_CALLED' not in self:
            print "Adding IS_CALLED..."
            self.IS_CALLED = Relation(['StudentId', 'Name'], [
                ('S1', 'Anne'),
                ('S2', 'Boris'),
                ('S3', 'Cindy'),
                ('S4', 'Devinder'),
                ('S5', 'Boris'),
            ])

        if 'IS_ENROLLED_ON' not in self:
            print "Adding IS_ENROLLED_ON..."
            self.IS_ENROLLED_ON = Relation(['StudentId', 'CourseId'], [
                ('S1', 'C1'),
                ('S1', 'C2'),
                ('S2', 'C1'),
                ('S3', 'C3'),
                ('S4', 'C1'),
            ])

        if 'COURSE' not in self:
            print "Adding COURSE..."
            self.COURSE = Relation(['CourseId', 'Title'], [
                ('C1', 'Database'),
                ('C2', 'HCI'),
                ('C3', 'Op Systems'),
                ('C4', 'Programming'),
            ])

        if 'EXAM_MARK' not in self:
            print "Adding EXAM_MARK..."
            self.EXAM_MARK = Relation(['StudentId', 'CourseId', 'Mark'], [
                ('S1', 'C1', 85),
                ('S1', 'C2', 49),
                ('S2', 'C1', 49),
                ('S3', 'C3', 66),
                ('S4', 'C1', 93),
            ])

    def _vinit(self):
        """Define virtual relvars/relconsts
           (Called repeatedly, e.g. after database load from disk or commit)
        """
        Database._vinit(self)

        if 'C_ER' not in self:
            print "Defining C_ER..."
            #this will always be the case, even when re-loading: we don't store relations with callable bodies
            self.C_ER = Relation(['CourseId', 'Exam_Result'], self.vC_ER,
                                 {'pk': (Key, ['CourseId'])})

    def vC_ER(self):
        return self.COURSE.extend(
            ['Exam_Result'], lambda t: {
                'Exam_Result':
                (self.EXAM_MARK & GENERATE({'CourseId': t.CourseId}))
                (['StudentId', 'Mark'])
            })(['CourseId', 'Exam_Result'])  #fixed