Package backend :: Package server :: Package rhnSQL :: Module sql_sequence
[hide private]
[frames] | no frames]

Source Code for Module backend.server.rhnSQL.sql_sequence

 1  # 
 2  # Copyright (c) 2008--2015 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15  # This file implements teh Sequence class 
16  # 
17   
18  from spacewalk.common.rhnException import rhnException 
19   
20  import sql_base 
21   
22   
23  # A class to handle sequences 
24  # XXX: this is still Oracle specific, but it shouldn't be 
25 -class Sequence:
26
27 - def __init__(self, db, seq):
28 if not seq or not isinstance(seq, str): 29 raise rhnException("First argument needs to be a sequence name", seq) 30 self.__seq = seq 31 if not isinstance(db, sql_base.Database): 32 raise rhnException("Argument db is not a database instance", db) 33 self.__db = db
34
35 - def next(self):
36 sql = "select sequence_nextval('%s') as ID from dual" % self.__seq 37 cursor = self.__db.prepare(sql) 38 cursor.execute() 39 ret = cursor.fetchone_dict() 40 if ret is None: # how the hell can this happen? 41 return ret 42 return int(ret['id'])
43
44 - def __call__(self):
45 return self.next()
46
47 - def __del__(self):
48 self.__seq = self.__db = None
49