Finalizado la primera version del wrapper de Mysql. Empezado a trabajar en el cuerpo del explorer
This commit is contained in:
parent
0278ea68a0
commit
b1b7de13f8
6 changed files with 125 additions and 15 deletions
2
core/__init__.py
Normal file
2
core/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
BIN
core/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
core/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
core/__pycache__/mysql_wrapper.cpython-36.pyc
Normal file
BIN
core/__pycache__/mysql_wrapper.cpython-36.pyc
Normal file
Binary file not shown.
|
|
@ -1,32 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Contiene las clases necesarias para conectar con la Base de Datos mysql.
|
||||
#
|
||||
# =============================================================================
|
||||
|
||||
import mysql.connector
|
||||
|
||||
anuncios_db_parameters = {'host': '46.183.115.154',
|
||||
'database': 'anuncios',
|
||||
'user': 'pablo',
|
||||
'password': 'noesfacilvivirsinpin'}
|
||||
|
||||
class DatabaseInstance():
|
||||
|
||||
class DatabaseWrapper():
|
||||
|
||||
def __init__(self, connection_parameters):
|
||||
self.host = connection_parameters['host']
|
||||
self.database = connection_parameters['database']
|
||||
self.user = connection_parameters['user']
|
||||
self.password = connection_parameters['password']
|
||||
|
||||
self.connection = None
|
||||
|
||||
self.ping()
|
||||
|
||||
def connect(self):
|
||||
try:
|
||||
self.connection = mysql.connector.connect(host = self.host,
|
||||
database = self.database,
|
||||
user = self.user,
|
||||
password = self.password)
|
||||
except Error as e:
|
||||
except Exception as e:
|
||||
print("Could not connect to the database.")
|
||||
print(e)
|
||||
|
||||
|
|
@ -40,9 +37,20 @@ class DatabaseInstance():
|
|||
self.connect()
|
||||
self.disconnect()
|
||||
|
||||
def query(self, query, parameters):
|
||||
def query(self, query_statement, query_parameters = None, dictionary = False):
|
||||
self.connect()
|
||||
if self.connection.is_connected():
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute()
|
||||
#SEGUIR AQUIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
|
||||
execution_cursor = self.connection.cursor(dictionary = dictionary)
|
||||
execution_cursor.execute(query_statement, query_parameters)
|
||||
self.disconnect()
|
||||
return execution_cursor
|
||||
|
||||
|
||||
def query_dict(self, query_statement, query_parameters = None):
|
||||
return self.query(query_statement, query_parameters, dictionary = True)
|
||||
|
||||
def get_anunciosdb():
|
||||
return DatabaseWrapper(anuncios_db_parameters)
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue