diff options
Diffstat (limited to 'day9/task5/database.py')
| -rw-r--r-- | day9/task5/database.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/day9/task5/database.py b/day9/task5/database.py index 067c481..9b958b7 100644 --- a/day9/task5/database.py +++ b/day9/task5/database.py @@ -1,7 +1,19 @@ import MySQLdb from config import * +import logging + +def db_column_names(): + cursor = db.cursor() + cursor.execute('DESCRIBE table_task1;') + table_structure = cursor.fetchall() + table_headers = [field[0] for field in table_structure] + return table_headers + + +logger = logging.getLogger('tableApp') +logger.info(f'Trying to connect to database "{DATABASE_NAME}@{HOST}"...') # В файле config.py создайте соответствующие переменные db = MySQLdb.connect( host=HOST, @@ -9,7 +21,9 @@ db = MySQLdb.connect( passwd=PASSWORD, db=DATABASE_NAME ) +logger.info('Connected') +logger.info(f'Preparing table "table_task1"...') db.cursor().execute( ''' CREATE TABLE IF NOT EXISTS `table_task1` ( @@ -26,4 +40,4 @@ db.cursor().execute( PRIMARY KEY (`service_id`) ) ENGINE=InnoDB AUTO_INCREMENT=35109400 DEFAULT CHARSET=utf8; ''' -)
\ No newline at end of file +) |