0 1 1
default
Jean-Francois Pieronne - 4 years ago 2016-04-28 09:12:53
jf.pieronne@laposte.net
Add sequences informations
2 files changed with 82 insertions and 0 deletions:
↑ Collapse Diff ↑
...
 
@@ -16,6 +16,7 @@ import rdb.Trigger
16 16
 
import rdb.Table
17 17
 
import rdb.StorageMap
18 18
 
import rdb.Constraint
19
 
import rdb.Sequence
19 20
 

	
20 21
 
class Database(object):
21 22
 
    def __init__(self, database_name = None):
...
 
@@ -78,6 +79,8 @@ class Database(object):
78 79
 
        self._partition = {}
79 80
 
        self._trigger = {}
80 81
 
        self._constraint = {}
82
 
        # Sequence store by name
83
 
        self._sequence = {}
81 84
 
        # Loading order is important and used
82 85
 
        try:
83 86
 
            self.load_root()
...
 
@@ -91,6 +94,7 @@ class Database(object):
91 94
 
        self.load_storage_maps()
92 95
 
        self.load_constraints()
93 96
 
        self.load_triggers()
97
 
        self.load_sequences()
94 98
 
        # build link from larea to table/index object
95 99
 
        for lareas in self._larea_by_id.itervalues():
96 100
 
            for larea in lareas:
...
 
@@ -260,6 +264,10 @@ from RDB$DATABASE
260 264
 
        generator = rdb.Trigger.genTrigger(self, None)
261 265
 
        for trigger in generator:
262 266
 
            self._trigger[trigger.trigger_name] = trigger
267
 
    def load_sequences(self):
268
 
        generator = rdb.Sequence.genSequence()
269
 
        for sequence in generator:
270
 
            self._sequence[sequence.sequence_name] = sequence
263 271
 
    def load_constraints(self):
264 272
 
        generator = rdb.Constraint.genConstraint(self)
265 273
 
        for constraint in generator:
...
 
@@ -322,6 +330,10 @@ from RDB$DATABASE
322 330
 
        return self._index
323 331
 
    def index(self, name):
324 332
 
        return self._index[name]
333
 
    def sequences(self):
334
 
        return self._sequence
335
 
    def sequence(self, name):
336
 
        return self._sequence[name]
325 337
 
    def triggers(self):
326 338
 
        return self._trigger
327 339
 
    def trigger(self, name):
...
 
@@ -410,3 +422,6 @@ if __name__ == '__main__':
410 422
 
    for constraint in res.constraints().itervalues():
411 423
 
        printattributes(constraint, 0)
412 424
 
        print
425
 
    for sequence in res.sequences().itervalues():
426
 
        printattributes(sequence, 0)
427
 
        print
 
new file 100755
1
 
import rdb
2
 
from rdb.utils import vmsdt2dt
3
 

	
4
 

	
5
 
class Sequence:
6
 
    def __init__(self, curs, created, last_altered, access_control, description,
7
 
                 start_value, minimum_sequence, maximum_sequence,
8
 
                 next_sequence_value, increment_value, cache_size,
9
 
                 flags, sequence_id, sequence_name, sequence_creator):
10
 
        self.created = created
11
 
        self.last_altered = last_altered
12
 
        self.access_control = access_control
13
 
        if self.access_control:
14
 
            self.access_control = \
15
 
                  rdb.fetchBlob(curs, 'RDB$ACCESS_CONTROL', True)
16
 
        self.description = description
17
 
        if self.description:
18
 
            self.description = \
19
 
                  rdb.fetchBlob(curs, 'RDB$DESCRIPTION', True)
20
 
        self.start_value = start_value
21
 
        self.minimum_sequence = minimum_sequence
22
 
        self.maximum_sequence = maximum_sequence
23
 
        self.next_sequence_value = next_sequence_value
24
 
        self.increment_value = increment_value
25
 
        self.cache_size = cache_size
26
 
        self.flags = flags
27
 
        self.sequence_id = sequence_id
28
 
        self.sequence_name = sequence_name.rstrip()
29
 
        self.sequence_creator = sequence_creator
30
 

	
31
 

	
32
 
def genSequence():
33
 
    """generator returning all sequences"""
34
 
    req = """
35
 
select
36
 
RDB$CREATED,
37
 
RDB$LAST_ALTERED,
38
 
RDB$ACCESS_CONTROL,
39
 
RDB$DESCRIPTION,
40
 
RDB$START_VALUE,
41
 
RDB$MINIMUM_SEQUENCE,
42
 
RDB$MAXIMUM_SEQUENCE,
43
 
RDB$NEXT_SEQUENCE_VALUE,
44
 
RDB$INCREMENT_VALUE,
45
 
RDB$CACHE_SIZE,
46
 
RDB$FLAGS,
47
 
RDB$SEQUENCE_ID,
48
 
RDB$SEQUENCE_NAME,
49
 
RDB$SEQUENCE_CREATOR
50
 
from RDB$SEQUENCES
51
 
"""
52
 
    curs = rdb.statement(req)
53
 
    curs.declareReadBinary('RDB$ACCESS_CONTROL')
54
 
    curs.declareReadBinary('RDB$DESCRIPTION')
55
 
    curs.execute()
56
 
    for vcurs in curs:
57
 
        yield Sequence(curs, *vcurs)
58
 
#    curs.close()
59
 

	
60
 
if __name__ == '__main__':
61
 
    from utils import printattributes
62
 
    rdb.read_only()
63
 
    generator = genSequence()
64
 
    for sequence in generator:
65
 
        printattributes(sequence, 0)
66
 
        print
67
 
    rdb.rollback()
0 comments (0 inline, 0 general)