def unnest_block(self, block, depth=0): ln=0 #depth= self._depth m = re.findall(r'(BEGIN(?:(?!BEGIN|END\;).)*END\;)',block, re.S) if m: ln=len(m) if ln>0: self._logger.debug('Got %d nested blocks.' % len(m)) if depth not in self._obj.keys(): self._obj[depth] = {} bid=0 for nb in m: if nb in block: pos = block.find(nb) self._logger.debug('Confirmed nested block at position %d.' % pos ) #marker = 'NESTED_BLOCK[%d:%d]' % (depth,bid) map_id = self.get_map_id('NESTED_BLOCK',depth,bid) print map_id block = block[:pos] + map_id + block[(pos+len(nb)):] (status, nb_stub) = self.get_block_stub(nb) pprint(nb_stub) #sys.exit(1) #nbo=PL_SQL_AnonBlock({'nested_block':nb,'block':block},self._logger) nbo=PL_SQL_AnonBlock(nb_stub,self._logger) nbo.parse_src(depth+1) self._obj[depth][map_id]=(pos,nb,nbo) self.add_map((map_id,nbo)) bid +=1 else: self._logger.debug('Cannot find match nested block %s found in %s.' % (nb,self._type)) sys.exit(1) #print block else: self._logger.debug('No nested blocks found for depth %d.' % depth) return (ln,block)
def __init__(self, stub,logger): """Generic PL/SQL block """ PL_SQL_AnonBlock.__init__(self, stub,logger) self._type='NAMED_BLOCK' self._block=None self._block_body=None self._declare={} self._exception=None # 0- src, 1- obj self._exc_obj=None self._exc_src=None #self._logger=logger self._block_stub=None self._unnested_block=None if self._stub.has_key('named_block'): self._src=self._stub['named_block'] #self.__nb=[] #nested block objects #self._obj={} #nested blocks #self._map={} #parsed objects' map self._preblock=None self._postblock=None self._eq ={} #execution queue self._seg=None