Guest User

Untitled

a guest
Dec 7th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import MySQLdb
  2.  
  3.  
  4. class Database:
  5.  
  6. host = 'localhost'
  7. user = 'root'
  8. password = ''
  9. db = 'watcherservice'
  10.  
  11. def __init__(self):
  12. self.connection = MySQLdb.connect(self.host, self.user, self.password, self.db)
  13. self.cursor = self.connection.cursor()
  14.  
  15. def insert(self, query):
  16. try:
  17. self.cursor.execute(query)
  18. self.connection.commit()
  19. except:
  20. self.connection.rollback()
  21.  
  22.  
  23.  
  24. def query(self, query):
  25. cursor = self.connection.cursor( MySQLdb.cursors.DictCursor )
  26. cursor.execute(query)
  27.  
  28. return cursor.fetchall()
  29.  
  30. def __del__(self):
  31. self.connection.close()
  32.  
  33.  
  34. if __name__ == "__main__":
  35.  
  36. db = Database()
  37.  
  38. CREATE TABLE IF NOT EXISTS `detalles` (
  39. `id` int(11) NOT NULL AUTO_INCREMENT,
  40. `fecha` date NOT NULL,
  41. `hora` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  42. `archivos_movidos` int(11) NOT NULL,
  43. `estado` text NOT NULL,
  44. PRIMARY KEY (`id`)
  45. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Add Comment
Please, Sign In to add comment