Merge branch 'master' of ssh://lausser,shinken@shinken.git.sourceforge.net/gitroot...
[shinken.git] / shinken / db_oracle.py
blob4f815a900126240b41d1bb4c85b0e919b5368302
1 #!/usr/bin/env python
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
24 #DBMysql is a MySQL access database class
25 from shinken.db import DB
27 connect_function = None
28 IntegrityError_exp = None
29 ProgrammingError_exp = None
30 DatabaseError_exp = None
31 InternalError_exp = None
32 DataError_exp = None
33 OperationalError_exp = None
36 #Failed to import will be catch by __init__.py
37 from cx_Oracle import connect as connect_function
38 from cx_Oracle import IntegrityError as IntegrityError_exp
39 from cx_Oracle import ProgrammingError as ProgrammingError_exp
40 from cx_Oracle import DatabaseError as DatabaseError_exp
41 from cx_Oracle import InternalError as InternalError_exp
42 from cx_Oracle import DataError as DataError_exp
43 from cx_Oracle import OperationalError as OperationalError_exp
46 class DBOracle(DB):
47 def __init__(self, user, password, database, table_prefix = ''):
48 self.user = user
49 self.password = password
50 self.database = database
51 self.table_prefix = table_prefix
54 #Create the database connexion
55 #TODO : finish (begin :) ) error catch and conf parameters...
56 def connect_database(self):
57 connstr='%s/%s@%s' % (self.user, self.password, self.database)
59 self.db = connect_function(connstr)
60 self.db_cursor = self.db.cursor()
61 self.db_cursor.arraysize=50
64 #Just run the query
65 #TODO: finish catch
66 def execute_query(self, query):
67 print "[DBOracle] I run Oracle query", query, "\n"
68 try:
69 self.db_cursor.execute(query)
70 self.db.commit ()
71 except IntegrityError_exp , exp:
72 print "[DBOracle] Warning : a query raise an integrity error : %s, %s" % (query, exp)
73 except ProgrammingError_exp , exp:
74 print "[DBOracle] Warning : a query raise a programming error : %s, %s" % (query, exp)
75 except DatabaseError_exp , exp:
76 print "[DBOracle] Warning : a query raise a database error : %s, %s" % (query, exp)
77 except InternalError_exp , exp:
78 print "[DBOracle] Warning : a query raise an internal error : %s, %s" % (query, exp)
79 except DataError_exp , exp:
80 print "[DBOracle] Warning : a query raise a data error : %s, %s" % (query, exp)
81 except OperationalError_exp , exp:
82 print "[DBOracle] Warning : a query raise an operational error : %s, %s" % (query, exp)
83 except Exception , exp:
84 print "[DBOracle] Warning : a query raise an unknow error : %s, %s" % (query, exp)
85 print exp.__dict__