From fcf1c1d13b08b7c59973cd974627745fb9d263a5 Mon Sep 17 00:00:00 2001 From: kulath Date: Mon, 1 Aug 2016 17:37:26 +0100 Subject: [PATCH] Improve pylint to 10.0 --- gramps/plugins/db/dbapi/sqlite.py | 83 +++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/gramps/plugins/db/dbapi/sqlite.py b/gramps/plugins/db/dbapi/sqlite.py index e4d1bd8c5..dac1ae920 100644 --- a/gramps/plugins/db/dbapi/sqlite.py +++ b/gramps/plugins/db/dbapi/sqlite.py @@ -18,19 +18,35 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -import os +""" +Backend for sqlite database. +""" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- import sqlite3 import logging import re sqlite3.paramstyle = 'qmark' +#------------------------------------------------------------------------- +# +# Sqlite class +# +#------------------------------------------------------------------------- class Sqlite: + """ + The Sqlite class is an interface between the DBAPI class which is the Gramps + backend for the DBAPI interface and the sqlite3 python module. + """ @classmethod def get_summary(cls): """ - Return a diction of information about this database - backend. + Return a dictionary of information about this database backend. """ summary = { "DB-API version": "2.0", @@ -43,6 +59,18 @@ class Sqlite: return summary def __init__(self, *args, **kwargs): + """ + Create a new Sqlite instance. + + This connects to a sqlite3 database and creates a cursor instance. + + :param args: arguments to be passed to the sqlite3 connect class at + creation. + :type args: list + :param kwargs: arguments to be passed to the sqlite3 connect class at + creation. + :type kwargs: list + """ self.log = logging.getLogger(".sqlite") self.connection = sqlite3.connect(*args, **kwargs) self.cursor = self.connection.cursor() @@ -50,35 +78,84 @@ class Sqlite: self.connection.create_function("regexp", 2, regexp) def execute(self, *args, **kwargs): + """ + Executes an SQL statement. + + :param args: arguments to be passed to the sqlite3 execute statement + :type args: list + :param kwargs: arguments to be passed to the sqlite3 execute statement + :type kwargs: list + """ self.log.debug(args) self.cursor.execute(*args, **kwargs) def fetchone(self): + """ + Fetches the next row of a query result set, returning a single sequence, + or None when no more data is available. + """ return self.cursor.fetchone() def fetchall(self): + """ + Fetches the next set of rows of a query result, returning a list. An + empty list is returned when no more rows are available. + """ return self.cursor.fetchall() def begin(self): + """ + Start a transaction manually. This transactions usually persist until + the next COMMIT or ROLLBACK command. + """ self.log.debug("BEGIN TRANSACTION;") self.execute("BEGIN TRANSACTION;") def commit(self): + """ + Commit the current transaction. + """ self.log.debug("COMMIT;") self.connection.commit() def rollback(self): + """ + Roll back any changes to the database since the last call to commit(). + """ self.log.debug("ROLLBACK;") self.connection.rollback() def table_exists(self, table): + """ + Test whether the specified SQL database table exists. + + :param table: table name to check. + :type table: str + :returns: True if the table exists, false otherwise. + :rtype: bool + """ self.execute("SELECT COUNT(*) FROM sqlite_master " "WHERE type='table' AND name='%s';" % table) return self.fetchone()[0] != 0 def close(self): + """ + Close the current database. + """ self.log.debug("closing database...") self.connection.close() def regexp(expr, value): + """ + A user defined function that can be called from within an SQL statement. + + This function has two parameters. + + :param expr: pattern to look for. + :type expr: str + :param value: the string to search. + :type value: list + :returns: True if the expr exists within the value, false otherwise. + :rtype: bool + """ return re.search(expr, value, re.MULTILINE) is not None