コード例 #1
0
def cached_sql_query(conn, sql, *args):
    global db_modified_time, query_cache
    last_mod_time = os.path.getmtime(archiver.get_db_name(GROUP_ID))

    if db_modified_time is None or last_mod_time > db_modified_time:
        # Flush cache
        query_cache = {}
        db_modified_time = last_mod_time

    query = sql + repr(args)

    if query in query_cache:
        return query_cache[query]
    else:
        result = sql_query(conn, sql, *args)
        query_cache[query] = result
        return result
コード例 #2
0
def cached_sql_query(conn, sql, *args):
    global db_modified_time, query_cache
    last_mod_time = os.path.getmtime(archiver.get_db_name(GROUP_ID))

    if db_modified_time is None or last_mod_time > db_modified_time:
        # Flush cache
        query_cache = {}
        db_modified_time = last_mod_time

    query = sql + repr(args)

    if query in query_cache:
        return query_cache[query]
    else:
        result = sql_query(conn, sql, *args)
        query_cache[query] = result
        return result
コード例 #3
0
def get_conn(group_id):
    db_path = archiver.get_db_name(group_id)
    try:
        with open(db_path): pass
    except IOError:
        raise NameError("Database not found: " + db_path)

    if PROD:
        def row_trace(cursor, row):
            names = (l[0] for l in cursor.getdescription())
            return dict(zip(names, row))
        conn = apsw.Connection(db_path, flags=1) # SQLITE Read-Only flag
        conn.setrowtrace(row_trace)
    else:
        conn = sqlite3.connect(db_path)
        conn.row_factory = sqlite3.Row
    return conn
コード例 #4
0
def get_conn(group_id):
    db_path = archiver.get_db_name(group_id)
    try:
        with open(db_path):
            pass
    except IOError:
        raise NameError("Database not found: " + db_path)

    if PROD:

        def row_trace(cursor, row):
            names = (l[0] for l in cursor.getdescription())
            return dict(zip(names, row))

        conn = apsw.Connection(db_path, flags=1)  # SQLITE Read-Only flag
        conn.setrowtrace(row_trace)
    else:
        conn = sqlite3.connect(db_path)
        conn.row_factory = sqlite3.Row
    return conn