psql.py
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import psycopg2
class BaseDatos():
def __init__(self):
self.HOST = "127.0.0.1" #"192.168.10.59"
self.PORT = 5432
self.USER = "administrador"
self.PASS = "administrador"
self.DB = "isvareporte"
self.SELECT = ""
def __conectarr__(self):
self.conn = psycopg2.connect(host=self.HOST, port=self.PORT,
database=self.DB, user=self.USER, password=self.PASS)
self.cur = self.conn.cursor()
self.resultado = ""
def __desconectar__(self):
self.conn.close()
self.cur.close()
def __leer__(self):
self.cur.execute(self.SELECT)
self.resultado = self.cur.fetchall()
def __ValidarComando__(self):
i = True
select = self.SELECT.split(" ")
for palabra in select:
if palabra == "DROP":
i = False
if palabra == "UPDATE":
i = False
if palabra == "INCERT":
i = False
if palabra == "drop":
i = False
if palabra == "update":
i = False
if palabra == "incert":
i = False
return(i)
def Leer(self):
if self.__ValidarComando__():
self.__conectarr__()
self.__leer__()
self.__desconectar__()