view roundup/backends/sessions_sqlite.py @ 8241:741ea8a86012

fix: issue2551374. Error handling for filter expressions. Errors in filter expressions are now reported. The UI needs some work but even the current code is helpful when debugging filter expressions. mlink_expr: defines/raises ExpressionError(error string template, context=dict()) raises ExpressionError when it detects errors when popping arguments off stack raises ExpressionError when more than one element left on the stack before returning also ruff fix to group boolean expression with parens back_anydbm.py, rdbms_common.py: catches ExpressionError, augments context with class and attribute being searched. raises the exception for both link and multilink relations client.py catches ExpressionError returning a basic error page. The page is a dead end. There are no links or anything for the user to move forward. The user has to go back, possibly refresh the page (because the submit button may be disalbled) re-enter the query and try again. This needs to be improved. test_liveserver.py test the error page generated by client.py db_test_base unit tests for filter with too few arguments, too many arguments, check all repr and str formats.
author John Rouillard <rouilj@ieee.org>
date Mon, 30 Dec 2024 20:22:55 -0500
parents a96a239db0d9
children
line wrap: on
line source

"""This module defines a very basic store that's used by the CGI interface
to store session and one-time-key information.

Yes, it's called "sessions" - because originally it only defined a session
class. It's now also used for One Time Key handling too.

We needed to split commits to session/OTK database from commits on the
main db structures (user data). This required two connections to the
sqlite db, which wasn't supported. This module was created so sqlite
didn't have to use dbm for the session/otk data. It hopefully will
provide a performance speedup.
"""
__docformat__ = 'restructuredtext'

from roundup.backends import sessions_rdbms


class BasicDatabase(sessions_rdbms.BasicDatabase):
    ''' Provide a nice encapsulation of an RDBMS table.

        Keys are id strings, values are automatically marshalled data.
    '''
    name = None

    def __init__(self, db):
        self.db = db
        self.conn, self.cursor = self.db.sql_open_connection(dbname=self.name)

        self.sql('''SELECT name FROM sqlite_master WHERE type='table' AND '''
                 '''name='%ss';''' % self.name)
        table_exists = self.cursor.fetchone()

        if not table_exists:
            # create table/rows etc.
            self.sql('''CREATE TABLE %(name)ss (%(name)s_key VARCHAR(255),
            %(name)s_value TEXT, %(name)s_time REAL)''' % {"name": self.name})
            self.sql('CREATE INDEX %(name)s_key_idx ON '
                     '%(name)ss(%(name)s_key)' % {"name": self.name})
            # Set journal mode to WAL.
            self.commit()  # close out rollback journal/transaction
            self.sql('pragma journal_mode=wal')  # set wal
            self.commit()  # close out rollback and commit wal change

    def sql(self, sql, args=None, cursor=None):
        """ Execute the sql with the optional args.
        """
        self.log_debug('SQL %r %r' % (sql, args))
        if not cursor:
            cursor = self.cursor
        if args:
            cursor.execute(sql, args)
        else:
            cursor.execute(sql)


class Sessions(BasicDatabase):
    name = 'session'


class OneTimeKeys(BasicDatabase):
    name = 'otk'

# vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/