예제 #1
0
    def before_cursor_execute(conn, cursor, sql, parameters, context,
                              executemany):
        data = dict(
            # TODO: Figure out how to retrieve the exact driver version.
            db_driver=conn.engine.driver,
            # Driver/framework centric information.
            db_framework='sqlalchemy:%s' % sqlalchemy.__version__,
        )

        # Because sqlalchemy is a plain database connectivity module,
        # folks using it in a web framework such as flask will
        # use it in unison with flask but initialize the parts disjointly,
        # unlike Django which uses ORMs directly as part of the framework.
        data.update(get_flask_info())

        # Filter down to just the requested attributes.
        data = {k: v for k, v in data.items() if attributes.get(k)}

        if with_opencensus:
            data.update(get_opencensus_values())

        sql_comment = generate_sql_comment(**data)

        # TODO: Check if the database type is MySQL and figure out
        # if we should prepend comments because MySQL server truncates
        # logs greater than 1kB.
        # See:
        #  * https://github.com/basecamp/marginalia/issues/61
        #  * https://github.com/basecamp/marginalia/pull/80
        sql += sql_comment

        return sql, parameters
예제 #2
0
        def execute(self, sql, args=None):
            data = dict(
                # Psycopg2/framework information
                db_driver='psycopg2:%s' % psycopg2.__version__,
                dbapi_threadsafety=psycopg2.threadsafety,
                dbapi_level=psycopg2.apilevel,
                libpq_version=psycopg2.__libpq_version__,
                driver_paramstyle=psycopg2.paramstyle,
            )

            # Because psycopg2 is a plain database connectivity module,
            # folks using it in a web framework such as flask will
            # use it in unison with flask but initialize the parts disjointly,
            # unlike Django which uses ORMs directly as part of the framework.
            data.update(get_flask_info())

            # Filter down to just the requested attributes.
            data = {k: v for k, v in data.items() if attributes.get(k)}

            if with_opencensus:
                data.update(get_opencensus_values())

            sql += generate_sql_comment(**data)

            return psycopg2.extensions.cursor.execute(self, sql, args)
예제 #3
0
파일: app.py 프로젝트: rheehot/sqlcommenter
def flask_info():
    return get_flask_info()
예제 #4
0
파일: app.py 프로젝트: rheehot/sqlcommenter
def handle_bad_request(e):
    return get_flask_info(), 404
예제 #5
0
def test_get_flask_info_outside_request_context(client):
    assert get_flask_info() == {}