# -*- coding: utf-8 -*-1# This program is free software; you can redistribute it and/or modify2# it under the terms of the GNU General Public License as published by3# the Free Software Foundation; either version 2 of the License, or4# (at your option) any later version.5#6# This program is distributed in the hope that it will be useful,7# but WITHOUT ANY WARRANTY; without even the implied warranty of8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9# GNU General Public License for more details.10#11# You should have received a copy of the GNU General Public License12# along with this program; if not, write to the Free Software13# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,14# MA 02110-1301, USA.15#16# Author: Mauro Soria1718import sqlite31920from lib.report.factory import BaseReport, SQLReportMixin21from lib.utils.file import FileUtils222324class SQLiteReport(SQLReportMixin, BaseReport):25__format__ = "sql"26__extension__ = "sqlite"27_reuse = False2829def get_create_table_query(self, table):30return (f'''CREATE TABLE "{table}" (31time DATETIME,32url TEXT,33status_code INTEGER,34content_length INTEGER,35content_type TEXT,36redirect TEXT37);''',)3839def get_insert_table_query(self, table, values):40return (f'INSERT INTO "{table}" VALUES (?, ?, ?, ?, ?, ?);', values)4142def connect(self, file):43FileUtils.create_dir(FileUtils.parent(file))44conn = sqlite3.connect(file, check_same_thread=False)45# Check if the file is a proper sqlite database46try:47conn.cursor().execute("PRAGMA integrity_check")48except sqlite3.DatabaseError:49raise Exception(f"{file} is not empty or is not a SQLite database")50else:51return conn525354