Add : the full demoCA certification autority so people can sign their own keys.
[shinken.git] / shinken / db_oracle.py
blob9866cad4738e20db53a8dedfa67db3e574b7fa8f
1 #!/usr/bin/env python
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
8 #Shinken is free software: you can redistribute it and/or modify
9 #it under the terms of the GNU Affero General Public License as published by
10 #the Free Software Foundation, either version 3 of the License, or
11 #(at your option) any later version.
13 #Shinken is distributed in the hope that it will be useful,
14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #GNU Affero General Public License for more details.
18 #You should have received a copy of the GNU Affero General Public License
19 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
22 #DBMysql is a MySQL access database class
23 from db import DB
26 connect_function = None
27 IntegrityError_exp = None
28 ProgrammingError_exp = None
29 DatabaseError_exp = None
30 InternalError_exp = None
31 DataError_exp = None
32 OperationalError_exp = None
35 #Failed to import will be catch by __init__.py
36 from cx_Oracle import connect
37 connect_function = connect
38 from cx_Oracle import IntegrityError
39 IntegrityError_exp = IntegrityError
40 from cx_Oracle import ProgrammingError
41 ProgrammingError_exp = ProgrammingError
42 from cx_Oracle import DatabaseError
43 DatabaseError_exp = DatabaseError
44 from cx_Oracle import InternalError
45 InternalError_exp = InternalError
46 from cx_Oracle import DataError
47 DataError_exp = DataError
48 from cx_Oracle import OperationalError
49 OperationalError_exp = OperationalError
52 class DBOracle(DB):
53 def __init__(self, user, password, database, table_prefix = ''):
54 self.user = user
55 self.password = password
56 self.database = database
57 self.table_prefix = table_prefix
60 #Create the database connexion
61 #TODO : finish (begin :) ) error catch and conf parameters...
62 def connect_database(self):
63 connstr='%s/%s@%s' % (self.user, self.password, self.database)
65 self.db = connect_function(connstr)
66 self.db_cursor = self.db.cursor()
67 self.db_cursor.arraysize=50
70 #Just run the query
71 #TODO: finish catch
72 def execute_query(self, query):
73 print "[DBOracle] I run Oracle query", query, "\n"
74 try:
75 self.db_cursor.execute(query)
76 self.db.commit ()
77 except IntegrityError_exp , exp:
78 print "[DBOracle] Warning : a query raise an integrity error : %s, %s" % (query, exp)
79 except ProgrammingError_exp , exp:
80 print "[DBOracle] Warning : a query raise a programming error : %s, %s" % (query, exp)
81 except DatabaseError_exp , exp:
82 print "[DBOracle] Warning : a query raise a database error : %s, %s" % (query, exp)
83 except InternalError_exp , exp:
84 print "[DBOracle] Warning : a query raise an internal error : %s, %s" % (query, exp)
85 except DataError_exp , exp:
86 print "[DBOracle] Warning : a query raise a data error : %s, %s" % (query, exp)
87 except OperationalError_exp , exp:
88 print "[DBOracle] Warning : a query raise an operational error : %s, %s" % (query, exp)
89 except Exception , exp:
90 print "[DBOracle] Warning : a query raise an unknow error : %s, %s" % (query, exp)
91 print exp.__dict__