Example #1
0
def main():
    try:
        database = DatabaseConnector(config.USER, config.PASSWORD, config.HOST,
                                     config.DATABASE)
        mysql_connect = database.mysql_open_connection()
        sql = (
            'SELECT article_id, title, received_date FROM article WHERE received_date BETWEEN %s AND %s'
        )
        received_date_start = datetime.date(2008, 1, 4)
        received_date_end = datetime.date(2008, 3, 5)
        paremeters = (received_date_start, received_date_end)
        cursor, data = database.mysql_execute_cursor_select(
            mysql_connect, sql, paremeters)
        if cursor.rowcount > 0:
            for row in data:
                print(row[ArticleColumn.article_id.value],
                      row[ArticleColumn.title.value],
                      row[ArticleColumn.received_date.value],
                      sep='\t')
    except:
        exception_message = sys.exc_info()[0]
        print("An error occurred. {}".format(exception_message))
    finally:
        database.mysql_close_cursor(cursor)
        database.mysql_close_connection(mysql_connect)
Example #2
0
def main():
    try:
        database = DatabaseConnector(config.USER, config.PASSWORD, config.HOST,
                                     config.DATABASE)
        mysql_connect = database.mysql_open_connection()
        sql = ('DELETE FROM magazine_type WHERE magazine_type_id = %s')
        paremeters = (9, )
        database.mysql_execute_cursor_update(mysql_connect, sql, paremeters)
    except:
        exception_message = sys.exc_info()[0]
        print("An error occurred. {}".format(exception_message))
    finally:
        database.mysql_close_connection(mysql_connect)
Example #3
0
def main():
    try:
        database = DatabaseConnector(config.USER, config.PASSWORD, config.HOST,
                                     config.DATABASE)
        mysql_connect = database.mysql_open_connection()
        sql = (
            'INSERT INTO magazine_type (type, description, notes, update_id) VALUES (%s, %s, %s, %s)'
        )
        paremeters = ('Lunix', 'The Lunix Magazine', 'The Notes', 300)
        database.mysql_execute_cursor_update(mysql_connect, sql, paremeters)
    except:
        exception_message = sys.exc_info()[0]
        print("An error occurred. {}".format(exception_message))
    finally:
        database.mysql_close_connection(mysql_connect)
Example #4
0
def main():
    try:
        database = DatabaseConnector(config.USER, config.PASSWORD, config.HOST,
                                     config.DATABASE)
        mysql_connect = database.mysql_open_connection()
        sql = (
            "UPDATE magazine_type SET type = %s , description = %s, notes = %s, update_id = %s WHERE magazine_type_id = %s"
        )
        paremeters = ('Windows', 'The Windows IT Magazine', 'The Notes', 300,
                      14)
        database.mysql_execute_cursor_update(mysql_connect, sql, paremeters)
    except:
        exception_message = sys.exc_info()[0]
        print("An error occurred. {}".format(exception_message))
    finally:
        database.mysql_close_connection(mysql_connect)
Example #5
0
def main():
    try:
        database = DatabaseConnector(config.USER, config.PASSWORD, config.HOST,
                                     config.DATABASE)
        mysql_connect = database.mysql_open_connection()
        sql = (
            'SELECT author_id, first_name, last_name, middle_name FROM author WHERE last_name LIKE %s ORDER BY first_name'
        )
        paremeters = ('%w%', )
        cursor, data = database.mysql_execute_cursor_select(
            mysql_connect, sql, paremeters)
        if cursor.rowcount > 0:
            for row in data:
                print(row[ArticleColumn.article_id.value],
                      row[ArticleColumn.title.value],
                      row[ArticleColumn.received_date.value],
                      sep='\t')
    except:
        exception_message = sys.exc_info()[0]
        print("An error occurred. {}".format(exception_message))
    finally:
        database.mysql_close_cursor(cursor)
        database.mysql_close_connection(mysql_connect)
def get_author_info(first_name_parameters):
    try:
        database = DatabaseConnector(config.USER, config.PASSWORD, config.HOST,
                                     config.DATABASE)
        mysql_connect = database.mysql_open_connection()
        sql = (
            "SELECT author_id, first_name, last_name, middle_name FROM author WHERE first_name = %s"
        )
        paremeters = ('John', )
        cursor, data = database.mysql_execute_cursor_select(
            mysql_connect, sql, paremeters)
        if cursor.rowcount > 0:
            for row in data:
                print(row[AuthorContact.author_id.value],
                      row[AuthorContact.first_name.value],
                      row[AuthorContact.last_name.value],
                      row[AuthorContact.middle_name.value],
                      sep='\t')
    except:
        exception_message = sys.exc_info()[0]
        print("An error occurred. {}".format(exception_message))
    finally:
        database.mysql_close_cursor(cursor)
        database.mysql_close_connection(mysql_connect)
     dataset = database.mysql_call_procedure_select(mysql_connect,
                                                    "usp_author_select")
     for row in dataset:
         print(row[AuthorColumn.author_id.value],
               row[AuthorColumn.first_name.value],
               row[AuthorColumn.last_name.value],
               row[AuthorColumn.middle_name.value],
               row[AuthorColumn.title.value],
               row[AuthorColumn.job_description.value],
               row[AuthorColumn.street_1.value],
               row[AuthorColumn.street_2.value],
               row[AuthorColumn.city.value],
               row[AuthorColumn.state_province.value],
               row[AuthorColumn.zip_code.value],
               row[AuthorColumn.country.value],
               row[AuthorColumn.phone.value],
               row[AuthorColumn.fax.value],
               row[AuthorColumn.email.value],
               row[AuthorColumn.website.value],
               row[AuthorColumn.picture.value],
               row[AuthorColumn.notes.value],
               row[AuthorColumn.active.value],
               row[AuthorColumn.updated_id.value],
               row[AuthorColumn.updated_date.value],
               sep='\t')
 except:
     exception_message = sys.exc_info()[0]
     print("An error occurred. {}".format(exception_message))
 finally:
     database.mysql_close_connection(mysql_connect)