Nikita | 4d9d4e5 | 2021-04-08 11:38:50 +0100 | [diff] [blame^] | 1 | ##############################################################################
|
| 2 | # Copyright (c) 2021, ARM Limited and Contributors. All rights reserved.
|
| 3 | #
|
| 4 | # SPDX-License-Identifier: BSD-3-Clause
|
| 5 | ##############################################################################
|
| 6 | """
|
| 7 | SQL adaptor for SQLite queries
|
| 8 | """
|
| 9 | import sqlite3
|
| 10 |
|
| 11 |
|
| 12 | class Database:
|
| 13 | """
|
| 14 | Class used to represent an sqlite database
|
| 15 |
|
| 16 | Methods:
|
| 17 | execute_query: Executes and sqlite query and returns response
|
| 18 | """
|
| 19 |
|
| 20 | def __init__(self, db):
|
| 21 | """Inits Database class with an sqlite db instance"""
|
| 22 | self.mydb = sqlite3.connect(db)
|
| 23 | self.cursor = self.mydb.cursor()
|
| 24 |
|
| 25 | def execute_query(self, query):
|
| 26 | """Executes a sqlite query
|
| 27 | Args:
|
| 28 | query(str): sqlite query
|
| 29 | Returns:
|
| 30 | response to the query
|
| 31 | """
|
| 32 | try:
|
| 33 | self.cursor.execute(query)
|
| 34 | self.mydb.commit()
|
| 35 | return self.cursor.fetchall()
|
| 36 | except sqlite3.Error as err:
|
| 37 | raise err
|