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
26 connect_function
= None
27 IntegrityError_exp
= None
28 ProgrammingError_exp
= None
29 DatabaseError_exp
= None
30 InternalError_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
53 def __init__(self
, user
, password
, database
, table_prefix
= ''):
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
72 def execute_query(self
, query
):
73 print "[DBOracle] I run Oracle query", query
, "\n"
75 self
.db_cursor
.execute(query
)
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
)