Changeset 115:e06c6a33bd33 in livinglogic.python.orasql

Show
Ignore:
Timestamp:
05/17/06 15:46:19 (13 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Make sequence values copyable.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • NEWS.xml

    r108 r115  
    1010and <class>LLProc</class>. Error messages for calling procedures 
    1111have been enhanced.</item> 
     12<item><class>SequenceDefinition</class> now has a new method 
     13<method>createddlcopy</method> that return copy that copies the 
     14sequence value. <filename>oracreate.py</filename> has a new 
     15option <option>-s</option>/<option>--seqcopy</option> that 
     16uses this feature.</item> 
    1217</ulist> 
    1318</section> 
  • orasql.py

    r111 r115  
    4040from cx_Oracle import * 
    4141 
    42 from ll import misc 
     42from ll import misc, astyle 
    4343 
    4444# ipipe support 
     
    245245 
    246246    def __xrepr__(self, mode): 
     247        yield (-1, True) 
    247248        if mode == "header": 
    248             return "%s.%s" % (self.__class__.__module__, self.__class__.__name__) 
    249         return repr(self) 
     249            yield (astyle.style_default, "%s.%s" % (self.__class__.__module__, self.__class__.__name__)) 
     250        else: 
     251            yield (astyle.style_default, repr(self)) 
    250252 
    251253    def __repr__(self): 
     
    264266 
    265267    def __xrepr__(self, mode): 
     268        yield (-1, True) 
    266269        if mode == "header" or mode == "footer": 
    267             return self.type + "s" 
    268         return repr(self) 
     270            yield (astyle.style_default, self.type + "s") 
     271        else: 
     272            yield (astyle.style_default, repr(self)) 
    269273 
    270274    def __iter__(self): 
     
    308312 
    309313    def __xrepr__(self, mode): 
     314        yield (-1, True) 
    310315        if mode == "header" or mode=="footer": 
    311             return "oracle connection to %s" % self.connectstring() 
    312         return repr(self) 
     316            yield (astyle.style_default, "oracle connection to %s" % self.connectstring()) 
     317        else: 
     318            yield (astyle.style_default, repr(self)) 
    313319 
    314320    def __xiter__(self, mode): 
     
    498504 
    499505    def __xrepr__(self, mode): 
     506        yield (-1, True) 
    500507        if mode == "header" or mode == "footer": 
    501508            if self.statement: 
    502                 return self.statement 
     509                yield (astyle.style_default, self.statement) 
    503510            else: 
    504                 return "no statement" 
    505         return repr(self) 
     511                yield (astyle.style_default, "no statement") 
     512        else: 
     513            yield (astyle.style_default, repr(self)) 
    506514 
    507515    def __repr__(self): 
     
    722730    type = "sequence" 
    723731 
    724     def createddl(self, cursor=None, term=True): 
     732    def _createddl(self, cursor, term, copyvalue): 
    725733        cursor = self.getcursor(cursor) 
    726734        cursor.execute("select * from all_sequences where sequence_owner=nvl(:owner, user) and sequence_name=:name", owner=self.owner, name=self.name) 
     
    733741            code  = "create sequence %s\n" % rec.sequence_name 
    734742        code += "\tincrement by %d\n" % rec.increment_by 
    735         code += "\tstart with %d\n" % rec.min_value 
     743        if copyvalue: 
     744            code += "\tstart with %d\n" % (rec.last_number + rec.increment_by) 
     745        else: 
     746            code += "\tstart with %d\n" % rec.min_value 
    736747        code += "\tmaxvalue %s\n" % rec.max_value 
    737748        code += "\tminvalue %d\n" % rec.min_value 
     
    748759        return code 
    749760 
     761    def createddl(self, cursor=None, term=True): 
     762        return self._createddl(cursor, term, False) 
     763 
     764    def createddlcopy(self, cursor=None, term=True): 
     765        return self._createddl(cursor, term, True) 
     766 
    750767    def dropddl(self, cursor=None, term=True): 
    751768        if self.owner is not None: 
     
    758775            code += "\n" 
    759776        return code 
     777 
     778    def __xiter__(self, mode): 
     779        if mode is None: 
     780            yield ipipe.XMode(self, "create", "create statement", "the SQL script to create this sequence") 
     781            yield ipipe.XMode(self, "createcopy", "create statement (exact copy)", "the SQL script to create this sequence (using the current value as the start value)") 
     782            yield ipipe.XMode(self, "drop", "drop statement", "the SQL script to drop this sequence") 
     783            yield ipipe.XMode(self, "referencedbyown", "referenced by own", "other objects (in this schema) depending on this sequence") 
     784            yield ipipe.XMode(self, "referencedbydep", "referenced by all", "all other objects depending on this sequence") 
     785            yield ipipe.XMode(self, "referencesown", "references own", "other objects (in this schema) on which this sequence depends") 
     786            yield ipipe.XMode(self, "referencesdep", "references all", "all other objects on which this sequence depends") 
     787        elif mode == "referencedbyown": 
     788            for item in self.iterdependent(mode="drop", schema="own"): 
     789                yield item 
     790        elif mode == "referencedbydep": 
     791            for item in self.iterdependent(mode="drop", schema="dep"): 
     792                yield item 
     793        elif mode == "referencesown": 
     794            for item in self.iterdependent(mode="create", schema="own"): 
     795                yield item 
     796        elif mode == "referencesdep": 
     797            for item in self.iterdependent(mode="create", schema="dep"): 
     798                yield item 
     799        elif mode == "drop": 
     800            for item in self.dropddl().splitlines(): 
     801                yield item 
     802        elif mode == "createcopy": 
     803            for item in self.createddlcopy().splitlines(): 
     804                yield item 
     805        else: 
     806            for item in self.createddl().splitlines(): 
     807                yield item 
    760808 
    761809 
  • scripts/oracreate.py

    r113 r115  
    2626    p.add_option("-v", "--verbose", dest="verbose", help="Give a progress report?", default=False, action="store_true") 
    2727    p.add_option("-c", "--color", dest="color", help="Color output (%s)" % ", ".join(colors), default="auto", choices=colors) 
     28    p.add_option("-s", "--seqcopy", dest="seqcopy", help="copy sequence values?", default=False, action="store_true") 
    2829    p.add_option("-x", "--execute", metavar="CONNECTSTRING2", dest="execute", help="Execute in target database", type="str") 
    2930    p.add_option("-k", "--keepdollar", dest="keepdollar", help="Output objects with '$' in their name?", default=False, action="store_true") 
     
    7071            stderr.writeln(msg) 
    7172        if keep: 
    72             ddl = definition.createddl(cursor, term) 
     73            if isinstance(definition, orasql.SequenceDefinition) and options.seqcopy: 
     74                ddl = definition.createddlcopy(cursor, term) 
     75            else: 
     76                ddl = definition.createddl(cursor, term) 
    7377            if ddl: 
    7478                if options.execute: